This example shows how to filter before downsampling to mitigate the distortion caused by aliasing. You can use decimate or resample to filter and downsample with one function. Alternatively, you can lowpass filter your data and then use downsample. Create a signal with baseband spectral support greater than π radians. Use decimate to filter the signal with a 10-th order Chebyshev type I lowpass filter prior to downsampling.
Create the signal and plot the magnitude spectrum.
F = [0 0.2500 0.5000 0.7500 1.0000]; A = [1.00 0.6667 0.3333 0 0]; Order = 511; B = fir2(Order,F,A); [Hx,W] = freqz(B,1,8192,'whole'); Hx = [Hx(4098:end) ; Hx(1:4097)]; omega = -pi+(2*pi/8192):(2*pi)/8192:pi; plot(omega,abs(Hx)); set(gca,'xlim',[-pi pi]); set(gca,'xtick',[-pi -3*pi/4 -pi/2 0 pi/2 3*pi/4 pi]); grid on; title('Magnitude Spectrum'); xlabel('Radians/Sample'); ylabel('Magnitude');
Filter the signal with a 10-th order type I Chebyshev lowpass filter and downsample by 2. Plot the magnitude spectra of the original signal along with the filtered and downsampled signal.
y = decimate(B,2,10); [Hy,W] = freqz(y,1,8192,'whole'); Hy = [Hy(4098:end) ; Hy(1:4097)]; plot(omega,abs(Hx)); hold on; plot(omega,abs(Hy),'r','linewidth',2); set(gca,'xlim',[-pi pi]); grid on; legend('Original Signal','Downsampled Signal'); xlabel('Radians/Sample'); ylabel('Magnitude');
The lowpass filter reduces the amount of aliasing distortion outside the interval [-π/2, π/2].