153 lab report 33

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

LAB REPORT-03

DIGITAL SIGNAL PROCESSING


(EEE 324)
SUBMITTED TO: Dr. Mubeen Sabir
SUBMITTED BY: Faiq Jhanzaib
REG NO: FA20-BEE-048
SECTION: BEE-6B
Lab # 3
Basic Operations on Discrete-Time Sequences
Objectives:
By the end of this lab students will be able to perform signal shifting and folding operations in
MATLAB, in addition students will be able to perform arithmetic operations like adding,
subtracting or multiplying signals of different lengths.

In Lab:
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.

Sol:
Code:
function [x] = exp_scalling(scalling,time)
x = scalling*exp(time);
plot(time,x)
grid on
xlabel('time')
ylabel('Amplitude')
title('Exponential Function')
end

t = -10:0.1:10;
e = exp_scalling(-10,t)
Plot:

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)

Sol:
Code:
function [x1] = sigshift(x,n,k)
x1 = n+k;
stem(x1,x,'linewidth',2)
grid on
xlabel('n-k')
ylabel('Amplitude')
title('Delayed in given sequence')
end
n = 0:4;
x = [6 11 14 5 0]
subplot(2,1,1)
stem(n,x,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('Given sequence')
grid on
subplot(2,1,2)
sigshift(x,n,5)

Plot:

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)

Sol:
Code:
function [] = sigfold(x,n)
n = fliplr(n);
x = fliplr(x)
stem(-n,x,'linewidth',2)
grid on
xlabel('-n')
ylabel('Amplitude')
title('Folding of a given sequence')
end

n = 0:4;
x = [6 11 14 5 0]
subplot(2,1,1)
stem(n,x,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('Given sequence')
grid on
subplot(2,1,2)
sigfold(x,n)

Plot:
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)

Sol:
Code:
function [] = sigadd(x1,n,x2)
stem(n,x1+x2,'linewidth',2)
grid on
xlabel('n')
ylabel('Amplitude')
title('x1+x2')
end

n = 0:4;
x1 = [6 11 14 5 0]
x2 = [16 22 24 10 1]
subplot(3,1,1)
stem(n,x1,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('x1 sequence')
grid on
subplot(3,1,2)
stem(n,x2,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('x2 sequence')
grid on
subplot(3,1,3)
sigadd(x1,n,x2)
Plot:

Task 5:
Let 𝑥𝑥(𝑛𝑛) = {1,2,3,4,5,6,7,6,5,4,3,2,1}
Determine and plot the following sequences
𝑎𝑎. 𝑥𝑥1 = 2𝑥𝑥(𝑛𝑛 − 5) − 3𝑥𝑥(𝑛𝑛 + 4)
𝑏𝑏. 𝑥𝑥2 = 𝑥𝑥(3 − 𝑛𝑛) + 𝑥𝑥(𝑛𝑛)𝑥𝑥(𝑛𝑛 − 2)

Sol:
Code:
a.
x = [1 2 3 4 5 6 7 6 5 4 3 2 1];
n = 0:length(x)-1;
subplot(2,1,1)
stem(n,x,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('x')
grid on
x2 = 2*x
x3 = 3*x
n1 = n+5
n2 = n-4
if n1(1)<n2(1)
var = zeros(1,n2(1)-n1(1))
x3 = [var x3]
n2(1)=n1(1)
elseif n2(1)<n1(1)
var = zeros(1,n1(1)-n2(1))
x2 = [var x2]
n1(1)=n2(1)
end
endpoint = length(n1)
if n1(endpoint)>n2(endpoint)
var = zeros(1,n1(endpoint)-n2(endpoint))
x3 = [x3 var]
n2(endpoint)=n1(endpoint)
elseif n2(endpoint)>n1(endpoint)
var = zeros(1,n2(endpoint)-n1(endpoint))
x2 = [x2 var]
n1(1)=n2(1)
end
N = n1(1):n2(endpoint)
x = x2-x3;
subplot(2,1,2)
stem(N,x,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('x=2x[n-5]-3x[n+4]')
grid on
b.
x = [1 2 3 4 5 6 7 6 5 4 3 2 1];
n = 0:length(x)-1;
subplot(2,1,1)
stem(n,x,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('x')
grid on
x2 = x
x3 = x.*x
n1 = n+3
n2 = n+2
if n1(1)<n2(1)
var = zeros(1,n2(1)-n1(1))
x3 = [var x3]
n2(1)=n1(1)
elseif n2(1)<n1(1)
var = zeros(1,n1(1)-n2(1))
x2 = [var x2]
n1(1)=n2(1)
end
endpoint = length(n1)
if n1(endpoint)>n2(endpoint)
var = zeros(1,n1(endpoint)-n2(endpoint))
x3 = [x3 var]
n2(endpoint)=n1(endpoint)
elseif n2(endpoint)>n1(endpoint)
var = zeros(1,n2(endpoint)-n1(endpoint))
x2 = [x2 var]
n1(1)=n2(1)
end
N = n1(1):n2(endpoint)
x = x2+x3;
subplot(2,1,2)
stem(N,x,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('x=x[3-n]+x[n]x[n-2]')
grid on
Plot:
a.

b.
Conclusion/Critical Analysis:
In this lab I learned about how to made functions in MATLAB and how to use these functions in
code. I also learn different operations of signal and systems e.g scaling, folding, shifting etc. In
this lab I also perform 5 lab tasks. In first task I simply made function of exponential function
and show its graph, in second lab task I made function for shifting operation and use in my
program to shift my signal right side, in third task I made function for folding and use in my
program to fold my signal, in fourth task I made function to add two signals and in last and fifth
task I made a program to implement given equation.
Now I am able to easily doing scaling, shifting, addition and folding of a signal.

You might also like