0% found this document useful (0 votes)
20 views10 pages

Lab No.5 Me

The document discusses generating and plotting various types of discrete time sequences in MATLAB, including unit sample sequences, unit step sequences, real and complex exponential sequences, and sinusoidal sequences. It provides the purpose and equipment needed. It then gives detailed procedures and MATLAB code examples to generate and plot each type of sequence over given intervals.

Uploaded by

Zainab Ashraf
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)
20 views10 pages

Lab No.5 Me

The document discusses generating and plotting various types of discrete time sequences in MATLAB, including unit sample sequences, unit step sequences, real and complex exponential sequences, and sinusoidal sequences. It provides the purpose and equipment needed. It then gives detailed procedures and MATLAB code examples to generate and plot each type of sequence over given intervals.

Uploaded by

Zainab Ashraf
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/ 10

LAB Experiment No .

5
Elementary sequences
PURPOSE
To learn
1. how to plot unit sample sequence and its shifted version
2. how to plot unit step sequence and its shifted version
3. how to plot real-valued exponential sequence
4. how to plot complex-valued exponential sequence
5. how to plot sinusoidal sequences
EQUIPMENT
Personal computer (PC) with windows operating system and MATLAB software
INTRODUCTION
A discrete time signal is represented as a sequence of numbers, called samples. These samples
are denoted by x(n) where the variable n is integer valued and represents in discrete instances in
time. An example of a discrete time signal is:
x(n) = {2 ,1 ,-1 ,0 ,1 ,4 ,3 ,7} …(1)

where the up arrow indicates the sample at n = 0


In MATLAB, a finite duration sequence is represented by a row vector. 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 ,
To represent the sequence defined in eq1, the following MATLAB command can be used:
>> n = [-3,-2,-1,0,1,2,3,4] x=[2,1,-1,0,1,4,3,7]
We use several elementary sequences in digital signal processing for analysis purposes. Their
definitions and MATLAB representations are given below.
PROCEDURE:
1. Unit sample sequence:
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. However, the logical relation n==0 is an elegant way
of implementing δ (n). For example, to implement over the interval, we will use the following
MATLAB function.
1. Define a function named impseq (given below) in script file.
2. Call the function with the proper input and output arguments in the main window.
3. Title and label the resulting plot properly.
M-File code
function [x,n] = impseq(n0,n1,n2)
% Generates x(n) = delta(𝑛 − 𝑛𝑜);
n1 <= n <= n2
% [x,n] = impseq(n0,n1,n2)
n= [n1:n2];
x = [(n - n0) == 0];
MATLAB Script code
% Generation of a Unit Sample Sequence
% Generate a vector from -10 to 20
[x,n]=impseq(1,-10,20)
%plot the unit sample sequence
stem(n,x);
xlabel(‘time index n’);ylabel(‘Amplitude’);
title(‘Unit Sample Sequence’);
axis([-10 20 0 1.2]);
Task 1
Generate and plot the sequence δ(n–30) -20 ≤ n ≤ 120
MATLAB CODE

2. Unit step sequence

In MATLAB the function ones(1,N) generates a row vector of N ones. It can be usedto generate
u( n) over a finite interval. Once again an elegant approach is to use the logical relation n>=0.
To implement over the
 Define a function named stepseq (given below) in script file.
 Call the function with the proper input and output arguments in the main window.
 Title and label the resulting plot properly.
MATLAB SCRIPT
function [x,n] = stepseq(n0,n1,n2)
% Generates x(n)= u(n-nO); n1 <= n <= n2
%
% [x,n] = stepseq(n0,n1,n2)
%
n = [n1:n2];
x = [(n-n0) >= 0];
Example
Generate and plot the sequence u(n-5) -20 ≤ n ≤ 10
Script File:-
>> % Generation of a Unit Step Sequence
% Generate a vector from -20 to 10
[x,n]=stepseq(5,-20,10);
>> %plot the unit sample sequence
stem(n,x);
>> xlabel('time index n');ylabel('Amplitude');
>> title('Unit Step Sequence');

axis([-20 10 0 1.2])
Task 2:
Generate and plot the sequence u(n+5) -20 ≤ n ≤ 20
MATLAB CODE:

3. Real-valued exponential sequence


