0% found this document useful (0 votes)
76 views9 pages

Lab 4

This document contains the code and output from a digital signal processing lab session. The tasks involve: 1) Generating a continuous time sinusoid and converting it to discrete time at different sampling frequencies. 2) As the sampling frequency increases, the number of samples increases. 3) For a 100Hz signal, the minimum sampling rate to avoid aliasing is 100Hz. Sampling at 200Hz reconstructs the signal, while sampling at 75Hz results in aliasing with a 25Hz signal.

Uploaded by

shakaib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
76 views9 pages

Lab 4

This document contains the code and output from a digital signal processing lab session. The tasks involve: 1) Generating a continuous time sinusoid and converting it to discrete time at different sampling frequencies. 2) As the sampling frequency increases, the number of samples increases. 3) For a 100Hz signal, the minimum sampling rate to avoid aliasing is 100Hz. Sampling at 200Hz reconstructs the signal, while sampling at 75Hz results in aliasing with a 25Hz signal.

Uploaded by

shakaib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 9

DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED

(EL-303) ROLL NO:2018-EL-003

TASK 1:
▪ Write a script to generate a continuous time sinusoid signal with amplitude=2 for a
time 0 to 1 sec and taken the frequency as a user input by using input command.
PROGRAM:
clc
t=[0:0.01:1];
f=input('ENTER FREQUENCY= ')
y=2*cos(2*pi*f*t);
plot(t,y,'b','linewidth',4)
xlabel('TIME')
ylabel('AMPLITUDE')
title('CONTINOUS TIME SIGNAL')

OUTPUT:

DEPARTMENT OF ELECTRICAL ENGINEERING


SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED
(EL-303) ROLL NO:2018-EL-003

TASK 2:
▪ Write a script to convert continuous time signal of task#1 to a discrete time signal and
take the sampling frequency as input which should be less than twice the maximum
signal frequency in Hertz.
PROGRAM:
clc
t=[0:0.01:1];
f=input('ENTER FREQUENCY= ')
y=2*cos(2*pi*f*t);
subplot(2,1,1)
plot(t,y,'b','linewidth',4)
xlabel('TIME')
ylabel('AMPLITUDE')
title('CONTINOUS TIME SIGNAL')
b=input('ENTER VALUE OF SAMPLING FREQUENCY= ')
n=[-10:1/b:10];
z=2*cos(2*pi*f*n);
subplot(2,1,2)
stem(n,z,'r','filled','linewidth',2)
xlabel('TIME')
ylabel('AMPLITUDE')
title('DISCRETE TIME SIGNAL')
A = ['VALUE OF FREQUENCY= ',num2str(f)]
text(4,8,A,'FontSize',14)
B= ['VALUE OF SAMPLING FREQUENCY= ',num2str(b)]
text(4,2.5,B,'FontSize',14)
grid on

DEPARTMENT OF ELECTRICAL ENGINEERING


SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED
(EL-303) ROLL NO:2018-EL-003

OUTPUT:

TASK 3:
▪ Write a script to convert continuous time signal of task#1 to a discrete time signal and
take the sampling frequency as input which should be equal to twice the maximum
signal frequency in Hertz.
PROGRAM:
clc
t=[0:0.01:1];
f=input('ENTER FREQUENCY= ')
y=2*cos(2*pi*f*t);
subplot(2,1,1)
plot(t,y,'b','linewidth',4)
xlabel('TIME')
ylabel('AMPLITUDE')
title('CONTINOUS TIME SIGNAL')
b=input('ENTER VALUE OF SAMPLING FREQUENCY= ')
n=[0:1/b:1];
z=2*cos(2*pi*f*n);
subplot(2,1,2)
DEPARTMENT OF ELECTRICAL ENGINEERING
SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED
(EL-303) ROLL NO:2018-EL-003

stem(n,z,'r','filled','linewidth',2)
xlabel('TIME')
ylabel('AMPLITUDE')
title('DISCRETE TIME SIGNAL')
i=['FREQUENCY=',num2str(f)]
text(0,3,i,'FontSize',14)
j=['SAMPLING FREQUENCY=',num2str(b)]
text(0,2.5,j,'FontSize',14)
grid on

OUTPUT:

TASK 4:
▪ Write a script to convert continuous time signal of task#1 to a discrete time signal and
take the sampling frequency as input which should be greater than twice the maximum
signal frequency in Hertz.
PROGRAM:
clc
t=[0:0.01:1];
f=input('ENTER FREQUENCY= ')
y=2*cos(2*pi*f*t);

DEPARTMENT OF ELECTRICAL ENGINEERING


SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED
(EL-303) ROLL NO:2018-EL-003

