LAB # 01 Digital Sequences (Unit Step, Unit Impulse) : Background Review
LAB # 01 Digital Sequences (Unit Step, Unit Impulse) : Background Review
for all n,
(1.3)
is called a periodic sequence with a period N where N is a positive integer and k is any integer.
Sequences:
The unit sample sequence, often called the discrete-time impulse or the unit impulse, denoted
by [n], is defined by
Generation of Sequences
The purpose of this section is to familiarize you with the basic commands in MATLAB for signal
generation and for plotting the generated signal. MATLAB has been designed to operate on data
stored as vectors or matrices. For our purposes, sequences will be stored as vectors. Therefore,
all signals are limited to being causal and of finite length.
Program 1:
% Generation of a Unit Sample Sequence
clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 20 0 1.2]);
Using Function:
function [x,n] = imseq(n0,n1,n2)
%Generates x(n) = delta(n-n0); n1 <=n <n2
n = [-10:10]; x = [(n-0) == 0];
stem(n,x)
Task 1:
i.
ii.
iii.
Run Program 1 to generate the unit sample sequence u[n] and display it.
What are the purposes of the commands clf, axis, title, xlabel, and ylabel?
Modify Program 1 to generate a delayed unit sample sequence ud[n] with a delay of 5
samples. Run the modified program and display the sequence generated.
Program 2:
Using Function:
Task 2:
i.
Run Program 2 to generate the unit step sequence s[n] and display it.
ii. Modify Program 2 to generate a delayed unit step sequence sd[n] with an advance of 7 samples
from 0. Run the modified program and display the sequence generated.
2. Exponential Signals
Another basic discrete-time sequence is the exponential sequence. Such a sequence can be
generated using the MATLAB operators .^ and exp.
Exponential Decaying:
Program 3.1:
clf;
N=input('number 0f samples=')
n = 0:.5:N;
%n=-N:0.5:0;
K =.8;
x = K.^n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
title('exponential decaying')
Exponential Growing:
Program 3.2:
clf;
N=input('number 0f samples=')
n = 0:.5:N;
%n=-N:0.5:0;
K =.8;
x = K.^-n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
title('exponential Growing')
Task 3:
I.
II.
Run Program 3.1 &3.2 to generate the exponential sequence and display
it.
Modify program 3.1 to generate flip exponential growing and inverted flip exponential
decaying signals
3. Sinusoidal Signals:
Another very useful class of discrete-time signals is the real sinusoidal sequence. Such
sinusoidal sequences can be generated in MATLAB using the trigonometric operators cos
and sin.
Program 4:
% Generation of a sinusoidal sequence
n = 0:.1:5;
f = 1;
phase =0;
A = 1;
arg = 2*pi*f*n - phase;
x = A*cos(arg);
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
%axis([0 40 -2 2]);
grid;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
Task 4:
4. Square Wave
Program 5:
close all;
clear all;
%f=2*pi;
a=input('Enter the amplitude of the square wave A = ');
f= input('Enter the frequency of the square wave F = ');
f=f*2*pi;
t=0:.001:1;
y=a*square(f*t);
plot(t,y);
axis([0 1 -2.2 2.2]);
Task 5:
i.
ii.
5. Sawtooth Wave:
Program 6:
close all;
clear all;
a=input('Enter the amplitude of the sawtooth wave A = ');
f= input('Enter the frequency of the sawtooth wave F = ');
f=f*2*pi;
t=0:.001:1;
y=a*sawtooth(f*t);
plot(t,y);
axis([0 1 -2.2 2.2]);
Task 6:
(1)
where
Program 7:
t = linspace(-5,5);
y = sinc(t);
plot(t,y);
xlabel('Time (sec)');
ylabel('Amplitude');
title('Sinc Function')
Task 7:
i.
ii.
Run Program 7 to generate the sinc signal wave and display it.
Shift the wave so that the 1 of the sinc function appears at 5.