www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/DecimateASumOfSineWavesExample.m
%% Decimate a Sum of Sine Waves % This example shows how to decimate a sum of sine waves with angular % frequencies of pi/4 and 2pi/3 radians/sample by a factor of two. % To prevent aliasing, the FIR decimator filters out the 2pi/3 radians/sample % component before downsampling. x = cos(pi/4*[0:95]')+sin(2*pi/3*[0:95]'); H = dsp.FIRDecimator; y = H(x); %% % View group delay of default FIR filter fvtool(fir1(35,0.4),1,'analysis','grpdelay'); %% % Group delay of the default linear-phase FIR filter % is 17.5 samples. Downsampling by a factor of % two expect an approx. 8.75 sample delay in the output % y with the initial filter states of zero subplot(211); stem(x(1:length(x)/2),'b','markerfacecolor',[0 0 1]); title('Input Signal'); subplot(212); stem(y,'b','markerfacecolor',[0 0 1]); title('Output--Lowpass filtered and downsampled by 2');