%% Determining Best Multistage Decimator Design
% The filters in the multistage design satisfy the following conditions:
% The combined response must meet or exceed the given design specifications.
% The combined decimation must equal the overall decimation required.
% For an overall decimation factor of 48, there are several combinations of individual stages.
% To obtain a design with the least number of total coefficients, set the 'MinTotalCoeffs' argument to true.

Astop = 80;
M = 48;
Fs = 6000;
TW = 0.03*Fs/2;
cMinCoeffs = designMultistageDecimator(M,Fs,TW,Astop,'MinTotalCoeffs',true)
cost(cMinCoeffs)

% To obtain the design with the least number of multiplications per input sample, set 'NumStages' to 'auto'.

cMinMulti = designMultistageDecimator(M,Fs,TW,Astop,'NumStages','auto')
cost(cMinMulti)

% Compare the magnitude response of both filters using fvtool. Both filters have the same transition-band behavior and a stopband attenuation that is below 80 dB.

fvtool(cMinCoeffs,cMinMulti)
legend('Minimize total coefficients','Minimize number of multiplications per input sample')

%
% Copyright 2018 The MathWorks, Inc.