main content

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:

  1. create the dsp.firhalfbanddecimator object and set its properties.

  2. 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

description

firhalfbanddecim = dsp.firhalfbanddecimator returns a halfband decimator, firhalfbanddecim, 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".

example

firhalfbanddecim = dsp.firhalfbanddecimator(name=value) returns a halfband decimator, with additional properties specified by one or more 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 .

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.

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

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

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

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

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 the designmethod 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

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

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 .

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

example

ylow = firhalfbanddecim(x) filters the input signal x using the fir halfband filter, firhalfbanddecim, and downsamples the output by a factor of 2.

example

[ylow,yhigh] = firhalfbanddecim(x) computes the 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

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

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

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)
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
run system object algorithm
release resources and allow changes to system object property values and input characteristics
reset internal states of system object

examples

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'})

figure figure 1: impulse response contains an axes object. the axes object with title impulse response, xlabel time (ms), ylabel amplitude contains 2 objects of type stem. these objects represent 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'})

figure figure 2: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel frequency (khz), ylabel magnitude (db) contains 3 objects of type line. these objects represent equiripple, kaiser.

hvftphase = fvtool(firhalfbanddecimequi,firhalfbanddecimkaiser,...
    analysis="phase");
legend(hvftphase,{'equiripple','kaiser'})

figure figure 3: phase response contains an axes object. the axes object with title phase response, xlabel frequency (khz), ylabel phase (radians) contains 2 objects of type line. these objects represent equiripple, kaiser.

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)

figure figure 1: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel frequency (khz), ylabel magnitude (db) contains 2 objects of type line.

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);

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);

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

algorithms

references

[1] harris, f.j. multirate signal processing for communication systems, prentice hall, 2004, pp. 208–209.

extended capabilities

version history

introduced in r2014b

see also

functions

  • | | | | |

objects

  • | | |

blocks

  • | | |
网站地图