%% Design of Lowpass Decimator
% Design a 100-tap FIR lowpass decimator filter that reduces the sample rate of a signal from 60 kHz to 20 kHz. The passband of the filter extends up to 6 kHz. Specify a passband ripple of 0.01 dB and a stopband attenuation of 100 dB.

Fs = 60e3;
N = 99;
Fpass = 6e3;
Apass = 0.01;
Astop = 100;
M = Fs/20e3;

% Setup the filter design specifications object using the fdesign.decimator function.

filtSpecs = fdesign.decimator(M,'lowpass','N,Fp,Ap,Ast',N,Fpass,Apass,Astop,Fs);

%
% Design the FIR lowpass decimator using the design function.
% The resulting filter is a dsp.FIRDecimator System object™. For details on how to apply this filter to streaming data, refer to dsp.FIRDecimator.

decimFIR = design(filtSpecs,'SystemObject',true)

%
% Use info to display information about the filter.

info(decimFIR)

%
% Visualize the magnitude response of the filter using fvtool.

fvtool(decimFIR,'Fs',Fs)

%
% Copyright 2019 The MathWorks, Inc.