www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/InterpolateASignalUsingCICInterpolatorObjectExample.m

    %% Interpolate a Signal Using CICInterpolator Object
% Interpolate signal by a factor of 2 (upsample the signal from 22.05 kHz
% to 44.1 kHz).
hcicint = dsp.CICInterpolator(2);

%%
% Create fixed-point sinusoidal input signal 
Fs = 22.05e3;      % Original sampling frequency
n = (0:511)';      % 512 samples, 0.0113 sec signal
x = fi(sin(2*pi*1e3/Fs*n),true,16,15); 

%%
% Create SignalSource System object (TM).
hsr = dsp.SignalSource(x, 32); 

%%
% Interpolate output with 64 samples per frame
y = zeros(16,64);
for ii=1:16
     y(ii,:) = step(hcicint,step( hsr ));   
end

%%
% Plot first frame of original and interpolated signals.
% Output latency is 2 samples.  
gainCIC = ...
   (hcicint.InterpolationFactor*hcicint.DifferentialDelay)...
   ^hcicint.NumSections/hcicint.InterpolationFactor;
stem(n(1:31)/Fs, double(x(1:31)),'r','filled'); hold on; 
stem(n(1:61)/(Fs*hcicint.InterpolationFactor), ...
   double(y(1,4:end))/gainCIC,'b'); 
xlabel('Time (sec)');ylabel('Signal Amplitude');
legend('Original signal', 'Interpolated signal',...
   'location', 'north');
hold off;