halfband decimator -凯发k8网页登录
halfband decimator
description
the dsp.firhalfbanddecimator
system object™ performs an efficient polyphase decimation of the input signal by a factor
of two. you can use dsp.firhalfbanddecimator
to implement the analysis
portion of a two-band filter bank to filter a signal into lowpass and highpass subbands.
dsp.firhalfbanddecimator
uses an fir equiripple design or a kaiser
window design to construct the halfband filters and a polyphase implementation to filter
the input.
to filter and downsample your data:
create the
dsp.firhalfbanddecimator
object and set its properties.call the object with arguments, as if it were a function.
to learn more about how system objects work, see what are system objects?
creation
syntax
description
returns a halfband decimator, firhalfbanddecim
= dsp.firhalfbanddecimatorfirhalfbanddecim
, with the
default settings. under the default settings, the system object filters and downsamples the input data with a halfband frequency
of 11025
hz, a transition width of 4.1
khz, and a stopband attenuation of 80
db. the design method
is set to "auto"
.
returns a halfband decimator, with additional properties specified by one or
more firhalfbanddecim
= dsp.firhalfbanddecimator(name=value
)name=value
pair arguments.
example: firhalfbanddecim =
dsp.firhalfbanddecimator(specification="filter order and stopband
attenuation")
creates an fir halfband decimator object with filter
order set to 52 and stopband attenuation set to 80 db.
properties
unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. objects lock when you call them, and the function unlocks them.
if a property is tunable, you can change its value at any time.
for more information on changing property values, see .
specification
— filter design parameters
"transition width and stopband
attenuation"
(default) | "filter order and stopband attenuation"
| "filter order and transition width"
| "coefficients"
filter design parameters, specified as a character vector. when you set
specification
to one of the following, you choose
two of the three available design parameters to design the fir halfband
filter.
"transition width and stopband attenuation"
–– transition width and stopband attenuation are the design parameters."filter order and stopband attenuation"
–– filter order and stopband attenuation are the design parameters."filter order and transition width"
–– filter order and transition width are the design parameters.
the filter is designed using the optimal equiripple filter design method or the kaiser-window-based design method.
when you set specification
to
"coefficients"
, you specify the halfband filter
coefficients directly through the numerator
property.
filterorder
— filter order
52
(default) | even positive integer
filter order, specified as an even positive integer.
dependencies
this property applies when you set specification
to either "filter order and stopband attenuation"
or
"filter order and transition width"
.
data types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
stopbandattenuation
— stopband attenuation
80
(default) | positive real scalar
stopband attenuation in db, specified as a positive real scalar.
dependencies
this property applies when you set specification
to either "filter order and stopband attenuation"
or
"transition width and stopband
attenuation"
.
data types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
transitionwidth
— transition width
4100
(default) | positive real scalar
transition width in hz, specified as a positive real scalar. the value of the transition width in hz must be less than 1/2 the input sample rate.
dependencies
this property applies when you set specification
to either "transition width and stopband attenuation"
or "filter order and transition width"
.
data types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
numerator
— fir halfband filter coefficients
firhalfband('minorder',0.407,1e-4)
(default) | row vector
fir halfband filter coefficients, specified as a row vector. the
coefficients must comply with the fir halfband impulse response format. for
details on this format, see halfband filters and fir halfband filter design. if
half the order of the filter, (length(numerator) - 1)/2
,
is even, every other coefficient starting from the first coefficient must be
a zero except for the center coefficient which must be a 0.5. if half the
order of the filter is odd, the sequence of alternating zeros with a 0.5 at
the center starts at the second coefficient.
dependencies
this property applies when you set specification
to "coefficients"
.
data types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
designmethod
— filter design method
"auto"
(default) | "equiripple"
| "kaiser"
specify the filter design method as one of the following:
"auto"
–– the algorithm automatically chooses the filter design method depending on the filter design parameters. the algorithm uses the equiripple or the kaiser window method to design the filter.if the design constraints are very tight, such as very high stopband attenuation or very narrow transition width, then the algorithm automatically chooses the kaiser method, as this method is optimal for designing filters with very tight specifications. however, if the design constraints are not tight, then the algorithm chooses the equiripple method.
when you set the
designmethod
property to"auto"
, you can determine the method used by the algorithm by examining the passband and stopband ripple characteristics of the designed filter. if the object used the equiripple method, the passband and stopband ripples of the designed filter have a constant amplitude in the frequency response. if the filter design method the object chooses in the"auto"
mode is not suitable for your application, manually specify thedesignmethod
as"equiripple"
or"kaiser"
."equiripple"
–– the algorithm uses the equiripple method."kaiser"
–– the algorithm uses the kaiser window method.
for more details on these two methods, see algorithms.
dependencies
to enable this property, set specification
to
"transition width and stopband attenuation"
,
"filter order and stopband attenuation"
, or
"filter order and transition width"
.
data types: char
| string
samplerate
— input sample rate
44100
(default) | positive real scalar
input sample rate in hz, specified as a positive real scalar. the input sample rate defaults to 44100 hz. if you specify transition width as one of your filter design parameters, the transition width cannot exceed 1/2 the input sample rate.
data types: single
| double
fixed-point properties
coefficientsdatatype
— word and fraction lengths of coefficients
numerictype(1,16)
(default) | numerictype
object
word and fraction lengths of coefficients, specified as a signed or
unsigned numerictype
object. the default,
numerictype(1,16)
corresponds to a signed numeric
type object with 16-bit coefficients and a fraction length determined
based on the coefficient values, to give the best possible
precision.
this property is not tunable.
word length of the output is same as the word length of the input. fraction length of the output is computed such that the entire dynamic range of the output can be represented without overflow. for details on how the fraction length of the output is computed, see .
roundingmethod
— rounding method for output fixed-point operations
"floor"
(default) | "ceiling"
| "convergent"
| "nearest"
| "round"
| "simplest"
| "zero"
rounding method for output fixed-point operations, specified as a character vector. for more information on the rounding modes, see precision and range.
usage
description
[
computes the ylow
,yhigh
] = firhalfbanddecim(x
)ylow
and yhigh
, of the
analysis filter bank, firhalfbanddecim
for input
x
. a ki-by-n
input matrix is treated as n independent channels. the
system object generates two power-complementary output signals by adding and
subtracting the two polyphase branch outputs respectively.
ylow
and yhigh
are of the same
size (ko-by-n) and data type.
ko = ki/2, where 2
is the decimation factor.
input arguments
x
— data input
column vector | matrix
data input, specified as a column vector or a matrix. if the input signal is a matrix, each column of the matrix is treated as an independent channel. the number of rows in the input signal must be a multiple of 2.
this object supports variable-size input signal.
data types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
complex number support: yes
output arguments
ylow
— lowpass subband of decimator output
column vector | matrix
lowpass subband of decimator output, returned as a column vector or a
matrix. the output, ylow
is a lowpass halfband
filtered and downsampled version of the input x
.
due to the halfband nature of the filter, the downsampling factor is
always 2.
data types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
complex number support: yes
yhigh
— highpass subband of decimator output
column vector | matrix
highpass subband of decimator output, returned as a column vector or a
matrix. the output, yhigh
is a highpass halfband
filtered and downsampled version of the input x
.
due to the halfband nature of the filter, the downsampling factor is
always 2.
data types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
complex number support: yes
object functions
to use an object function, specify the
system object as the first input argument. for
example, to release system resources of a system object named obj
, use
this syntax:
release(obj)
specific to dsp.firhalfbanddecimator
frequency response of discrete-time filter system object | |
visualize frequency response of dsp filters | |
information about filter system object | |
estimate cost of implementing filter system object | |
returns the filter system object coefficients in a structure | |
polyphase decomposition of multirate filter |
common to all system objects
run system object algorithm | |
release resources and allow changes to system object property values and input characteristics | |
reset internal states of system object |
examples
impulse and frequency response of halfband decimation filter
create two lowpass halfband decimation filters for data sampled at 44.1 khz. the design method in the first filter is set to "equiripple"
and in the second filter is set to "kaiser"
.
the output data rate is 1/2 the input sample rate, or 22.05 khz. specify the filter order to be 52 with a transition width of 4.1 khz.
fs = 44.1e3; filterspec = "filter order and transition width"; order = 52; tw = 4.1e3; firhalfbanddecimequi = dsp.firhalfbanddecimator(... specification=filterspec,... filterorder=order,... transitionwidth=tw,... designmethod="equiripple",... samplerate=fs); firhalfbanddecimkaiser = dsp.firhalfbanddecimator(... specification=filterspec,... filterorder=order,... transitionwidth=tw,... designmethod="kaiser",... samplerate=fs);
plot the impulse response of both the filters. the zeroth-order coefficient is delayed 26 samples, which is equal to the group delay of the filter. this yields a causal halfband filter.
hfvt = fvtool(firhalfbanddecimequi,firhalfbanddecimkaiser,... analysis="impulse"); legend(hfvt,{'equiripple','kaiser'})
plot the magnitude and phase response.
if the filter specifications are tight, say a very high filter order with a very narrow transition width, the filter designed using the "kaiser"
method converges more effectively.
hvftmag = fvtool(firhalfbanddecimequi,firhalfbanddecimkaiser,... analysis="magnitude"); legend(hvftmag,{'equiripple','kaiser'})
hvftphase = fvtool(firhalfbanddecimequi,firhalfbanddecimkaiser,... analysis="phase"); legend(hvftphase,{'equiripple','kaiser'})
extract low frequency subband from speech
use a halfband analysis filter bank and interpolation filter to extract the low frequency subband from a speech signal.
note: the audiodevicewriter
system object™ is not supported in .
set up the audio file reader, the analysis filter bank, audio device writer, and interpolation filter. the sample rate of the audio data is 22050 hz. the order of the halfband filter is 52, with a transition width of 2 khz.
set the design method to "auto"
. this mode chooses one of the filter design methods, equiripple or kaiser, based on the design parameters of the filter.
afr = dsp.audiofilereader(... "speech_dft.mp3",... samplesperframe=1024); filtspec = "filter order and transition width"; order = 52; tw = 2000; firhalfbanddecim = dsp.firhalfbanddecimator(... specification=filtspec,... filterorder=order,... transitionwidth=tw,... designmethod="auto",... samplerate=afr.samplerate); firhalfbandinterp = dsp.firhalfbandinterpolator(... specification=filtspec,... filterorder=order,... transitionwidth=tw,... designmethod="auto",... samplerate=afr.samplerate/2); adw = audiodevicewriter(samplerate=afr.samplerate);
view the magnitude response of the halfband filter.
fvtool(firhalfbanddecim)
read the speech signal from the audio file in frames of 1024 samples. filter the speech signal into lowpass and highpass subbands with a halfband frequency of 5512.5 hz. reconstruct a lowpass approximation of the speech signal by interpolating the lowpass subband. play the filtered output.
while ~isdone(afr) audioframe = afr(); xlo = firhalfbanddecim(audioframe); ylow = firhalfbandinterp(xlo); adw(ylow); end
wait until the audio file is played to the end, then close the input file and release the audio output resource.
release(afr); release(adw);
two-channel filter bank
use a halfband decimator and interpolator to implement a two-channel filter bank. this example uses an audio file input and shows that the power spectrum of the filter bank output does not differ significantly from the input.
note: the audiodevicewriter
system object™ is not supported in matlab online.
set up the audio file reader and device writer. construct the fir halfband decimator and interpolator. finally, set up the spectrum analyzer to display the power spectra of the filter-bank input and output.
af = dsp.audiofilereader("speech_dft.mp3",samplesperframe=1024); ap = audiodevicewriter(samplerate=af.samplerate); filterspec = "filter order and transition width"; order = 52; tw = 2000; firhalfbanddecim = dsp.firhalfbanddecimator(... specification=filterspec,filterorder=order,... transitionwidth=tw,designmethod="auto",... samplerate=af.samplerate); firhalfbandinterp = dsp.firhalfbandinterpolator(... specification=filterspec,filterorder=order,... transitionwidth=tw,samplerate=af.samplerate/2,... designmethod="auto",... filterbankinputport=true); specana = spectrumanalyzer(samplerate=af.samplerate,... plotastwosidedspectrum=false,... showlegend=true,... channelnames={'input signal','filtered output signal'});
read the audio 1024 samples at a time. filter the input to obtain the lowpass and highpass subband signals decimated by a factor of two. this is the analysis filter bank. use the halfband interpolator as the synthesis filter bank. display the running power spectrum of the audio input and the output of the synthesis filter bank. play the output.
while ~isdone(af) audioinput = af(); [xlo,xhigh] = firhalfbanddecim(audioinput); audiooutput = firhalfbandinterp(xlo,xhigh); spectruminput = [audioinput audiooutput]; specana(spectruminput); ap(audiooutput); end release(af); release(ap); release(specana);
filter input into lowpass and highpass subbands using fir halfband decimator
create a halfband decimator for data sampled at 44.1 khz. use a minimum-order design with a transition width of 2 khz and a stopband attenuation of 60 db.
set the design method to "auto"
. this mode chooses one of the filter design methods, equiripple or kaiser, based on the specified filter design parameters.
hfirhalfbanddecim = dsp.firhalfbanddecimator(... specification="transition width and stopband attenuation",... transitionwidth=2000,... stopbandattenuation=60,... designmethod="auto",... samplerate=44.1e3);
filter a two-channel input into low and highpass subbands.
x = randn(1024,2); [ylow,yhigh] = hfirhalfbanddecim(x);
more about
halfband filters
an ideal lowpass halfband filter is given by
an ideal filter is not realizable because the impulse response is noncausal and not absolutely summable. however, the impulse response of an ideal lowpass filter possesses some important properties that are required in a realizable approximation. the impulse response of an ideal lowpass halfband filter is:
equal to 0 for all even-indexed samples.
equal to 1/2 at n=0 as shown by l'hôpital's rule on the continuous-valued equivalent of the discrete-time impulse response
the ideal highpass halfband filter is given by
evaluating the preceding integral gives the following impulse response
the impulse response of an ideal highpass halfband filter is:
equal to 0 for all even-indexed samples
equal to 1/2 at n=0
the fir halfband decimator uses a causal fir approximation to the ideal halfband response, which is based on minimizing the norm of the error (minimax). see algorithms for more information.
kaiser window
the coefficients of a kaiser window are computed from this equation:
where i0 is the zeroth-order modified bessel function of the first kind.
to obtain a kaiser window that represents an fir filter with stopband attenuation of α db, use this β.
the filter order n is given by:
where δω is the transition width.
algorithms
filter design method
the fir halfband decimator algorithm uses the equiripple or the kaiser window method to design
the fir halfband filter. when the design constraints are tight, such as very high
stopband attenuation or very narrow transition width, use the kaiser window method. when
the design constraints are not tight, use the equiripple method. if you are not sure of
which method to use, set the design method to auto
. in this mode, the
algorithm automatically chooses a design method that optimally meets the specified
filter constraints.
halfband equiripple design
in the equiripple method, the algorithm uses a minimax (minimize the maximum error) fir design to design a fullband linear phase filter with the desired specifications. the algorithm upsamples a fullband filter to replace the even-indexed samples of the filter with zeros and creates a halfband filter. it then sets the filter tap corresponding to the group delay of the filter in samples to 1/2. this yields a causal linear-phase fir filter approximation to the ideal halfband filter defined in halfband filters. see [1] for a description of this filter design method using the remez exchange algorithm. since you can design a filter using this approximation method with a constant ripple both in the passband and stopband, the filter is also known as the equiripple filter.
kaiser window design
in the kaiser window method, the algorithm first truncates the ideal halfband filter defined in halfband filters, then it applies a kaiser window defined in kaiser window. this yields a causal linear-phase fir filter approximation to the ideal halfband filter.
for more information on designing fir halfband filters, see fir halfband filter design.
polyphase implementation with halfband filters
the fir halfband decimator uses an efficient polyphase implementation for halfband filters when you filter the input signal. the chief advantage of the polyphase implementation is that you can downsample the signal prior to filtering. this allows you to filter at the lower sampling rate.
splitting a filter’s impulse response h(n) into two polyphase components results in an even polyphase component with z-transform of
and an odd polyphase component with z-transform of
the z-transform of the filter can be written in terms of the even and odd polyphase components as
you can represent filtering the input signal and then downsampling it by 2 using this figure.
using the multirate noble identity for downsampling, you can move the downsampling operation before the filtering. this allows you to filter at the lower rate.
for a halfband filter, the only nonzero coefficient in the even polyphase component is the coefficient corresponding to z0. implementing the halfband filter as a causal fir filter shifts the nonzero coefficient to approximately z-n/4 where n is the number of filter taps. this process is illustrated in the following figure.
the top plot shows a halfband filter of order 52. the bottom plot shows the even polyphase component. both of these filters are noncausal. delaying the even polyphase component by 13 samples creates a causal fir filter.
to efficiently implement the halfband decimator, the algorithm replaces the delay block and downsampling operator with a commutator switch. this is illustrated in the following figure where one polyphase component is replaced by a gain and delay.
the commutator switch takes input samples from a single branch and supplies every other sample to one of the two polyphase components for filtering. this halves the sampling rate of the input signal. which polyphase component reduces to a simple delay depends on whether the half order of the filter is even or odd. this is because the delay required to make the even polyphase component causal can be odd or even depending on the filter half order.
to confirm this behavior, run the following code in the matlab® command prompt and inspect the polyphase components of the following filters.
filterspec = "filter order and stopband attenuation"; halfordereven = dsp.firhalfbanddecimator(specification=filterspec,... filterorder=64,stopbandattenuation=80,designmethod="auto"); halforderodd = dsp.firhalfbanddecimator(specification=filterspec,... filterorder=54,stopbandattenuation=80,designmethod="auto"); polyphase(halfordereven) polyphase(halforderodd)
to summarize, the fir halfband decimator:
decimates the input prior to filtering and filters the even and odd polyphase components of the input separately with the even and odd polyphase components of the filter.
exploits the fact that one filter polyphase component is a simple delay for a halfband filter.
references
[1] harris, f.j. multirate signal processing for communication systems, prentice hall, 2004, pp. 208–209.
extended capabilities
c/c code generation
generate c and c code using matlab® coder™.
usage notes and limitations:
see (matlab coder).
this object supports code generation for arm® cortex®-m and arm cortex-a processors.
version history
introduced in r2014b
打开示例
您曾对此示例进行过修改。是否要打开带有您的编辑的示例?
matlab 命令
您点击的链接对应于以下 matlab 命令:
请在 matlab 命令行窗口中直接输入以执行命令。web 浏览器不支持 matlab 命令。
select a web site
choose a web site to get translated content where available and see local events and offers. based on your location, we recommend that you select: .
you can also select a web site from the following list:
how to get best site performance
select the china site (in chinese or english) for best site performance. other mathworks country sites are not optimized for visits from your location.
americas
- (español)
- (english)
- (english)
europe
- (english)
- (english)
- (deutsch)
- (español)
- (english)
- (français)
- (english)
- (italiano)
- (english)
- (english)
- (english)
- (deutsch)
- (english)
- (english)
- switzerland
- (english)
asia pacific
- (english)
- (english)
- (english)
- 中国
- (日本語)
- (한국어)