Lab Report 2 Zaryab Rauf Fa17-Ece-046

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

LAB REPORT #2

DIGITAL SIGNALS PROCESSING


INSTRUCTOR: SIR MUBEEN SABIR
DATED: 14/10/2020

SUBMITTED BY: ZARYAB RAUF


CIIT/FA17-ECE-046/ISB | BEE-5B
IN-LAB TASKS
Task-1:
Take an exponential signal and perform scaling operation with a negative
integer as given in In-Lab Work section and plot the result.
clc
clear all
close all
n = 0:5
x= exp(n)
subplot(2,1,1)
stem(n,x)
y = exp(n)*(-2)
subplot(2,1,2)
stem(n,y)

150

100

50

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

-100

-200

-300
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
Task-2:
Write a Matlab function “sigshift” for producing a delay of ‘k’ in a given
sequence ‘x[n]’ defined by arrays “x” and “n” by using the pseudo code
given in In-Lab Work section. Your function should yield y[n] = x[n-k].
Function [y, n] =sigshift (x, n, k)

function [y,n] = sshift( x,k )


n1 =3;
n2=10;
n=n1:n2;
subplot(2,1,1)
stem(n,x)
if k<0
n = n1-k:n2-k;
y=x;
else
k>0
n=n1-k:n2-k;
y=x;
end
subplot(2,1,2)
stem(n,y)
end

WITH K=3
WITH K=-3

Task-3:
Write a Matlab function “sigfold” for folding a given sequence ‘x[n]’
defined by arrays “x” and “n” by using the pseudo code given in In-Lab
Work section.
Function [y, n] =sigfold (x, n)
function [ y,n ] =SigFold(x,n)
n = -3:3;
n1 = -n;
subplot(2,1,1)
stem(n,x)
subplot(2,1,2)
stem(n1,x)

end

Command Window:
>> x = [1 2 3 4 5 6 7];
>> SigFold(x,n)
8

0
-3 -2 -1 0 1 2 3

0
-3 -2 -1 0 1 2 3

Task-4:
Write a Matlab function “sigadd” for adding two sequences x1[n] and
x2[n] by using the pseudo code given in In-Lab Work section.
Function [y, n] =sigadd (x1, n1, x2, n2)

function [ y,x ] = SigAdd( x1,n1,x2,n2 )


if(x1(1)<x2(1))
a = n2(1)<n1(1);
x2 = [zeros(1,a),x2];
n2(1)=n1(1)
elseif(n2(1)<x1(1))
b = n1(1)-n2(1);
x1 = [zeros(1,b),x1];
x1(1)=n2(1);
end
if(n1(end)>n2(end))
c = n1(end)-n2(end);
x2 = [zeros(1,c),x2];
n2(end)=n1(end);
elseif(n2(end)>n1(end))
d = n2(end)-n1(end);
x1 = [zeros(1,d),x1];
n1(end)=n2(end);
end
n= n1(1):n2(end);
x= x1 + x2;
stem(n,x)
end

Command window:
>> x1 = 0:5
>> x2 = 2:7
>> n1=0:5
>> n2=0:5
>> SigAdd(x1,n1,x2,n2)
12

10

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5

Task-5:
Let x(n)  {1, 2,3, 4,5,6,7,6,5, 4,3, 2,1}
 the following sequences
Determine and plot
a. x1 (n)  2 x (n  5)  3x (n  4)
b. x2 (n)  x(3  n)  x(n) x(n  2)

a)
clc
close all
clear all
x = [1 2 3 4 5 6 7 6 5 4 3 2 1];
l = length(x)
n = 1:1:l+5;
y = [0 0 0 0 0];
x1 = 2.*[y x];
x2 = 3.*[x y];
x3 = x1-x2;
stem(n-5,x3)

10

-5

-10

-15

-20
-4 -2 0 2 4 6 8 10 12 14

b)
clc
close all
clear all
x = [1 2 3 4 5 6 7 6 5 4 3 2 1];
l = length(x)
n = 1:1:l+3;
x1 = [0 0 0 x];
x2 = [0 0 x];
x3 = [x 0 0];
x4 = x2.*x3;
maxlength = max([length(x1),length(x4)])
x1(length(x1)+1:maxlength) = 0;
x4(length(x4)+1:maxlength) = 0;
x5 = x1+x4;
stem(n-3,x5)

45

40

35

30

25

20

15

10

0
-2 0 2 4 6 8 10 12 14

CRITICAL ANALYSIS:
In this lab the following was learned:

1. Various operations of exponential signals were performed.


2. Functions were used to
 Add sequence.
 Fold sequence.
 Shift a sequence.
 Scaling of exponential signals.
 Two signals of different lengths were added by using if-else statement.
3. Scaling a signal with negative integer will flip the axis.

You might also like