%% Decimate a Sum of Sine Waves
% Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For example, myObject(x) becomes step(myObject,x).
% 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)');
firdecim = dsp.FIRDecimator;
y = firdecim(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');

% Copyright 2012 The MathWorks, Inc.