%% Notch Filter
% This example shows how to use dsp.NotchPeakFilter as a notch filter with center 
% frequency of 5000 Hz and a 3 dB bandwidth of 500 Hz.
% 
% *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).

npFilter = dsp.NotchPeakFilter('CenterFrequency',5000,'Bandwidth',500);
sa =  dsp.SpectrumAnalyzer('SampleRate',44100,...
    'PlotAsTwoSidedSpectrum',false,'SpectralAverages',50);
for i=1:5000
    y = npFilter(randn(1024,1));
    sa(y);
    if (i==2500)
        % Tune center frequency to 10000
        npFilter.CenterFrequency = 10000;
    end
end
release(npFilter)
release(sa)

%% 
% Copyright 2012 The MathWorks, Inc.