Lab No.5 Me
Lab No.5 Me
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)
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:
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
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
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.