www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/FilteringThroughAVariableBandwidthBandpassFIRFilterExample.m
%% Filtering through a variable bandwidth bandpass FIR filter %% % *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). %% % This example shows you how to tune the center frequency and the bandwidth % of the FIR filter. Fs = 44100; % Input sample rate % Define a bandpass variable bandwidth FIR filter: hfir = dsp.VariableBandwidthFIRFilter('FilterType','Bandpass',... 'FilterOrder',100,... 'SampleRate',Fs,... 'CenterFrequency',1e4,... 'Bandwidth',4e3); htfe = dsp.TransferFunctionEstimator('FrequencyRange','onesided'); hplot = dsp.ArrayPlot('PlotType','Line',... 'XOffset',0,... 'YLimits',[-120 5], ... 'SampleIncrement', 44100/1024,... 'YLabel','Frequency Response (dB)',... 'XLabel','Frequency (Hz)',... 'Title','System Transfer Function'); FrameLength = 1024; hsin = dsp.SineWave('SamplesPerFrame',FrameLength); for i=1:500 % Generate input x = hsin() + randn(FrameLength,1); % Pass input through the filter y = hfir(x); % Transfer function estimation h = htfe(x,y); % Plot transfer function hplot(20*log10(abs(h))) % Tune bandwidth and center frequency of the FIR filter if (i==250) hfir.CenterFrequency = 5000; hfir.Bandwidth = 2000; end end