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

    %% Decimate a Signal Using CICDecimator Object
% Decimate signal by a factor of 4 (i.e., downsample the signal from 
% 44.1 kHz to 11.025 kHz).
hcicdec = dsp.CICDecimator(4);  
hcicdec.FixedPointDataType = 'Minimum section word lengths'; 
hcicdec.OutputWordLength = 16; 

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

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

%%
% Decimate output with 16 samples per frame
y = zeros(16,16);
for ii=1:16
     y(ii,:) = hcicdec(hsr());   
end

%%
% Plot first frame of original and decimated signals.
% Output latency is 2 samples.  
gainCIC = ...
   (hcicdec.DecimationFactor*hcicdec.DifferentialDelay)^hcicdec.NumSections;
stem(n(1:56)/Fs, double(x(4:59))); hold on;     
stem(n(1:14)/(Fs/hcicdec.DecimationFactor),double(y(1,3:end))/gainCIC,'r','filled'); 
xlabel('Time (sec)');ylabel('Signal Amplitude');
legend('Original signal', 'Decimated signal', 'location', 'north');
hold off;