LAB MANUAL of DSP-1

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

LAB MANUAL

COURSE: DSP-3105

Information and Communication Technology


Faculty of Science & Technology
Bangladesh University of Professionals (BUP)

Laboratory Manual
Prepared by: Supervised by:
Saiful Islam Dr. Md. Junaebur Rashid
Lecturer of ICT, BUP Associate Professor of EEE, DU
Experiment Name: Time domain analysis of discrete time signals

Objectives:
1. To understand the time domain properties of discrete time signals: unit impulse, unit step,
unit ramp, and exponential signals.
2. To learn how to generate and plot the discrete time signals in MATLAB.

Pre-Lab works
1. Read carefully the experiment manual before attending the lab.
2. See the theory lecture notes (bring them with you if necessary).
3. Practice the examples given in this experiment at home for better class performance.
4. Do not bring any relevant MATLAB codes, neither in any portable device nor in written
form.
5. Familiarize yourself with the MATLAB commands that may be required for this lab (see
the list).

Discrete Time Signals

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(n)} = {. . . , x(−1), x(0), x(1), . . .}

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

In MATLAB we can represent a finite-duration sequence by a row vector of appropriate values.


However, such a vector does not have any information about sample position n. Therefore a
correct representation of x(n) would require two vectors, one each for x and n. For example, a
sequence x(n) = {2, 1,−1,0, 1, 4, 3, 7} can be represented in MATLAB by
>> n=[-3,-2,-1,0,1,2,3,4]; x=[2,1,-1,0,1,4,3,7];
Generally, we will use the x-vector representation alone when the sample position information is
not required or when such information is trivial (e.g. when the sequence begins at n = 0). An
arbitrary infinite-duration sequence cannot be represented in MATLAB due to the finite memory
limitations.

TYPES OF SEQUENCES
We use several elementary sequences in digital signal processing for analysis purposes. Their
definitions and MATLAB representations follow.

1. Unit sample sequence (unit impulse, unit impulse signal)


1 𝑓𝑜𝑟 𝑛=0
𝑢(𝑛) = {
0 𝑓𝑜𝑟 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒
{… ,0,0,1,0,0, … }

MATLAB Coding

In MATLAB the function zeros(1,N) generates a row vector of N zeros, which can be used to
implement δ(n) over a finite interval.

% Program for the generation of Unit Impulse sequence


clc;
clear all;
close all;
n=-5:1:5;
x=[zeros(1,5),ones(1,1),zeros(1,5)];
stem(n,x);
xlabel('time');
ylabel('Amplitude');
title('Unit Impulse signal');
2. Unit Step sequence

1 for n  0
u ( n) =  {… ,0,0,1,1,1, … }
0 for n  0

MATLAB Coding

In MATLAB the function ones(1,N) generates a row vector of N ones. It can be used to generate
u(n) over a finite interval.

% Program for the generation of Unit Step sequence


clc;
clear all;
close all;
n=-10:1:15;
x=[zeros(1,10),ones(1,16)];
stem(n,x);
xlabel('time');
ylabel('Amplitude');
title('Unit step signal');
3. Ramp sequence

𝑢(𝑛) = 𝑛 𝑓𝑜𝑟 𝑛 ≥ 0
0 𝑓𝑜𝑟 𝑛 < 0

MATLAB Coding
% Program for the generation of Unit Ramp sequence
clc;
clear all;
close all;
n=-1:10;
x=[zeros(1,1),0:10];
stem(n,x)
xlabel('time')
ylabel('Amplitude')
title('Unit Ramp signal')
Alternative coding
% program for generation of ramp signal
clc;
clear all;
close all;
n1 = input('Enter the value for end of the sequence: '); %n1 = <any
value>10
x = 0:n1;
stem(x);
xlabel('time')
ylabel('Amplitude')
title('Unit Ramp signal')

'Enter the value for end of the sequence: 10


4. Exponential sequence

Real-valued exponential sequence:


n
x(n) = a , ∀n; a ∈ R

In MATLAB an array operator “.^” is required to implement a real exponential sequence. For
example, to generate x(n) = (0.9)n, 0 ≤ n ≤ 10, we will need the following MATLAB script:
>> n = [0:10];
>> x = (0.9).^n;

MATLAB Coding

% program for generation of exponential signal


clc;
clear all;
close all;
n=0:20;
x=(0.9).^n
stem(n,x);
xlabel('time');
ylabel('Amplitude');
title('Real valued Exponential signal');
Useful MATLAB Commands:
clc zeros xlabel
close all ones ylabel
clear all stem title

LAB WORK
1. Unit Impulse signal
a. Create Unit impulse signals,  (n ) for n = -5:5

[Hint: Use the logical relation n==0 for implementing δ(n). For example, to implement
𝛿(𝑛) = 1 𝑓𝑜𝑟 𝑛 = 𝑛𝑜
0 𝑓𝑜𝑟 𝑛 ≠ 𝑛𝑜
over the n1 ≤n0 ≤n2 interval.]

b. Plot Unit Impulse signal Vs. n Using the MATLAB function stem ( ).

c. Level the X and Y coordinate and use a title of the generated signal.

2. Unit Step signal


a. Create Unit Step signals: u(n), u(n-8), u(n+12) for n = -25:25
[Hint: Use MATLAB functions- zeors and ones.]
b. In each case plot impulse signal Vs. n Using the MATLAB function stem ( ).
c. Level the X and Y coordinate and use a title of the generated signals.
3. Unit Ramp signal

Generate a ramp sequence shown in following figure using your own aptitude.
a. Write MATLAB script or m-file.
b. Plot Unit Ramp signal Vs. n Using the MATLAB function stem ( ).
c. Level the X and Y coordinate and use a title of the generated signals.
[You can code this program in different ways.]
4. Exponential sequence
Generate a real valued-exponential sequence shown in following figure using, a=0.85
a. Write MATLAB script or m-file.
b. Plot Real valued Exponential signal Vs. n Using the MATLAB function stem ( ).
c. Level the X and Y coordinate and use a title of the generated signals.
REPORT:
1. Submit a report on your lab work along with the corresponding MATLAB script file and
figure window for each work.
2. Clearly label x-axis, y-axis, and title in each figure.
3. Answer all the questions in Lab Work.

Warning
1. Don’t copy from your mates.

Reference
1. Digital Signal Processing Using MATLAB®, Third Edition Vinay K. Ingle, John G.
Proakis.

You might also like