0% found this document useful (0 votes)
17 views11 pages

Abdul Wahab DSP LAB 3

Uploaded by

zimalabdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views11 pages

Abdul Wahab DSP LAB 3

Uploaded by

zimalabdi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

EEE324 Digital Signal Processing

Lab No.3:Basic Operations on Discrete-Time Sequences

Abdul Wahab
Name
FA20-BEE-010
Registration Number
BEE-6A
Class

Instructor’s Name Dr. Fawad Zaman

Lab Assessment

Post Lab Total


Pre-Lab In-Lab Data
Data Analysis Writing Style
Presentation

1|Page
Introduction:
In this lab we will 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. This lab will guide us about the basic working of different
function in MATLAB those are used for the different purposes.

In Lab Section:

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.

Code:

clc
close all
clear all
t = -10:0.1:10; %time scale
e = exp_scalling(-10,t); %exponential plotting
function [x] = exp_scalling(scalling,time) %function is defined
x = scalling*exp(time); %formula
plot(time,x,'linewidth',2) %plot of signal
grid on
xlabel('time')
ylabel('Amplitude')
title('Exponential Function')
end

2|Page
Result:

Figure 1:Exponential function plot of decaying.

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)

Code:
clc
close all
clear all
function [x1] = sigshift(x,n,k) % function delaration
x1 = n+k; % defined of variable
stem(x1,x,'linewidth',2) % discrete plot
grid on
xlabel('n-k')
ylabel('Amplitude')
title('Delayed in given sequence')

3|Page
end

k=1:5; % defining of constant


n=0:4; % discrete time range
x = [6 11 14 5 0]; % defining of an array
subplot(2,1,1)
stem(n,x,'linewidth',2) % discrete plot
grid on
xlabel('n')
ylabel('Amplitude')
title('Given sequence')
subplot(2,1,2)
sigshift(x,n,5)

Result:

Figure 2: It shows that after the delay added in the system then the signal response varies that
depend on the value how much delay is added.

4|Page
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)

Code:
clc
close all
clear all
function [] = sigfold(x,n) % function declaration
n = fliplr(n); % variable
x = fliplr(x); % variable name
stem(-n,x,'linewidth',2) % discrete plot
grid on
xlabel('-n')
ylabel('Amplitude')
title('Folding of a given sequence')
end

n = 0:4; % range of discrete time


x = [6 11 14 5 0] % array x is defined
subplot(2,1,1)
stem(n,x,'linewidth',2) % discrete plot
xlabel('n')
ylabel('Amplitude')
title('Given sequence')
grid on
subplot(2,1,2)
sigfold(x,n)

5|Page
Result:

Figure 3: it shows that the function behavior before and after adding some specific variation.

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)

Code:
clc
close all
clear all
function [] = sigadd(x1,n,x2) % function declaration
stem(n,x1+x2,'linewidth',2) % discrete plot with sum
grid on
xlabel('n')
ylabel('Amplitude')
title('x1+x2')
end
6|Page
n = 0:4; % range of x-axis
x1 = [6 11 14 5 0] % x1 array is defined
x2 = [16 22 24 10 1] % x2 array is defined
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) % recalling of function

Result:

Figure 4: it shows the single result of original x1 and x2 array. but it also shows their sum
result.

7|Page
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)

Code:
clc
close all
clear all
% % part a
x = [1 2 3 4 5 6 7 6 5 4 3 2 1]; % array is defined
n = 0:length(x)-1; % range for the discrete time
subplot(2,1,1)
stem(n,x,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('x')
grid on
x2 = 2*x; % multi-plying contant with array x
x3 = 3*x; % multi-plying contant with array x
n1 = n+5; % delay is added in tyhe system
n2 = n-4; % make the system advance
if n1(1)<n2(1) % check the condition
var = zeros(1,n2(1)-n1(1)); % lenght of arrays
x3 = [var x3]; % another array is created
n2(1)=n1(1); % equate delay and advance system
elseif n2(1)<n1(1) % another condition is added
var = zeros(1,n1(1)-n2(1));
x2 = [var x2];
n1(1)=n2(1);
end
endpoint = length(n1);
if n1(endpoint)>n2(endpoint) % condition is added to check the system behavior
var = zeros(1,n1(endpoint)-n2(endpoint)); % comparison of end values ofv arrays
x3 = [x3 var];
n2(endpoint)=n1(endpoint); % equate the both n1 and n2 system

8|Page
elseif n2(endpoint)>n1(endpoint)
var = zeros(1,n2(endpoint)-n1(endpoint));
x2 = [x2 var]; % another array is defined
n1(1)=n2(1);
end
N = n1(1):n2(endpoint); % range of discrete time is defined
x = x2-x3; % difference is calculated
subplot(2,1,2)
stem(N,x,'linewidth',2) % discrete plot
xlabel('n')
ylabel('Amplitude')
title('x=2x[n-5]-3x[n+4]')
grid on

Result:

Figure 5:it show the behavior of system under specific terms and conditions. Conditional is
also added in the system to verify the system behavior.

9|Page
Code:
clc
close all
clear all
%% part b
x = [1 2 3 4 5 6 7 6 5 4 3 2 1]; % array is defined
n = 0:length(x)-1; % range for the discrete time
subplot(2,1,1)
stem(n,x,'linewidth',2)
xlabel('n')
ylabel('Amplitude')
title('x')
grid on
x2 = x % equate two variables
x3 = x.*x % multiply variable x with x
n1 = n+3 % delay is added in the system
n2 = n+2 % delay is added in the system
if n1(1)<n2(1) % condition
var = zeros(1,n2(1)-n1(1)) % arrays length
x3 = [var x3] % another array is created
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')

10 | P a g e
title('x=x[3-n]+x[n]x[n-2]')
grid on

Result:

Figure 6: it show the collective behavior of different discrete signal when specific conditions
are implemented.

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.

11 | P a g e

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy