Name: Zulfiqar Ali.: Department of Electronic Engineering University of Engineering and Technology Abbottabad Campus

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

Name: Zulfiqar Ali.

DEPARTMENT OF ELECTRONIC ENGINEERING


UNIVERSITY OF ENGINEERING AND TECHNOLOGY
ABBOTTABAD CAMPUS

Registration No: 17ABELT0736


Subject: “DIGITAL SIGNAL PROCESSING”
Date of Conduction:
Date of Submission:
Particulars Max. Marks Marks Obtained
Pre-Lab
Lab Performance
Post-Lab
Lab Report
Total

REPORT VERIFICATION

Date: 8/19/2020

Instructor Name: Prof Afshan Ishaq.

Signature:
Inlab Task:

PLOTTING CONTINUOUS TIME SIGNAL:

Task1:COSINE SIGNAL PLOT:


t=-10:0.001:10;
z=cos(2*t);
figure(1)
plot(t,z,'b','linewidth',3),grid on;
legend({'cos2t'},'FontSize',14,'FontName','Times New Roman')
xlabel('Time (second)','FontSize',14,'FontName','Times New Roman');
ylabel('Amplitude','FontSize',14,'FontName','Times New Roman');

Graph:

Task2:Plotting Decaying And Increasing Discrete Time Exponentials:


% if b is +ive then increasing exp or if b is -ive then decreasing exp
n=-3:3
b1=-2
b2=2
A=1
y33=A*exp(b1*n)
y44=A*exp(b2*n)
s(1)=subplot(2,1,1)
stem(n,y33,'b','linewidth',3),grid on
legend(s(1),'y33[n]')
xlabel(s(1),'Time(second)','FontSize',14,'FontName','Times New Roman')
ylabel(s(1),'Decaying exponential','FontSize',14,'FontName','Times New Roman')
title(s(1),'Decaying','FontSize',14,'FontName','Times New Roman')
axis(s(1),[min(n)-1 max(n)+1 min(y33) max(y33)])
s(2)=subplot(2,1,2)
stem(n,y44,'k','linewidth',3),grid on
legend(s(2),'y44[n]','FontSize',14,'FontName','Times New Roman')
xlabel('Time (second)','FontSize',14,'FontName','Times New Roman')
ylabel('Growing exponential','FontSize',14,'FontName','Times New Roman')
title('Growing','FontSize',14,'FontName','Times New Roman')
axis(s(2),[min(n)-1 max(n)+1 min(y33) max(y33)])

Graph:

Task-3: Write a MATLAB program for the ‘running average’, a running total is a sequence of
partial sum of a given sequence/signal. For example, the running totals of the signal {a, b, c,
…}are a, a+b, a+b+c, ... Use that program to find the running total of the discrete time signal of
length N=100. Write your program so that it is flexible. That is, you should be able to invoke
your program from the command window as follows:
>> y=running_averagel(x)
where x is the input signal, and y is the running total of that signal.
m-File Code:
%Moving Average Or Running Average
function y= runningaverage(x)
sum=0;
x=[1:100];
for i=1:100;
sum=sum+x(i);
y(i)=sum;
end
end

Command Window Code:


>> runningaverage()

ans =

Columns 1 through 7

1 3 6 10 15
21 28

Columns 8 through 14

36 45 55 66 78
91 105

Columns 15 through 21

120 136 153 171 190


210 231

Columns 22 through 28
253 276 300 325 351
378 406

Columns 29 through 35

435 465 496 528 561


595 630

Columns 36 through 42

666 703 741 780 820


861 903

Columns 43 through 49

946 990 1035 1081 1128


1176 1225

Columns 50 through 56

1275 1326 1378 1431 1485


1540 1596

Columns 57 through 63

1653 1711 1770 1830 1891


1953 2016

Columns 64 through 70
2080 2145 2211 2278 2346
2415 2485

Columns 71 through 77

2556 2628 2701 2775 2850


2926 3003

Columns 78 through 84

3081 3160 3240 3321 3403


3486 3570

Columns 85 through 91

3655 3741 3828 3916 4005


4095 4186

Columns 92 through 98

4278 4371 4465 4560 4656


4753 4851

Columns 99 through 100

4950 5050

Task-4: Write a program to compute the variance and mean of a signal x. The variance σ is
defined to be:
where ‘m’ is the mean value of the signal x. For signal x, use all the integers from 1 to 1000.

Code:
t=1:0.01:20;
%Let x be equal to cos(nt)
x=cos(0.01*t);
sum=0;
for i=1:length(x)
sum=sum+x(i);
end
mean=sum./length(x)
sum=0;
for i=1:length(x)
sum=sum+(x(i)-mean);
end
variance = sum./length(x)
Output:
>> t=1:0.01:20;
%Let x be equal to cos(nt)
x=cos(0.01*t);
sum=0;
for i=1:length(x)
sum=sum+x(i);
end
mean=sum./length(x)
sum=0;
for i=1:length(x)
sum=sum+(x(i)-mean);
end
variance = sum./length(x)

mean =

0.9930

variance =

1.7133e-15

Task-5: Can you explain what the following program does:


x=[-5,-4,-3,-2,-1,0,1,2,3,4,5];
L = length(x);
for I = 1: L
if x (I) < 0
x (I) = -1;
else
x(I) =1
end

end

