0% found this document useful (0 votes)
13 views30 pages

Lab Assignment (2) 2141003003 Mohak Chakrabory

The document outlines an assignment for a Digital Signal Processing course focusing on the generation and manipulation of discrete-time signals. It includes theoretical concepts, types of discrete-time signals, operations on these signals, MATLAB functions for generating various signal types, and lab assignments for practical implementation. The submission date is set for the 3rd week of February 2024.

Uploaded by

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

Lab Assignment (2) 2141003003 Mohak Chakrabory

The document outlines an assignment for a Digital Signal Processing course focusing on the generation and manipulation of discrete-time signals. It includes theoretical concepts, types of discrete-time signals, operations on these signals, MATLAB functions for generating various signal types, and lab assignments for practical implementation. The submission date is set for the 3rd week of February 2024.

Uploaded by

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

Digital Signal

Processing
(EET 3051)

Assignment Set – 02

Generation and manipulation of


discrete time signals.
Submission Date: 3rd Week of February 2024

Branch: ECE
Section:
Name Registration No. Signature

Department of Electronics & Communication


Engineering
Institute of Technical Education and Research (Faculty of
Engineering)
Siksha ‘O’ Anusandhan
(Deemed to be University)
Bhubaneswar

Page No.: .
2.1 AIM:

In this lab you will learn to generate and manipulate some basic DT signals

2.2 Theory
Signals are broadly classified into analog and discrete signals. An analog signal will be
denoted by xa(t), in which the variable t can represent any physical quantity but we will
assume that it represents time in seconds. A discrete signal will be denoted by x(n), in
which the variable n is integer-valued and represents discrete instances in time.
Therefore, it is also called a discrete-time signal, which is a number sequence and will
be denoted by one of the following notations:

x [ n ] ={… , x (−1), x (0) , x ( 1 ) , … } (2.1)



where the up-arrow indicates the sample at n = 0.

2.2.1 Types of Sequences

1. Unit Sample Sequence:

{
δ [ n ] = 1 n=0
¿ 0 ,n ≠ 0
(2.2)

2. Unit Step sequence:

u [ n ] = 1 n≥ 0
¿ 0 , n<0 { (2.3)

3. Real Valued Exponential Sequence

x [ n ] =a , ∀ n ; a ∈ R
n
(2.4)
4. Complex Valued Exponential Sequence

x [ n ] =e
(σ + j ω0 )n
,∀n (2.5)
where σ produces an attenuation (if <0) or amplification (if >0) and ω 0 is the
frequency in radians/sample.

5. Sinusoidal sequence:
x [ n ] =A cos(ω0 n+θ 0) , ∀ n (2.6)
where A is an amplitude, ω 0 is the angular velocity and θ0 is the phase in radians.

6. Random Sequences:
Many practical sequences cannot be described by mathematical expressions like
those above. These sequences are called random (or stochastic) sequences and
are characterized by parameters of the associated probability density functions.
The most common random sequences are the uniform and the gaussian random
sequences.

Page No.: .
2.2.2 Operations on Sequences

The following are some of the basic operations done on the signal sample-by-sample
basis.
1. Signal Addition

y ( n )=x 1 ( n ) + x 2 ( n ) (2.7)
2. Signal Subtraction

y ( n )=x 1 ( n )−x 2 ( n ) (2.8)


3. Signal Multiplication

y ( n )=x 1 ( n ) × x 2 ( n ) (2.9)
4. Signal Division

x1 ( n ) (2.10)
y ( n )=
x2 ( n )
5. Signal Amplitude Scaling

y ( n )=αx(n) (2.11)
6. Signal Amplitude Shifting

y ( n )=x ( n ) + A (2.11)
7. Signal Time Shifting

y ( n )=x ( n−k ) , k ∈ I (2.12)


8. Signal Folding /Time Reversal

y ( n )=x (−n ) (2.13)


9. Signal Energy

The energy of a periodic sequence ~


x (n) with a time period N is given by

1
N −1
(2.14)
∑ |~x ( n )|
2
P x=
N n=0
10. Signal Power

The energy of a sequence x (n) is given by



(2.12)
E x = ∑ x2 ( n)
n=−∞

Page No.: .
2.3 Prelab Questions
Answer the following questions in your own handwriting. Use extra pages if necessary.
Q1. Determine the energy of a DT power signal.
Q2. Determine the power of an DT energy signal.
Q3. Provide examples of five DT signals that are neither energy nor power signals
(along with their plots (hand drawn)).
Q4. Provide one example of a DT signal which extends to infinity but converges.
(along with the plot (hand drawn)).
Q5. Provide one example of a DT signal which extends to infinity but does not
converge. (along with the plot (hand drawn)).

Answers to the Prelab Questions

Page No.: .
2.4 Lab Assignment

2.4.1 Generation of Basic DT Signals

a. Write a MATLAB function to generate δ ( n ) in the given range [n1 ,n 2] . The function
must have the following template.
function [x,n] = impSeq(n0,n1,n2)
% Generates x(n) = delta(n-n0); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = impseq(n0,n1,n2)
%
% Write the code for generating the function

Code

Function:
function [x,n] = impSeq(n0,n1,n2)
% Generates x(n) = delta(n-n0); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = impseq(n0,n1,n2)
%
% Write the code for generating the function
if n1>=n2 || n0<=n1 || n0>= n2
error('Wrong Choice for n0, n1 and n2')
end

n = n1:n2;
x = n==n0;

b. Write a MATLAB function to generate u ( n ) in the given range [n1 ,n 2] . The function
must have the following template.
function [x,n] = stepSeq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = stepseq(n0,n1,n2)
%
% Write the code for generating the function

Code

Function: function [x,n] = stepSeq(n0,n1,n2)


if n1 >= n2 || n0 < n1 || n0 > n2
error('Wrong Choice for n0, n1, and n2')
end

n = n1:n2;
x = (n - n0) >= 0;

Page No.: .
c. Write a MATLAB function to generate r ( n ) in the given range [n1 ,n 2] . The function
must have the following template.
function [x,n] = rampSeq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = rampseq(n0,n1,n2)
%
% Write the code for generating the function

Code

Function: function [x,n] = rampSeq(n0,n1,n2)


if n1 >= n2 || n0 < n1 || n0 > n2
error('Wrong Choice for n0, n1, and n2')
end

n = n1:n2;
x = (n - n0);
x(x<0)=0;

d. Write a MATLAB function to generate real valued exponential signal in the given
range [n1 ,n 2] . The function must have the following template.
function [x,n] = realValuedExpSeq(a,n1,n2)
% Generates x(n) = a^(n); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = realValuedExpSeq(a,n1,n2)
%
% Write the code for generating the function

Code

Function:
function [x,n] = realValuedExpSeq(a,n1,n2)
n = n1:n2;
x=a.^n;

e. Write a MATLAB function to generate complex valued exponential signal in the given
range [n1 ,n 2] . The function must have the following template.
function [x,n] = complexValuedExpSeq(a,n1,n2)
% Generates x(n) = a^(n); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = complexValuedExpSeq(a,n1,n2)
%
% Write the code for generating the function

Code

Function:
function [x,n] = complexValuedExpSeq(a,alp,n1,n2)

Page No.: .
n=n1:n2;
x=a*alp.^n

f. Write a MATLAB function to generate a Sine signal in the given range [n1 ,n 2] . The
function must have the following template.
function [x,n] = sineSeq(A, omega_0, theta, n1,n2)
% Generates x(n) = A sin(omega_0xn+theta); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = sineSeq(A, omega_0, theta, n1,n2)
%
% Write the code for generating the function

Code

Function:
function [x,n] = sineSeq(A, omega_0, theta, n1,n2)
n=n1:n2;
x=A*sin(omega_0.*n+theta);

g. Write a MATLAB function to generate a Cosine signal in the given range [n1 ,n 2] . The
function must have the following template.
function [x,n] = cosineSeq(A, omega_0, theta, n1,n2)
% Generates x(n) = A cos(omega_0xn+theta); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = cosineSeq(A, omega_0, theta, n1,n2)
%
% Write the code for generating the function

Code

Function:
function [x,n] = cosineSeq(A, omega_0, theta, n1,n2)
n=n1:n2;
x=A*cos(omega_0.*n+theta);

h. Write a MATLAB function to generate a uniform random signal in the given range
[n1 ,n 2] with mean value μ and variance σ . The function must have the following
template.
function [x,n] = uniformRandomSeq(mu,sigma,n1,n2)
% Generates x(n) = A sin(omega_0xn+theta); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = sineSeq(A, omega_0, theta, n1,n2)
%
% Write the code for generating the function

Code

Page No.: .
Function:
function [x, n] =
uniformRandomSignal(mu,sigma,lim_min,lim_max,n1,n2)
n = (n1:n2);
x = mu + sigma * (randi([lim_min, lim_max], 1,length(n)));
end

i. Generate and plot corresponding signals given generated by the MATLAB functions
in (a)-(g) in the range n=[ −5 ,5 ] . Choose your own values of the other parameters if
needed.

Code

//Plot function
function x=setplot(x,n,xlab,ylab,Title)
stem(n, x, 'r', 'linewidth', 3);
hold on; grid on;
plot([n(1), n(end)], [0, 0], 'b', 'linewidth', 2);
plot([0 0], [min(x)-0.2 max(x)*1.2], 'b', 'linewidth', 2); % y-axis
axis([ min(n) max(n) min(x)-0.2 max(x)+0.2]);
xlabel(xlab);
ylabel(ylab);
title(Title);
end

(a)Impulse Sequence

Calling Function
clc;
clear all;
close all;
[x,n]=impSeq(2,-5,5);
y=setplot(x,n,'n','\delta(n-n_0)','Impulse Function');

Output (Command Window and/or Plots)

Page No.: .
(b)Step Sequence

Calling Function

[x,n]=stepSeq(2,-5,5);

y=setplot(x,n,'n','u(n-n_0)','Unit Step Function');

Output (Command Window and/or Plots)

Page No.: .
(c) Ramp Sequence

Calling Function

[x,n]=stepSeq(2,-5,5);

y=setplot(x,n,'n','r(n-n_0)','Ramp Function');

Output (Command Window and/or Plots)

Page No.: .
(d)Real Exponential Sequence

Calling Function
Subplot(211)

[x,n]=realValuedExpSeq(2,-5,5);

y=setplot(x,n,'n','x(n)=a^n','Real Valued Exponential Function');

subplot(212)

[x,n]=realValuedExpSeq(.5,-5,5);

y=setplot(x,n,'n','x(n)=a^n','Real Valued Exponential Function');

Output (Command Window and/or Plots)

Page No.: .
(e)Complex Exponential Sequence

Calling Function

subplot(211)

[x,n]=complexValuedExpSeq(1.5,.5,-5,5);

y=setplot(x,n,'n','x(n)=aα^n','Complex Valued Exponential Function( )');

subplot(212)

[x,n]=complexValuedExpSeq(1.5,2,-5,5);

y=setplot(x,n,'n','x(n)=aα^n','Complex Valued Exponential Function');

Output (Command Window and/or Plots)

Page No.: .
(f) Sine Sequence

Calling Function

[x,n]=sineSeq(2,4,pi/4,-5,5);

y=setplot(x,n,'n','Amplitude','Sine Function');

Output (Command Window and/or Plots)

Page No.: .
(g)Cosine Sequence

Calling Function

[x,n]=cosineSeq(2,4,pi/6,-5,5);

y=setplot(x,n,'n','Amplitude','Cosine Function');

Output (Command Window and/or Plots)

Page No.: .
(h)Random Sequence

Calling Function

[x,n]=randomSeq(2,-1,0,5,-5,5);

y=setplot(x,n,'n','x(t)','Random Function ');

Output (Command Window and/or Plots)

Page No.: .
2.4.2 Generation of Composite Signals

Generate and plot each of the following sequences over the indicated interval.

a. x (n)=2 δ (n+2)−δ(n−4 ),−5 ≤n ≤ 5.

Code

[x1 n1] = impSeq(-2, -5,5)


[x2 n2] = impSeq(4, -5,5)
x3 = 2*x1-x2
n3 = n1

figure;
subplot(311)
setplot(x1,n1,'n','\delta(n+2)','Unit Impulse Function');

subplot(312)
setplot(x2,n2,'n','\delta(n-4)','Unit Impulse Function');

Page No.: .
subplot(313)
setplot(x2,n2,'n','x(t)=2\delta(n+2)+\delta(n-4)','Unit
Impulse Function');

Output (Command Window and/or Plots)

Unit Impulse Function

1
(n+2)

0.5

-5 -4 -3 -2 -1 0 1 2 3 4 5
n
Unit Impulse Function

1
(n-4)

0.5

-5 -4 -3 -2 -1 0 1 2 3 4 5
n
Unit Impulse Function
2
x(n) =2 (n+2) + (n-4)

-1
-5 -4 -3 -2 -1 0 1 2 3 4 5
n

b. x (n)=cos (0.04 πn)+0.2 w (n), 0 ≤ n ≤50 , where w (n) is a Gaussian random sequence with
zero mean and unit variance.

Code

[x1 n1] = cosineSeq(1,0.04*pi ,0,0,50)


[x2 n2] = randomSeq(0,1,0,50)
x3 = 2*x1-x2
n3 = n1

figure;
subplot(311)
setplot(x1,n1,'n','x(n)','CosineFunction (Cos(0.04?n)');

subplot(312)
setplot(x2,n2,'n','w(n)','Random Function');

subplot(313)
setplot(x2,n2,'n','x(n)+0.2w(n)','Y(n)');

Output (Command Window and/or Plots)

Page No.: .
CosineFunction (Cos(0.04?n)
1
x(n)

0
-1
0 5 10 15 20 25 30 35 40 45 50
n
Random Function
1
w(n)

0.5
0
0 5 10 15 20 25 30 35 40 45 50
n
Y(n)
x(n)+0.2w(n)

1
0.5
0
0 5 10 15 20 25 30 35 40 45 50
n

c. ~
x (n)={... ,5 , 4 ,3 ,2 , 1 ,5 , 4 ,3 , 2 , 1, 5 , 4 ,3 , 2 ,1 , ...};−10≤ n ≤ 9.

Code

clc;
clear all;
close all;
[x,n]=randomSeq(0,1,0,5,-10,9);
y=setplot(x,n,'n','x(t)','Random Function ');

Output (Command Window and/or Plots)

Page No.: .
Random Function
5

4.5

3.5

3
x(t)

2.5

1.5

0.5

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

Page No.: .
2.4.3 Signal Manipulation

a. Write individual MATLAB functions to perform signal addition, subtraction,


multiplication, division, signal amplitude shifting, amplitude scaling, time shifting,
time folding, and to evaluate the energy and power of signal.

Code

clc;
clear all;
close all;
[x_a,n_1]=stepSeq(-2,-10,10);
[x_b,n_2]=stepSeq(2,-10,10);
x1=x_a+x_b;
n1=n_1;
[x2,n2]=realValuedExpSeq(1.5,-10,10);
subplot(211)
setplot(x1,n1,'n','x_1(n)','Unit Impulse');
subplot(212)
setplot(x2,n2,'n','x_2(n)','Real Exponential Function');

%Adding of Function
figure
n3=n1;
subplot(211)
x3=2*x1+0.4*x2;
setplot(x3,n3,'n','x_2(n)','Addition of Function');

%Subtracting of Function
subplot(212)
x4=x1-x2;
setplot(x4,n3,'n','x_2(n)','Subtraction of Function');

%Multiplication of Function
figure
subplot(211)
x5=x1.*x2;
setplot(x5,n3,'n','x_2(n)','Multiplication of Function');

%Division of Function
subplot(212)
x6=x2./x1;
setplot(x6,n3,'n','x_2(n)','Division of Function');

%Signal Amplitude Shifting


figure
subplot(211)
x7=4*x1;

Page No.: .
setplot(x7,n3,'n','4x_1(n)','Amplification');
subplot(212)
x8=.5*x1;
setplot(x8,n3,'n','.4x_1(n)','Attenuation');

%Time Shifting
figure
subplot(211)
x9=x1;
setplot(x9,n3-2,'n','x_1(n+2)','Time Shifting');
subplot(212)
x10=x1;
setplot(x10,n3+2,'n','.4x_1(n-2)','Time Shifting');

%Time folding
figure
subplot(211)
x9=x1;
setplot(x1,n3,'n','x_1','Original Signal');
subplot(212)
setplot(x1,-n3,'n','x_1(-n)','Time folding');

%Energy Signal
Energy=sum(x1.^2);
fprintf('Energy of Signal is: %f\n', Energy);

Power=Energy/(2*length(n1));
fprintf('Energy of Signal is: %f\n', Power);

Output (Command Window and/or Plots)

Page No.: .
Unit Impulse
2

1.5
x1 (n)

0.5

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
Real Exponential Function

40
x2 (n)

20

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

Addition of Function

20
x2 (n)

10

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
Subtraction of Function
0

-20
x2 (n)

-40

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

Page No.: .
Multiplication of Function

100
x2 (n)

50

0
-10 -8 -6 -4 -2 0 2 4 6 8 10
n
Division of Function

25
20
x2 (n)

15
10
5

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

Amplification
8

6
4x 1 (n)

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

1
.4x 1 (n)

0.5

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

Page No.: .
Time Shifting
2

1.5
x1 (n+2)

0.5

0
-12 -10 -8 -6 -4 -2 0 2 4 6 8
n
Time Shifting
2

1.5
.4x 1 (n-2)

0.5

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

Original Signal
2

1.5

1
x1

0.5

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

1.5
x1 (-n)

0.5

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

Energy of Signal is: 40.000000

Page No.: .
Energy of Signal is: 0.952381
b. Let x(n) = {1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1}.

Determine and plot the following sequences using the MATLAB functions written in
2.4.3 (a).

i. x 1 (n)=2 x (n−5)−3 x (n+ 4)


ii. x 2 (n)=x (3−n)+ x (n) x (n−2)

Code

Output (Command Window and/or Plots)

Page No.: .
c. Generate the complex-valued signal
( −0.1+ j 0.3) n
x ( n )=e ,−10 ≤ n ≤10
and plot its magnitude, phase, real, and imaginary parts in four separate subplots.

Code

Output (Command Window and/or Plots)

Page No.: .
d. Let x (n)=u (n)−u(n−10). Decompose x (n) into even and odd components. Plot all
signals suitably.

Code

Output (Command Window and/or Plots)

Page No.: .
2.5 Conclusion
Make a list of all the new Octave in-built functions that you learned in this
assignment set.
Sl. Function Short Description
No. Name
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[10]

Describe (in your own words and handwriting) what you have
learned in this assignment set.

Signature of the (Signature of the


Faculty Student)
Date:_____/______/_____

Page No.: .
Page No.: .

You might also like