www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/TwoChannelFilterBankExample.m
%% 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*: This example runs only in R2016b or later. If you are using an % earlier release, replace each call to the function with the equivalent % |step| syntax. For example, myObject(x) becomes step(myObject,x). %% % 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,'SampleRate',AF.SampleRate); firhalfbandinterp = dsp.FIRHalfbandInterpolator(... 'Specification',filterspec,'FilterOrder',Order,... 'TransitionWidth',TW,'SampleRate',AF.SampleRate/2,... 'FilterBankInputPort',true); SpecAna = dsp.SpectrumAnalyzer('SampleRate',AF.SampleRate,... 'PlotAsTwoSidedSpectrum',false,'ReducePlotRate',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);