%% Bandpass Filter Steepness
% Filter white noise sampled at 1 kHz using an infinite impulse response bandpass filter with a passband width of 100 Hz. Use different steepness values. Plot the spectra of the filtered signals.

fs = 1000;
x = randn(20000,1);

[y1,d1] = bandpass(x,[ 50 150],fs,'ImpulseResponse','iir','Steepness',0.5);
[y2,d2] = bandpass(x,[200 300],fs,'ImpulseResponse','iir','Steepness',0.8);
[y3,d3] = bandpass(x,[350 450],fs,'ImpulseResponse','iir','Steepness',0.95);

pspectrum([y1 y2 y3],fs)
legend('Steepness = 0.5','Steepness = 0.8','Steepness = 0.95', ...
    'Location','south')

%
% Compute and plot the frequency responses of the filters.

[h1,f] = freqz(d1,1024,fs);
[h2,~] = freqz(d2,1024,fs);
[h3,~] = freqz(d3,1024,fs);

plot(f,mag2db(abs([h1 h2 h3])))
legend('Steepness = 0.5','Steepness = 0.8','Steepness = 0.95', ...
    'Location','south')
ylim([-100 10])

%
% Make the filters asymmetric by specifying different values of steepness at the lower and higher passband frequencies.

[y1,d1] = bandpass(x,[ 50 150],fs,'ImpulseResponse','iir','Steepness',[0.5 0.8]);
[y2,d2] = bandpass(x,[200 300],fs,'ImpulseResponse','iir','Steepness',[0.5 0.8]);
[y3,d3] = bandpass(x,[350 450],fs,'ImpulseResponse','iir','Steepness',[0.5 0.8]);

pspectrum([y1 y2 y3],fs)

% Compute and plot the frequency responses of the filters.

[h1,f] = freqz(d1,1024,fs);
[h2,~] = freqz(d2,1024,fs);
[h3,~] = freqz(d3,1024,fs);

plot(f,mag2db(abs([h1 h2 h3])))
ylim([-100 10])

% Copyright 2012 The MathWorks, Inc.