www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/FilterANoisySignalUsingTheIIRFilterSystemObjectExample.m

    %% Filter a Noisy Signal Using the IIRFilter System object
% This example shows how to filter a noisy signal with a |dsp.IIRFilter|
% System object(TM). View the magnitude response of the IIR filter. Use
% the |Spectrum Analyzer| to display the power spectrum of the output
% signal.

%% Initialization
x = randn(2048,1);
x = x-mean(x);
Hsr = dsp.SignalSource;
Hsr.Signal = x;
Hlog = dsp.SignalSink;

N = 10;
Fc = 0.4;
[b,a] = butter(N,Fc);
H = dsp.IIRFilter('Numerator',b,'Denominator',a);

h = dsp.SpectrumAnalyzer('SampleRate',8e3,...
    'PlotAsTwoSidedSpectrum',false,...
    'OverlapPercent', 80,'PowerUnits','dBW',...
    'YLimits', [-220 -10]);

%% Filter the Signal
while ~isDone(Hsr)
  input = Hsr();
  output = H(input);
  h(output)
  Hlog(output);
end

Result = Hlog.Buffer;
fvtool(H,'Fs',8000)