%% Compensation Interpolator Design
% Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalent step syntax. For example, obj(x) becomes  step(obj,x).
% Design a compensation interpolator for an existing CIC interpolator having six sections and an interpolation factor of 16.

CICInterp = dsp.CICInterpolator('InterpolationFactor',16, ...
    'NumSections',6);

%
% Construct the compensation interpolator. Specify an interpolation factor of 2, an input sample rate of 600 Hz, a passband frequency of 100 Hz, and a stopband frequency of 250 Hz. Set the minimum attenuation of alias components in the stopband to be at least 80 dB.

fs = 600;
fPass = 100;
fStop = 250;
ast = 80;

CICCompInterp = dsp.CICCompensationInterpolator(CICInterp, ...
    'InterpolationFactor',2,'PassbandFrequency',fPass, ...
    'StopbandFrequency',fStop,'StopbandAttenuation',ast, ...
    'SampleRate',fs);

%
% Visualize the frequency response of the cascade. Normalize all magnitude responses to 0 dB.

FC = dsp.FilterCascade(CICCompInterp, CICInterp);

f = fvtool(CICCompInterp,CICInterp,FC, ...
    'Fs', [fs*2 fs*16*2 fs*16*2]);

f.NormalizeMagnitudeto1 = 'on';
legend(f,'CIC Compensation Interpolator','CIC Interpolator', ...
    'Overall Response');

%
% Apply the design to a 1000-sample random input signal.

x = dsp.SignalSource(fi(rand(1000,1),1,16,15),'SamplesPerFrame',100);

y = fi(zeros(32000,1),1,32,20);
for ind = 1:10
    x2 = CICCompInterp(x());
    y(((ind-1)*3200)+1:ind*3200) = CICInterp(x2);
end

% Copyright 2012 The MathWorks, Inc.