%% Filter White Gaussian Noise with an IIR Highpass 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).
% 
% Set up the IIR highpass filter. The sampling rate of the white Gaussian 
% noise is 44,100 Hz. The passband frequency of the filter is 12 kHz, the stopband 
% frequency is 8 kHz, the passband ripple is 0.1 dB, and the stopband attenuation 
% is 80 dB.

Fs = 44.1e3;
filtertype = 'IIR';
Fpass = 12e3;
Fstop = 8e3;
Rp = 0.1;
Astop = 80;
hpf = dsp.HighpassFilter('SampleRate',Fs,...
                             'FilterType',filtertype,...
                             'PassbandFrequency',Fpass,...
                             'StopbandFrequency',Fstop,...
                             'PassbandRipple',Rp,...
                             'StopbandAttenuation',Astop);
%% 
% View the magnitude response of the highpass filter.
%%
fvtool(hpf)
%% 
% Create a spectrum analyzer object.
%%
sa = dsp.SpectrumAnalyzer('SampleRate',44.1e3,...
    'PlotAsTwoSidedSpectrum',false,'ShowLegend',true,'YLimits',...
           [-150 30],...
           'Title',...
           'Input Signal and Output Signal of IIR Highpass Filter');
sa.ChannelNames = {'Input','Output'};
%% 
% Filter the white Gaussian noisy input signal. View the input and output 
% signals using the spectrum analyzer.
%%
for k = 1:100
    Input = randn(1024,1);
    Output = hpf(Input);
    sa([Input,Output]);
end

%% 
% Copyright 2012 The MathWorks, Inc.