Documentation Center

  • Trial Software
  • Product Updates

Downsampling — Aliasing

This example shows how to avoid aliasing when downsampling a signal. If a discrete-time signal's baseband spectral support is not limited to an interval of width 2π/M radians, downsampling by M results in aliasing. Aliasing is the distortion that occurs when overlapping copies of the signal's spectrum are added together. The more the signal's baseband spectral support exceeds 2π/M radians, the more severe the aliasing. Demonstrate aliasing in a signal downsampled by two. The signal's baseband spectral support exceeds π radians in width.

Create a signal with baseband spectral support equal to 3π/2 radians. Use fir2 to design the signal. Plot the signal's spectrum.

F = [0 0.2500 0.5000 0.7500 1.0000];
A = [1.00  0.6667 0.3333 0 0];
Order = 511;
B1 = fir2(Order,F,A);
[Hx,W] = freqz(B1,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 -pi/2 0 pi/2 pi]);
grid on;
title('Magnitude Spectrum');
xlabel('Radians/Sample'); ylabel('Magnitude');

You see that the signal's baseband spectral support exceeds [-π/2, π/2].

Downsample the signal by a factor of 2 and plot the downsampled signal's spectrum with the spectrum of the original signal.

y = downsample(B1,2,0);
[Hy,W] = freqz(y,1,8192,'whole');
Hy = [Hy(4098:end) ; Hy(1:4097)];
hold on;
plot(omega,abs(Hy),'r','linewidth',2);
set(gca,'xlim',[-pi pi]);
legend('Original Signal','Downsampled Signal');

In addition to an amplitude scaling of the spectrum, the superposition of overlapping spectral replicas causes distortion of the original spectrum for |ω|>π/2.

Increase the baseband spectral support of the signal to [-7π/8, 7π/8] and downsample the signal by 2. Plot the original spectrum along with the spectrum of the downsampled signal.

F = [0 0.2500 0.5000 0.7500  7/8 1.0000];
A = [1.00 0.7143 0.4286 0.1429 0 0];
Order = 511;
B2 = fir2(Order,F,A);
[Hx,W] = freqz(B2,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]);
y = downsample(B2,2,0);
[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 increased spectral width results in more pronounced aliasing in the spectrum of the downsampled signal because more signal energy is outside [-π/2, π/2].

Finally, construct a signal with baseband spectral support limited to [-π/2, π/2]. Downsample the signal by a factor of 2 and plot the spectrum of the original and downsampled signals. The downsampled signal is full band, but the shape of the spectrum is preserved because the spectral copies do not overlap. There is no aliasing.

F = [0 0.250 0.500 0.7500 1];
A = [1.0000 0.5000 0 0 0];
Order = 511;
B3 = fir2(Order,F,A);
[Hx,W] = freqz(B3,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]);
y = downsample(B3,2,0);
[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');

You see in the preceding figure that the shape of the spectrum is preserved. The spectrum of the downsampled signal is a stretched and scaled version of the original signal's spectrum, but there is no aliasing.

Was this topic helpful?