%% Compare Multistage Interpolator Designs
% Design an interpolator with an overall interpolation factor of 24 using the designMultistageInterpolator function. Design the filter in two configurations:
% Two-stage configuration - NumStages is set to 2.
% Auto configuration - NumStages is set to 'Auto'. This configuration designs a filter with the lowest number of multiplications per input sample.
% Compare the cost of implementing both the configurations.
%
%% Initialization
% Choose an interpolation factor of 24, input sample rate of 6 kHz, stopband attenuation of 90 dB, and a transition width of 0.03\times6000/2.

L = 24;
Fs = 6000;
Astop = 90;
TW = 0.03*Fs/2;

%
%% Design the Filter
% Design the two filters using the designMultistageInterpolator function.

cAuto = designMultistageInterpolator(L,Fs,TW,Astop,'NumStages','Auto')
cTwo = designMultistageInterpolator(L,Fs,TW,Astop,'NumStages',2)

% View the filter information using the info function. The 'Auto' configuration designs a cascade of three FIR interpolators with interpolation factors 4, 3, and 2, respectively. The two-stage configuration designs a cascade of two FIR interpolators with interpolation factors 6 and 4, respectively.
%
%% Compare the Cost
% Compare the cost of implementing the two designs using the cost function.

cost(cAuto)
cost(cTwo)

% The 'Auto' configuration interpolation filter yields a three-stage design that out-performs the two-stage design in terms of NumCoefficients and MultiplicationsPerInputSample metrics.
% Copyright 2018 The MathWorks, Inc.
%