subplot(2,1,1)
plot(t,y,'b','linewidth',4)
xlabel('TIME')
ylabel('AMPLITUDE')
title('CONTINOUS TIME SIGNAL')
b=input('ENTER VALUE OF SAMPLING FREQUENCY= ')
n=[0:1/b:1];
z=2*cos(2*pi*f*n);
subplot(2,1,2)
stem(n,z,'r','filled','linewidth',2)
xlabel('TIME')
ylabel('AMPLITUDE')
title('DISCRETE TIME SIGNAL')
i=['FREQUENCY=',num2str(f)]
text(0,3,i,'FontSize',14)
j=['SAMPLING FREQUENCY=',num2str(b)]
text(0,2.5,j,'FontSize',14)
grid on

OUTPUT:

DEPARTMENT OF ELECTRICAL ENGINEERING


SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED
(EL-303) ROLL NO:2018-EL-003

TASK 5:
▪ Write a script using subplot command to generate task #1, task#2, task#3 and task#4
plots. Analyze the four plots, what happens by increasing the sampling frequency?
PROGRAM:
clc
t=[0:0.01:1];
f=10;
f1=15;
f2=20;
f3=25;
y=2*cos(2*pi*f*t);
subplot(4,1,1)
plot(t,y,'b','linewidth',4)
xlabel('TIME')
ylabel('AMPLITUDE')
title('CONTINOUS TIME SIGNAL')
c=['FREQUENCY=',num2str(f)]
text(0,2.5,c,'FontSize',10)
grid on
n=[0:1/f1:1];
z=2*cos(2*pi*f*n);
subplot(4,1,2)
stem(n,z,'r','filled','linewidth',2)
xlabel('TIME')
ylabel('AMPLITUDE')
title('DISCRETE TIME SIGNAL fs<2fmax')
j=['SAMPLING FREQUENCY=',num2str(f1)]
text(0,2.5,j,'FontSize',10)
grid on
n1=[0:1/f2:1];
z1=2*cos(2*pi*f*n1);
subplot(4,1,3)
stem(n1,z1,'g','filled','linewidth',2)
xlabel('TIME')
ylabel('AMPLITUDE')
title('DISCRETE TIME SIGNAL fs=2fmax')
l=['SAMPLING FREQUENCY=',num2str(f2)]
text(0,2.5,l,'FontSize',10)
DEPARTMENT OF ELECTRICAL ENGINEERING
SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED
(EL-303) ROLL NO:2018-EL-003

grid on
n2=[0:1/f3:1];
z2=2*cos(2*pi*f*n2);
subplot(4,1,4)
stem(n2,z2,'y','filled','linewidth',2)
xlabel('TIME')
ylabel('AMPLITUDE')
title('DISCRETE TIME SIGNAL fs>2fmax')
p=['SAMPLING FREQUENCY=',num2str(f3)]
text(0,2.5,p,'FontSize',10)
grid on

OUTPUT:

In above output we observe that as we increase in the value of sampling


frequency number of samples are increased.

DEPARTMENT OF ELECTRICAL ENGINEERING


SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED
(EL-303) ROLL NO:2018-EL-003
TASK 6:
Consider the analog signal xa(t)=3cos(100πt)
▪ Determine the minimum sampling rate required to avoid aliasing.
▪ Suppose that the signal is sampled at the rate Fs=200 Hz. What is the discrete time
signal obtained after sampling? Plot the discrete-time signal.
▪ Suppose that the signal is sampled at the rate Fs=75 Hz. What is the discrete time
signal obtained after sampling? Plot the discrete-time signal.
▪ What is the frequency 0<F<Fs/2 of a sinusoid that yields samples identical to those
obtained in part (iii)? Give your observation regarding Aliasing effect.
PROGRAM:

• In order to avoiding aliasing the minimum sampling rate will be 100Hz.

• clc
Fs=200;
n=[0:1/Fs:0.1];
z=3*cos(100*pi*n);
stem(n,z,'r','filled','linewidth',2)
xlabel('TIME')
ylabel('AMPLITUDE')
title('DISCRETE TIME SIGNAL')
grid on
OUTPUT:

DEPARTMENT OF ELECTRICAL ENGINEERING


SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY
DIGITAL SIGNAL PROCESSING LAB SESSION #04 NAME:SYED SHAKAIB AHMED
(EL-303) ROLL NO:2018-EL-003

• clc
Fs=75;
n=[0:1/Fs:0.1];
z=3*cos(100*pi*n);
stem(n,z,'r','filled','linewidth',2)
xlabel('TIME')
ylabel('AMPLITUDE')
title('DISCRETE TIME SIGNAL')
grid on

OUTPUT:

• By using the formula Fs-F we get a frequency of 25Hz which is lie in the
range which Is give in part 4.The frequency which we get from formula is
sampled with 75Hz,DT signal remain same as signal of frequency of
50Hz.This is the aliased version of unique signal.

DEPARTMENT OF ELECTRICAL ENGINEERING


SIR SYED UNIVERSITY OF ENGINEERING & TECHNOLOGY

You might also like