Lab Report 1
Lab Report 1
Lab Rubrics
10-9 8-7 6-5 4-0
CLO-3 Perfect report Format not Format not followed Format not followed
and completed followed. with some sections with major
Communication through all sections and completed all missing sections/conclusion
Report and viva sections missing
Signed By
Engr. Afshan Ishaq (Course Instructor)
1
Digital Signal Processing Electronic Department Abbottabad Spring -2024
Table of Contents
1.1 Objective...............................................................................................................................................4
1.2 USES.................................................................................................................................................4
1.3 Instructions............................................................................................................................................4
1.4 TASK 01..................................................................................................................................................4
1.4.1 Given Code.....................................................................................................................................5
1.4.2 Updated Code for Removed Glitches.............................................................................................5
1.4.4 Output Waveform...........................................................................................................................6
1.5 TASK 2....................................................................................................................................................6
1.5.1 Given Code.....................................................................................................................................6
1.6 TASK 3 (Part 1).......................................................................................................................................7
1.7 TASK 3 (Part 2).......................................................................................................................................8
1.7.1 Matlab Code...................................................................................................................................8
1.7.2 Output Waveform...........................................................................................................................8
1.8 Task 1.....................................................................................................................................................9
1.8.1 Matlab Code.......................................................................................................................................9
1.9 Task 2 (Part I).........................................................................................................................................9
1.9.1 Matlab Code.................................................................................................................................10
1.9.2 Output Waveform.........................................................................................................................11
1.10 Task 2 (Part II)....................................................................................................................................11
1.10.1 Matlab Code...............................................................................................................................11
1.10.2 Output Waveform.......................................................................................................................12
1.11 Task 4.................................................................................................................................................12
1.11.1 Matlab Code...............................................................................................................................12
1.11.2 Output Waveform.......................................................................................................................13
1.12 Task 1 (Part 1 : Unit Step Sequence)..................................................................................................13
1.12.1 Matlab Code...............................................................................................................................13
1.12.2 Output Waveform.......................................................................................................................14
1.13 TASK 1 (PART 2: Sine Signal)..............................................................................................................14
1.13.1 Matlab Code...............................................................................................................................14
1.13.2 Output Waveform.......................................................................................................................15
1.14 TASK 1 (Part 3 : Unit Step Signal).......................................................................................................15
1.14.1 Matlab Code..........................................................................................................................15
2
Digital Signal Processing Electronic Department Abbottabad Spring -2024
1.14.2 Output Waveform.......................................................................................................................16
1.15 TASK 1 (PART 5 : Cosine Wave)..........................................................................................................16
1.15.1 Matlab Code...............................................................................................................................16
1.15.2 Output Waveform.......................................................................................................................17
1.16 TASK 1 (PART 5: Unit Ramp Function)................................................................................................17
1.16.1 Matlab Code...................................................................................................................................17
1.16.2 Output Waveform.......................................................................................................................18
1.17 TASK 1 (PART 6: Exponential signal)..................................................................................................18
1.17.1 Matlab Code...............................................................................................................................18
1.17.2 Output Waveform.......................................................................................................................19
3
Digital Signal Processing Electronic Department Abbottabad Spring -2024
LAB NO. 1
PLOT THE BASIC SIGNALS AND MANIPULATE THEM USING
DIFFERENT COMMANDS IN MATLAB
1.1 Objective
The objective of this lab is to plot the some commonly used sequences using graphic editor of
Matlab and also find some parameters of signals using Matlab commands like sum, max, min,
find etc.
PRE LAB
1. What is eps in Matlab?
1.2 USES
1.3 Instructions
You have to
plot the tutorial m-files, Label them properly (x-axis-axis,Title,legends)
every graph title (‘whatever is plotted (class no)
Comment your M-files
Conclusion(suggestion) must be possibly on the graph
1.4 TASK 01
Q1. Following is an m-file to generate a signal and its samples, Remove the glitches so that the
graph is smooth.
A=5;
4
Digital Signal Processing Electronic Department Abbottabad Spring -2024
F0=2;
T0=1/F0;
theta= pi/4;
Fsam=10;
Tsam=1/Fsam;
dur=5*T0;
t=0:Tsam:dur;
x=A*cos(2*pi*F0*t+theta);
figure(1)
plot(t,x);
hold on
stem(t,x)
title('continous time siganl for 15 msec')
xlabel('time in msec')
ylabel('freq in Hertz’)
%%Huma Tariq
A=5;
F0=0.6;
T0=1/F0;
theta= pi/4;
A=5;
F0=0.5;
T0=1/F0;
theta= pi/4;
Fsam=10;
Tsam=1/Fsam;
dur=5*T0;
t=0:Tsam:dur;
x=A*cos(2*pi*F0*t+theta);
plot(t,x);
hold on
stem(t,x)
title('Continous Time Siganl For 15 msec (Huma Tariq,Class No 2)')
xlabel('Time in milli sec')
ylabel('Freq in Hertz')
1.4.3 Discussion
5
Digital Signal Processing Electronic Department Abbottabad Spring -2024
This MATLAB code generates a cosine signal with an amplitude of 5, frequency of 2 Hz, and a
phase shift of π/4. It samples the signal at 10 Hz for 5 periods and plots both the continuous and
sampled signals together for comparison.
1.5 TASK 2
Q1. Find command
x=[-4:4]
x= -4 -3 -2 -1 0 1 2 3 4
ans = 6
>>x(ans)
6
Digital Signal Processing Electronic Department Abbottabad Spring -2024
=1
>>theta=[-pi:pi/1024:pi]
n=[-5:5];
x1=zeros(size(n));
ind1=find(n==4);
x1(ind1)=0.5;
stem(n,x1,'fill');
xlabel('Time (sec)');
axis([-5,5,0,1]);
Figure 2: Plot
7
Digital Signal Processing Electronic Department Abbottabad Spring -2024
1.7.1 Matlab Code
%%Huma Tariq
n=[-10:2];
x2=zeros(size(n));
ind1=find(n==-7);
ind2=find(n==1);
x2(ind1)=4.5;
x2(ind2)=1.5;
stem(n,x2,'fill');
xlabel('Time (sec)');
ylabel('Amplitude');
title('Impulse Response at -7 AND 1(Huma Tariq ,Class NO 2)')
axis([-10,2,0,5]);
IN LAB TASKS
Q1. Plot the sequence based on unit step signal
8
Digital Signal Processing Electronic Department Abbottabad Spring -2024
1.8 Task 1
%%Huma Tariq
n=[0:10];
x1=zeros(size(n));
ind1=find(n>=0);
ind2=find(n>=5);
u=x1;
9
Digital Signal Processing Electronic Department Abbottabad Spring -2024
v=x1;
u(ind1)=1;
v(ind2)=1;
x2=u-v;
subplot(3,1,1);
stem(n,u);
xlabel('Time(sec)')
ylabel('Amplitude')
title('Unit Step Signal (Huma Tariq,Roll no 2)')
axis([0,10,0,1])
subplot(3,1,2);
stem(n,v);
xlabel('Time(sec)')
ylabel('Amplitude')
title('Unit Step Signal at n=5 (Huma Tariq,Roll no 2)')
axis([0,10,0,1])
subplot(3,1,3);
stem(n,x2)
xlabel('Time(sec)')
ylabel('Amplitude')
title('Subtraction of Unit Step Signal (Huma Tariq,Roll no 2)')
axis([0,10,0,1])
10
Digital Signal Processing Electronic Department Abbottabad Spring -2024
1.9.2 Output Waveform
%Huma Tariq
n=[-10:10];
x1=zeros(size(n));
u=x1;
v=x1
ind1=find((-n+4)>=0);
ind2=find(n>=0);
u(ind1)=1;
v(ind2)=1;
subplot(3,1,1)
stem(n,v);
xlabel('Time(sec)');
ylabel('Amplitude');
title('Unit Step Signal (Huma Tariq,Class NO 2)')
11
Digital Signal Processing Electronic Department Abbottabad Spring -2024
x2=u.*v
subplot(3,1,2)
stem(n,u);
xlabel('Time(sec)')
ylabel('Amplitude')
title('Unit Step Signal of -n+4(Huma Tariq,Class NO 2)')
subplot(3,1,3)
stem(n,x2);
xlabel('Time(sec)');
ylabel('Amplitude');
title('Multiplication of Two Unit Step Signal (Huma Tariq,Class NO 2)')
12
Digital Signal Processing Electronic Department Abbottabad Spring -2024
1.11 Task 4
x6(n) = x5(n-2)
%%Huma Tariq
n=[0:10];
x=zeros(size(n));
u=x;
v=x;
ind1=find((-n+6)>=0);
ind2=find((n-2)>=0);
u(ind1)=1;
v(ind2)=1;
x1=0.5*v.*u;
stem(n,x1);
xlabel('Time(sec)');
ylabel('Amplitude');
title('Plot of 2<u(n)<6 (Huma Tariq ,Class NO 2)')
13
Digital Signal Processing Electronic Department Abbottabad Spring -2024
1.12 Task 1 (Part 1 : Unit Step Sequence)
%%Huma Tariq
t=[0:0.01:10]
N=20;
Sequence = ones(1,N);
stem(Sequence);
xlabel('Samples');
ylabel('Amplitude');
title('Unit Step Sequence (Huma Tariq ,Class NO 2)');
%%Huma Tariq
t=[0:0.01:10]
Result=sin(2*pi*t);
14
Digital Signal Processing Electronic Department Abbottabad Spring -2024
plot(t,Result);
xlabel('Time(sec)');
ylabel('Amplitude');
title('Sine Wave (Huma Tariq,Class NO 2)');
%%Huma Tariq
n=[-50:50];
x1=zeros(size(n));
u=x1;
v=x1
ind1=find((-n+4)>=0);
ind2=find(n>=0);
u(ind1)=1;
v(ind2)=1;
stem(n,v);
xlabel('Time(sec)');
ylabel('Amplitude');
15
Digital Signal Processing Electronic Department Abbottabad Spring -2024
title('Unit Step Signal From -50 to +50 (Huma Tariq,Class NO 2)')
%%Huma Tariq
t=[0:0.01:10]
Result=cos(2*pi*t);
plot(t,Result);
xlabel('Time(seconds)');
ylabel('Amplitude');
title('Cosine Wave (Huma Tariq ,Class NO 2)');
16
Digital Signal Processing Electronic Department Abbottabad Spring -2024
1.15.2 Output Waveform
1.16.2 Output
Waveform
17
Digital Signal Processing Electronic Department Abbottabad Spring -2024
%%Huuma Tariq
t=[0:0.01:10]
A=5;
alpha = 0.5; %% Decay constant
Exponential_Signal = A* exp(alpha*t);
plot(t,Exponential_Signal);
xlabel('Samples');
ylabel('Amplitude');
title('Exponential Signal (Huma Tariq, Class NO 2)');
18
Digital Signal Processing Electronic Department Abbottabad Spring -2024
19