0% found this document useful (0 votes)
104 views6 pages

LAB # 01 Digital Sequences (Unit Step, Unit Impulse) : Background Review

This document discusses various discrete-time sequences including: - Unit sample and unit step sequences which are defined mathematically and can be generated in MATLAB. - Exponential sequences which decay or grow exponentially and are generated using exponential operators in MATLAB. - Sinusoidal sequences which are generated using trigonometric functions in MATLAB to produce a signal of a given frequency, amplitude, and phase. - Square and sawtooth waves which are generated using square and sawtooth functions in MATLAB with the ability to control frequency and amplitude. - The sinc function which is commonly used in signal processing and arises in Fourier transforms. It is generated in MATLAB by defining the sinc function and plotting it.

Uploaded by

Zohaib Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
104 views6 pages

LAB # 01 Digital Sequences (Unit Step, Unit Impulse) : Background Review

This document discusses various discrete-time sequences including: - Unit sample and unit step sequences which are defined mathematically and can be generated in MATLAB. - Exponential sequences which decay or grow exponentially and are generated using exponential operators in MATLAB. - Sinusoidal sequences which are generated using trigonometric functions in MATLAB to produce a signal of a given frequency, amplitude, and phase. - Square and sawtooth waves which are generated using square and sawtooth functions in MATLAB with the ability to control frequency and amplitude. - The sinc function which is commonly used in signal processing and arises in Fourier transforms. It is generated in MATLAB by defining the sinc function and plotting it.

Uploaded by

Zohaib Khan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 6

LAB # 01

Digital sequences (Unit Step, Unit Impulse)


Background Review
A discrete-time signal is represented as a sequence of numbers, called samples. A sample value
of a typical discrete-time signal or sequence {x[n]} is denoted as x[n] with the argument n being
an integer in the range and . For convenience, the sequence {x[n]} is often denoted without
the curly brackets.
The discrete-time signal may be a finite length or an infinite length sequence. A finite length
(also called finite duration or finite extent) sequence is defined only for a finite time interval.
N1 n N2,
(1.1)
where < N1 and N2 < with N2 N1. The length or duration N of the finite length sequence
is
N = N2 N1 + 1.
(1.2)
1. A sequence x[n] satisfying
x[n] = x[n + kN]

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

The unit step sequence , denoted by [n], is defined by

The exponential sequence is given by

where A and are real or complex numbers. By expressing

The real sinusoidal sequence with a constant amplitude is of the form


x[n] = Acos(on + )

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.

1. Unit Sample and Unit Step Sequences


Two basic discrete-time sequences are the unit sample sequence and the unit step sequence. A
unit sample sequence u[n] of length N can be generated using the MATLAB command
u = [1 zeros(1,N -1)];
A unit sample sequence ud[n] of length N and delayed by M samples, whereM < N, can be
generated using the MATLAB command
ud = [zeros(1,M) 1 zeros(1,N - M - 1)];
Likewise, a unit step sequence s[n] of length N can be generated using the MATLAB command
s = [ones(1,N)];
A delayed unit step sequence can be generated in a manner similar to that used in the generation
of a delayed unit sample sequence.

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:

% Generation of a Unit Step Sequence


clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit step sequence
s= [ones(1,31)];
% Plot the unit sample sequence
stem(n,s);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Step Sequence');
axis([-10 20 0 1.2]);

Using Function:

function [x,n] = stepseq(n0,n1,n2)


%Generates x(n) = u(n-n0); n1 <= n <= n2
n = [-10: 10]; x = [(n-0) >= 0];
stem(n,x)

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:

i. Run Program 4 to generate the sinusoidal sequence and display it.


ii. What is the frequency of this sequence and how can it be changed? Which parameter controls the
phase of this sequence? Which parameter controls the amplitude of this sequence?
iii. Modify the above program to generate a sinusoidal sequence of length 50, frequency 0.08,
amplitude 2.5, and phase shift 90 degrees and display it. What is the period of this sequence?
iv. Replace the stem command in Program 4 with the plot command and run the program again.
What is the difference between the new plot and the one generated in (i)?

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.

Run Program 5 to generate the square wave and display it.


Modify the program to change the duty cycle to 70.

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:

i. Run Program 6 to generate the sawtooth wave and display it.


6. Sinc Signal
The sinc function
, also called the "sampling function," is a function that arises frequently
in signal processing and the theory of Fourier transforms. The full name of the function is "sine
cardinal," but it is commonly referred to by its abbreviation, "sinc." There are two definitions in
common use. The one adopted in this work defines

(1)

where

is the sine function.

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.

You might also like