%% FIR Differentiator Filters
% Design a 33rd-order FIR differentiator using least squares. Plot the zero-phase response of the filter.

d = fdesign.differentiator(33);
hd = design(d,'firls','SystemObject',true);

zerophase(hd)

%
% Design a 54th-order narrowband equiripple differentiator. Differentiate the lowest 25% of the frequencies in the Nyquist range and filter the higher frequencies. Specify a sample rate of 20 kHz, a passband frequency of 2.5 kHz, and a stopband frequency of 3 kHz.

Fs = 20000;

d = fdesign.differentiator('N,Fp,Fst',54,2500,3000,Fs);
Hd = design(d,'equiripple','SystemObject',true);

%
% Redesign the filter, but this time weight the stopband to increase the attenuation.

Hd1 = design(d,'equiripple','Wstop',4,'SystemObject',true);

hfvt = fvtool(Hd,Hd1,'MagnitudeDisplay','zero-phase', ...
    'FrequencyRange','[0, Fs/2)');
legend(hfvt,'No stopband weighting','Stopband weighting');

% Copyright 2012 The MathWorks, Inc.