Lab 4
Lab 4
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:
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
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);
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:
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:
• 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:
• 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.