Output:
>> x=[-5,-4,-3,-2,-1,0,1,2,3,4,5];

L = length(x);

for I = 1: L

if x (I) < 0

x (I) = -1;

else

x(I) =1

end

end

x =

-1 -1 -1 -1 -1 1 1 2 3 4
5

x =

-1 -1 -1 -1 -1 1 1 2 3 4
5
x =

-1 -1 -1 -1 -1 1 1 1 3 4
5

x =

-1 -1 -1 -1 -1 1 1 1 1 4
5

x =

-1 -1 -1 -1 -1 1 1 1 1 1
5

x =

-1 -1 -1 -1 -1 1 1 1 1 1 1

Task-6: Generate a step sequence u [n] as described in In-Lab section, use it to generate an

impulse as δ [n] = u[n] – u[n-1].

Code:
n=-10:10
figure(1)
u0= n>=0; %u(n)
stem(n,u0,'linewidth',3);
legend('u[n]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u0'},'FontSize',14,'FontName','Times New Roman')
title({'u[n]'},'FontSize',14,'FontName','Times New Roman')
figure(2)
u1= n>=1; %u(n-1)
stem(n,u1,'linewidth',3);
legend('u[n-1]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u1'},'FontSize',14,'FontName','Times New Roman')
title({'u[n-1]'},'FontSize',14,'FontName','Times New Roman')
figure(3)
y=u0-u1; %dellta(n)=u(n)-u(n-1)
stem(n,y,'linewidth',3);
legend('&[n]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'y'},'FontSize',14,'FontName','Times New Roman')
title({'&[n]'},'FontSize',14,'FontName','Times New Roman')

Graph:

u[n]
1
u[n]
0.9

0.8

0.7

0.6
u0

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
u[n-1]
1
u[n-1]
0.9

0.8

0.7

0.6
u1

0.5

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

&[n]
1
&[n]
0.9

0.8

0.7

0.6

0.5
y

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
Task-7: Generate an impulse sequence δ [n] as described in In-Lab section, use it to generate a
step sequence .

Code:
n=-10:10;
k=0:10;
u0= n>=0; %u(n)
u1= n>=length(k); %u(n-k)
y= (u0-u1); %dellta(n)=u(n)-u(n-1)
stem(n,y,'linewidth',3);
legend('&[n-k]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'y'},'FontSize',14,'FontName','Times New Roman')
title({'&[n-k]'},'FontSize',14,'FontName','Times New Roman')

Output:

&[n-k]
1
&[n-k]
0.9

0.8

0.7

0.6

0.5
y

0.4

0.3

0.2

0.1

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
Task-8: Generate the following sequences using step and impulse sequence.
a. x[n] = u[n] – u[n-10]

Code:
n=-20:20
figure(1)
u0= n>=0; %u(n)
stem(n,u0,'linewidth',3);
legend('u[n]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u0'},'FontSize',14,'FontName','Times New Roman')
title({'u[n]'},'FontSize',14,'FontName','Times New Roman')
figure(2)
u1= n>=10; %u(n-10)
stem(n,u1,'linewidth',3);
legend('u[n-10]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u1'},'FontSize',14,'FontName','Times New Roman')
title({'u[n-10]'},'FontSize',14,'FontName','Times New Roman')
figure(3)
y=u0-u1; %dellta(n)=u(n)-u(n-1)
stem(n,y,'linewidth',3);
legend('&[n]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'y'},'FontSize',14,'FontName','Times New Roman')
title({'&[n]'},'FontSize',14,'FontName','Times New Roman')

Graph:
u[n]
1
u[n]
0.9

0.8

0.7

0.6
u0

0.5

0.4

0.3

0.2

0.1

0
-20 -15 -10 -5 0 5 10 15 20
n
u[n-10]
1
u[n-10]
0.9

0.8

0.7

0.6
u1

0.5

0.4

0.3

0.2

0.1

0
-20 -15 -10 -5 0 5 10 15 20
n
&[n]
1
&[n]
0.9

0.8

0.7

0.6

0.5
y

0.4

0.3

0.2

0.1

0
-20 -15 -10 -5 0 5 10 15 20
n

b. x[n] = an u[n]

Code:
n=-10:10
a= 2;
figure(1)

u0=(0.*(n<0)+1.*(n>0)).*(a.^n); % x[n] = an u[n]


stem(n,u0,'linewidth',3);
legend('u[n]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'u0'},'FontSize',14,'FontName','Times New Roman')
title({'u[n]'},'FontSize',14,'FontName','Times New Roman')

Graph:
u[n]
1200
u[n]

1000

800
u0

600

400

200

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

c. Σan δ[n-k] , k = -10 to 10

Code:
n=-10:10;
k=0:10;
a=2;
u0= n>=0; %u(n)
u1= n>=length(k); %u(n-k)

y= (u0-u1).*(a.^n); %Σa
n δ[n-k] , k = -10 to 10
stem(n,y,'linewidth',3);
legend('&[n-k]','FontSize',14,'FontName','Times New Roman')
xlabel({'n'},'FontSize',14,'FontName','Times New Roman')
ylabel({'y'},'FontSize',14,'FontName','Times New Roman')
title({'&[n-k]'},'FontSize',14,'FontName','Times New Roman')

Graph:
&[n-k]
1200
&[n-k]

1000

800

600
y

400

200

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n

You might also like