x(n) a n , n; a
In MATLAB an array operator “.^” is, required to implement a real exponential sequence.
Example
Generate
𝑥(𝑛) = (0.9)𝑛, 0 ≤ 𝑛 ≤ 10
MATLAB script
>>n = [0:10]; x = (0.9).^ n;
>>stem(n,x);

Task 3
Generate and plot the sequence
𝑥(𝑛) = (−10)𝑛, −10 ≤ 𝑛 ≤ 10
MATLAB code
1. Complex-valued exponential sequence:
x(n) e( jwo )n
Where σ is called an attenuation and wo is the frequency in radians. A MATLAB function
exp is used to generate exponential sequences.
Example:-
Generate x(n) = exp [(2 + j3) n] , 0 n 10 ,
MATLAB script:-
>> n = [0:10];
>> x = exp((2+3j)*n);
>> subplot(2,1,1);
>> stem(n,real(x));
>> xlabel('Time index n');ylabel('Amplitude');
>> title('Real part');
>> subplot(2,1,2);
>> stem(n,imag(x));
>> xlabel('Time index n');ylabel('Amplitude');
>> title('Imaginary part');

1. Sinusoidal sequence:
𝑥(𝑛) = cos(𝜔𝑛 + 𝜃),
where θ is the phase in radians. A MATLAB function cos (or sin) is used to generate
sinusoidal sequences.
Example
Generate
𝜋
𝑥(𝑛) = cos (0.1𝜋𝑛 + ) + 2 sin(0.5𝜋𝑛) , 0 ≤ 𝑛 ≤ 10
3
MATLAB script

n = [0:10]; x = 3*cos(0.1*pi*n+pi/3) + 2*sin(0.5*pi*n);


>> n = [0:10];
>> x = 3*cos(0.1*pi*n+pi/3) + 2*sin(0.5*pi*n);
>> stem(n,x);
>> xlabel('Time index n');ylabel('Amplitude');
>> title('Sinusoidal sequence');
Example
Generate and plot each of the following sequences over the indicated interval.
a.
x(n) 2 (n 2) (n 4),
MATLAB script:
n = [-5 : 5];
x = 2*impseq(-2,-5,5) - impseq(4,-5,5);
subplot(2,1,1);stem(n,x); title('Sequence in example a')
xlabel ('n'); ylabel('x(n)');
>> n = [-5 : 5];
>> x = 2*impseq(-2,-5,5) - impseq(4,-5,5);
>> subplot(2,1,1);stem(n,x); title('Sequence in example
a')
>> xlabel ('n'); ylabel('x(n)');

MATLAB SCRIPT:
>> n = [0:20];
>> x1 = n.*(stepseq(0,0,20)-stepseq(10,0,20));
>> x2 = 10*exp(-0.3*(n-10)).*(stepseq(10,0,20)-stepseq(20,0,20));
>> x = x1+x2;
>> subplot(2,1,2); stem(n ,x); title('Sequence in example b'); xlabel(' n
'); ylabel('x (n)');
EXERCISE
Generate and plot each of the following sequences over the indicated interval
1. x[n] = cos πn/3 + sin πn/3 0 ≤ n ≤ 20
Matlab work

2. y[n] = nx[n] 0 ≤ n ≤ 20 x[n] is given in qs.1


Matlab work
3. . x[n] = sin πn/4 0 ≤ n ≤ 10
Matlab work

4.y[n] = x[n]/(πn/4)-10 ≤ n ≤ 10 x[n] is given in qs.3


5. x[n] = (sin πn/4)/(sin π/4) -20 ≤ n ≤ 20
Matlab work

6. y[n] = (exp(j3n) + exp(-j3n)) / 2 0 ≤ n ≤ 100


Matlab work
7. y[n] = (exp(j5n) - exp(-j5n)) / 2 -50 ≤ n ≤ 50
Matlab work

Analysis
In above all exercises, value of n is given and we applied x r y values then subplot the values
of x y and z. We applied step sequence which has unity magnitude and the stem which displays the
discrete values of the points on the curve, we label the X and Y with their axis and label the title which
is given in question.
Conclusion
In this experiment, we use many functions such as step sequence, exponential sequence,
complex sequence and impulse sequence and applied Matlab commands to perform various tasks and
exercises to determine real and imaginary parts.

You might also like