%% Interpolate a Signal Using CICInterpolator Object
% 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).
% Create a dsp.CICInterpolator System object™ with InterpolationFactor set to 2. Interpolate signal by a factor of 2 from 22.05 kHz to 44.1 kHz.

cicint = dsp.CICInterpolator(2);

%
% Create fixed-point sinusoidal input signal of 512 samples, with a sampling frequency 22.05 kHz.

Fs = 22.05e3;      
n = (0:511)';      % 0.0113 sec signal
x = fi(sin(2*pi*1e3/Fs*n),true,16,15);

%
% Create dsp.SignalSource System object.

src = dsp.SignalSource(x,32);

%
% Interpolate the output with 64 samples per frame.

y = zeros(16,64);
for ii = 1:16
     y(ii,:) = cicint(src());   
end

%
% Plot the first frame of the original and interpolated signals. Output latency is 2 samples.

gainCIC = ...
   (cicint.InterpolationFactor*cicint.DifferentialDelay)...
   ^cicint.NumSections/cicint.InterpolationFactor;
stem(n(1:31)/Fs, double(x(1:31)),'r','filled')
hold on; 
stem(n(1:61)/(Fs*cicint.InterpolationFactor), ...
   double(y(1,4:end))/gainCIC,'b') 
xlabel('Time (sec)')
ylabel('Signal Amplitude')
legend('Original signal','Interpolated signal',...
   'location','north')
hold off;

%
% Using the info method in 'long' format, obtain the word lengths and fraction lengths of the fixed-point filter sections and the filter output.

info(cicint,'long')

% Copyright 2012 The MathWorks, Inc.