DSP Lab 03
DSP Lab 03
LAB # 03
ALIASING EFFECT IN TIME AND FREQUENCY DOMAIN
OBJECT:
Aliasing Effect in Time and Frequency Domain
Continuous Time and Discrete Time functions using sinc
Aliasing Effect in the Time Domain
Aliasing Effect in the Frequency-Domain
Practice Aliasing Using Simulink
sinccomputes the sinc function of an input vector or array, where the sinc function is:
{
1, t=0
sinc ( t )= sinc (πt)
t≠0
πt
t=linspace(-5,5,50); % generates lineraly spaced vectors. It gives direct control over the number of
points.
y=sinc(t); %returns an array y the same size as x, whose elements are the sinc function of the element of
x.
subplot(2,1,1)
plot(t,y)
subplot(2,1,2)
stem(t,y);
xlabel('Time (sec)');
ylabel('Amplitude');
title('Since Function')
Section A
With Aliasing
clf;
f=13;%frequency of sinusoid=13 Hz
T = 1/(13*1.5); %Sampling rate (1/T) is not following Nyquist sampling theorem
n = (0:T:1)';
xs = cos(2*pi*f*n);
t = [-0.5:0.004:1.5]';
ya = sinc((1/T)*t(:,ones(size(n))) - (1/T)*n(:,ones(size(t)))')*xs;
%This is Reconstruction lowpassfiltering,implemented in time-domain
subplot(2,1,1)
plot(n,xs,'o',t,ya);grid;%Reconstructed CT signal
xlabel('Time, sec');ylabel('Amplitude');
title('Reconstructed continuous-time signal y_{a}(t)');
axis([0 1 -1.2 1.2]);
subplot(2,1,2)
t=0:0.0005:1;
xa=cos(2*pi*f*t); %original CT Signal
plot(t,xa);grid;
xlabel('Time,sec');
ylabel('Amplitude');
title('Orignal Continuous-time signal x_{a}(t)');
axis([0 1 -1.2 1.2]);
%Note: Both Time-domain plots are not same, because of Aliasing.
Without Aliasing
clf;
f=13;%frequency of sinusoid=13 Hz
T = 1/(13*2); %Sampling rate (1/T) is following Nyquist sampling theorem
n = (0:T:1)';
xs = cos(2*pi*f*n); %cos(w0 k) where k is integer and w0 =2*pi*f*T=2.6*pi
t = [-0.5:0.004:1.5]';
ya = sinc((1/T)*t(:,ones(size(n))) - (1/T)*n(:,ones(size(t)))')*xs;
%This is Reconstruction lowpassfiltering,implemented in time-domain
subplot(2,1,1)
plot(n,xs,'o',t,ya);grid;%Reconstructed CT signal
xlabel('Time, sec');ylabel('Amplitude');
title('Reconstructed continuous-time signal y_{a}(t)');
axis([0 1 -1.2 1.2]);
subplot(2,1,2)
t=0:0.0005:1;
xa=cos(2*pi*f*t); %original CT Signal
plot(t,xa);grid;
xlabel('Time,sec');
ylabel('Amplitude');
title('Orignal Continuous-time signal x_{a}(t)');
axis([0 1 -1.2 1.2]);
Section B
CE-320L: Digital System Processing Page 3 SSUET/QR/114
M.Umer Ahsan LAB # 03 CE-118-2020
subplot(2,2,2)
fa=0:0.001:10;
wa=2*pi*fa;
Xa=2./((1-wa.^2)+1i*2*wa); %Xa is freq. specturm (i.e CT Fourier Transform) of xa. It's a non-
bandlimited signal
plot(fa(1:1500), abs(Xa(1:1500))); grid
xlabel('Frequency, Hz');
ylabel('Amplitude');
title('Xa Frequency spectrum');
subplot(2,2,3)
T=0.5; %Sampling-Rate selected as 2 Hz
%Aliasing will always occur as this is non-bandlimited signal
n=0:T:10;
xs=2*n.*exp(-n); % Actually sampled xs=2*T*n.*exp(-T.*n)
k=0:length(n)-1;
stem(k,xs);
grid;
xlabel('Time index n');
ylabel('Amplitude');
title('Discrete-timrdignal x[n]');
subplot(2,2,4)
wd=0:pi/255:pi;
Xs=freqz(xs,1,wd); %Xs is Freq. spectrum (i,e. DT Fourier Transform) of xs
%CTFT of upto freq. 1 Hz(Nyquist frequency) has been captured by DTFT (and
%the rest discraded), because sampling-rate is 2 Hz.
plot(wd/(2*T*pi),T*abs(Xs));
grid;
xlabel('Frequency Hz');
ylabel('Amplitude');
title('Xs Frequency spectrum');
Section C
Assignment Task
Aliasing Using Simulink
Now to observe the effects of aliasing.
Explanation: Two continuous signals having two frequencies, one is 40 Hz and other 140
Hz. Both sampled at 100 samples/sec. but the plots of both signals are same. It means that
40 Hz and 140 Hz are alias frequencies when sampled at 100 samples/sec
HOME TASK:
TASK # 01: Write a script to construct a continuous time sinusoid signal with amplitude=2 for
a time t and take the frequency as a user input by using input command.
Coding:
Result:
TASK # 02: Write a script to construct continuous time signal of task #1 to a discrete time
signal and take the analog frequency as input. Sampling frequency should be less than twice of
analog signal frequency in Hertz.
Coding:
Result:
TASK # 03: Write a script to construct continuous time signal of task#1 to a discrete time
signal and take the analog frequency as input. Sampling frequency should be equal to twice of
analog signal frequency in Hertz.
Coding:
Result:
TASK # 04: Write a script to construct continuous time signal of task#1 to a discrete time
signal and take the analog frequency as input. Sampling frequency should be greater than twice
of analog signal frequency in Hertz.
Coding:
Result:
TASK # 05: Write a script using subplot command to construct task #1, task#2, task#3 and
task#4 plots. Analyze the four plots, what happens by increasing the sampling frequency?
Coding:
Result: