0% found this document useful (0 votes)
7 views7 pages

DSP Lab Report 3

The document outlines Lab#3 of the EEE-324 Digital Signal Processing course, detailing tasks involving basic operations on discrete-time sequences using MATLAB. It includes tasks such as scaling, shifting, folding, and adding sequences, with accompanying code snippets and discussions on the results. The lab emphasizes fundamental DSP operations and the development of functions to manipulate signals effectively.

Uploaded by

Roman Roman
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)
7 views7 pages

DSP Lab Report 3

The document outlines Lab#3 of the EEE-324 Digital Signal Processing course, detailing tasks involving basic operations on discrete-time sequences using MATLAB. It includes tasks such as scaling, shifting, folding, and adding sequences, with accompanying code snippets and discussions on the results. The lab emphasizes fundamental DSP operations and the development of functions to manipulate signals effectively.

Uploaded by

Roman Roman
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

EEE-324 Digital Signal Processing

Lab#3: Basic Operations on Discrete-Time Sequences

Name Roman Bin Ehsan


Reg no# FA22-BEE-258
Class BEE-6A
Instructor Dr. Bakhtiar Ali
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.

Code:

n = -10:10; ylabel('x(n)');
a = 0.9; grid on;
n1 = 2; x1 = n1 * x;
x = (a).^n; subplot(2,2,2);
subplot(2,2,1); stem(n, x1, 'filled');
stem(n, x, 'filled'); title('With Scaling');
title('Without Scaling'); xlabel('n'); ylabel('x_1(n)');
xlabel('n'); grid on;
Graph:

Discussion:

In this experiment, an exponential signal x(n)=a^n with a=0.9a = 0.9 is generated and
plotted. The first plot shows the original signal without scaling. In the second plot, the
signal is scaled using a negative integer factor (n1=2), which amplifies the values of x(n)
by multiplying them with 2. However, since the base a=0.9 is less than 1, the exponential
decay remains, but with a larger magnitude. This demonstrates the effect of amplitude
scaling, which changes the signal’s strength but not its shape.

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:

n = -10:10; x1=fliplr(x);
x=sin(n); subplot(222)
subplot(221) stem(n,x1,'fill')
stem(n,x,'fill') title('flipped')
title('orignal')
Graph:

Discussion:
The function sigshift(x, n, k) applies a delay of kk to the input signal x[n], effectively
shifting it to the right by modifying the time indices. In the given code, a sine signal is
generated and plotted. The first plot shows the original signal, while the second plot
displays the flipped version using fliplr(x), which reflects the signal about the vertical axis.
This demonstrates how time-reversal affects a sequence, and when combined with
shifting, it helps in various signal processing applications like convolution and filtering.

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:
function [y, n1] = sigshift_pad(x, n, k) else
n = -5:5; y = x;
x = heaviside(n); n1 = n;
k = -3; end
if k > 0 stem(n1, y); % Use y instead of x
n1 = n(1):(n(end) + k); xlabel('n');
y = [zeros(1, k), x]; ylabel('Amplitude');
elseif k < 0 title('Shifted signal ');
m = abs(k); grid on;
n1 = (n(1) - m):n(end); end
y = [x, zeros(1, m)];
Graph:
Discussion:
The function sigfold(x, n) is used to perform time-reversal (folding) of a discrete-time
signal x[n]x[n], which flips the sequence around n = 0. This means if the original sequence
is defined at indices n, the folded sequence will be defined at −n. The sigshi _pad func on
shifts a unit step signal (Heaviside function) and adds extra zeros when shifting forward or
backward to keep the signal aligned properly.

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:
function [y1, y2, n] = sigadd(x1, n1, x2, n2) elseif n2(end) > n1(end)
n1 = -5:5; n_new = n2(end) - n1(end);
n2 = -5:0; x1 = [x1, zeros(1, n_new)];
x1 = double(n1 >= 0); n1 = n1(1):n2(end);
x2 = double(n2 >= 0); end
% Align start indices n = n2;
if n1(1) < n2(1) % Output aligned signals
n_new = n2(1) - n1(1); y1 = x1;
x2 = [zeros(1, n_new), x2]; y2 = x2;
n2 = n1(1):(n1(1) + length(x2) - 1); % Plot results
elseif n2(1) < n1(1) subplot(3,1,1);
n_new = n1(1) - n2(1); stem(n, y1, 'filled');
x1 = [zeros(1, n_new), x1]; title('Signal x1[n]');
n1 = n2(1):(n2(1) + length(x1) - 1); subplot(3,1,2);
end stem(n, y2, 'filled');
% Align end indices title('Signal x2[n]');
if n1(end) > n2(end) subplot(3,1,3);
n_new = n1(end) - n2(end); stem(n, y1 + y2, 'filled');
x2 = [x2, zeros(1, n_new)]; title('Summed Signal x1[n] + x2[n]');
n2 = n2(1):n1(end); end

Graph:
Discussion:
The sigadd function adds two signals by making sure their time values match. If one signal
starts or ends earlier than the other, zeros are added to make them the same length. After
that, both signals are shown in separate plots, and their sum is shown in the final plot. This
helps in signal processing tasks like filtering and analyzing system responses.

Task#5: Let x(n)  {1, 2,3, 4,5, 6, 7, 6, 5, 4,3, 2,1}



Determine and plot the following sequences
a. x1 (n)  2 x(n  5)  3x(n  4)
b. x2 (n)  x(3  n)  x(n) x( n  2)

Code(a):
x = [1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1]; x_shift1(n3 >= (min(n) + k1) & n3 <= (max(n)
n = -2:10; + k1)) = x;
k1 = -5; x_shift2(n3 >= (min(n) + k2) & n3 <= (max(n)
k2 = 4; + k2)) = x;
n1 = min(n) + min(k1, k2); x1 = 2 * x_shift1 - 3 * x_shift2;
n2 = max(n) + max(k1, k2); figure;
n3 = n1:n2; stem(n3, x1, 'b', 'filled');
x1 = zeros(1, length(n3)); title('Computed Sequence: x_1(n) = 2x(n-5)
x1(n3 >= min(n) & n3 <= max(n)) = x; - 3x(n+4)');
x_shift1 = zeros(size(n3)); xlabel('n'); ylabel('Amplitude'); grid on;
x_shift2 = zeros(size(n3));

Graph:

Discussion:
In part (a), the sequence is moved in two directions: x(n-5) shifts it to the right, and x(n+4)
shifts it to the left. Then, x(n-5) is doubled, and x(n+4) is multiplied by -3 before adding
them together. This changes both the size and position of the sequence. The final graph
shows how these changes affect the original sequence.
Code(B):
% Define the sequence x(n) and index n for i = 1:length(n)
x = [1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1]; index = find(n == (n(i) - 2));
n = -2:10; if ~isempty(index)
% Compute x(3-n) (time-reversed around x_shifted(i) = x(index);
n=3) end
n_folded = 3 - n; end
x_folded = zeros(size(n)); % Compute x2(n) = x(3-n) + x(n) * x(n-2)
% Assign values for x(3-n) x2 = x_folded + (x .* x_shifted);
for i = 1:length(n) % Plot results
index = find(n == n_folded(i)); figure;
if ~isempty(index) stem(n, x2, 'r', 'filled');
x_folded(i) = x(index); title('Computed Sequence: x_2(n) = x(3-n) +
end x(n)x(n-2)');
end xlabel('n');
% Compute x(n-2) ylabel('Amplitude');
x_shifted = zeros(size(n)); grid on;
Graph:

Discussion:
In part (b), the sequence undergoes two main transformations. First, it is flipped around
n=3, creating x(3 - n). Then, the sequence is multiplied element-wise with a shifted
version, x(n-2), before adding the results. This operation combines time-reversal and
multiplication, altering both the shape and values of the sequence. The final graph shows
how these transformations modify the original signal.
Critical Analysis:
This lab focused on fundamental operations in Digital Signal Processing (DSP), including
shifting, reversal, scaling, addition, and multiplication of signals; hence, signal shifting can
be performed to the right (delay) or to the left (advance), while reversal involves creating
a mirror image of the original signal. Moreover, it was observed that the procedures for
addition and multiplication are similar, differing only in the respective operations applied.
Furthermore, various functions were developed to implement these basic signal
operations, including sigadd, sigmul, sigshift, and sigfold, and their functionality was
thoroughly analyzed during the lab.

You might also like