0% found this document useful (0 votes)
97 views2 pages

Objective: % Time (Sampling Freq - 10 HZ) % Amplitude % Frequency % The Command y (Y 0) 0 Removes - Ve Values

This document provides examples of generating common signals in MATLAB for an advanced digital signal processing lab. It includes: 1) Examples of generating triangular, square, step, and exponential signals using built-in MATLAB functions. 2) Discussing discrete time signals and generating them using the stem function. 3) Explaining how to generate even and odd parts of signals using their definitions. 4) Providing exercises for students to generate additional signals and analyze their properties.

Uploaded by

Aman
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)
97 views2 pages

Objective: % Time (Sampling Freq - 10 HZ) % Amplitude % Frequency % The Command y (Y 0) 0 Removes - Ve Values

This document provides examples of generating common signals in MATLAB for an advanced digital signal processing lab. It includes: 1) Examples of generating triangular, square, step, and exponential signals using built-in MATLAB functions. 2) Discussing discrete time signals and generating them using the stem function. 3) Explaining how to generate even and odd parts of signals using their definitions. 4) Providing exercises for students to generate additional signals and analyze their properties.

Uploaded by

Aman
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/ 2

MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO

INSTITUTE OF INFORMATION & COMMUNICATION TECHNOLOGIES


ADVANCED DIGITAL SIGNAL PROCESSING
Lab 2: Generation of commonly used signals using MATLAB

Objective values defined by n. The vectors n and x must, of course,


have compatible dimensions. Following example will
The objective of this lab is to generate and plot com- help you draw such a waveform.
monly used continuous as well as discrete time signals.

3.1 Example
1 Triangular Wave
Generate discrete time square wave of amplitude 3 and
MATLAB has a built-in function sawtooth to generate frequency of 2 Hz
a periodic triangular waveform. Following example will clc , clear all , close all
help you draw such a waveform. t = 0:0.1:1; % time ( sampling freq . 10 Hz )
A = 3; % amplitude
f = 2; % frequency
1.1 Example y = A * square (2* pi * f * t ) ; % the command y (y <0) =0;
removes - ve values
Generate triangular wave having amplitude of 2 and fre- stem (t , y )
quency of 2 Hz with a width of 0.5 units axis ([0 1 -4 4])
xlabel ( ’ Time in seconds ’)
clc , clear all , close all ylabel ( ’ Amplitude ’)
t = 0:.0001:1; % time title ( ’ Discrete Signal ’ )
A = 2; % amplitude grid
f = 2; % frequency
W = 0.5; % width A discrete time unit step function u(n) may be created
y = A * sawtooth (2* pi * f *t , W );
plot (t , y ) using following example.
axis ([0 1 -3 3])
clc , clear all , close all
xlabel ( ’ Time in seconds ’)
t = 0:0.1:5;
ylabel ( ’ Amplitude ’)
x = ones (1 , length ( t ) ) ;
title ( ’ Triangula r Wave ’)
stem (t , x )
grid
axis ([0 1 -4 4])
xlabel ( ’ Time in seconds ’)
ylabel ( ’ Amplitude ’)
title ( ’ Step Function ’)
2 Square Wave axis ([ -1 5 0 2])
grid
MATLAB has a built-in function square to generate a
periodic square waveform. Following example will help
you draw such a waveform.
4 Exponential Signals
2.1 Example
There are two types of exponential signals namely de-
Generate a square wave having amplitude 3 and fre- caying exponentials and growing exponentials. Follow-
quency of 2 Hz ing example will help you draw such a waveform.
clc , clear all , close all
t = 0:.0001:1; % time
A = 3; % amplitude 4.1 Example
f = 2; % frequency
d = 50; % duty cycle in percentag e Generate growing and decaying exponential signals with
y = A * square (2* pi * f *t , d ) ; amplitude 2
plot (t , y )
axis ([0 1 -4 4]) clc , clear all , close all
xlabel ( ’ Time in seconds ’) t = 0:0.1:1; % time
ylabel ( ’ Amplitude ’) A = 3; % amplitude
title ( ’ Square Wave ’) g = A * exp ( A * t ) ; % growing
grid d = A * exp ( - A * t ); % decaying
subplot (2 ,1 ,1)
plot (t , g )
title ( ’ Growing Exponenti a l Function ’)
3 Discrete Time Signals grid
subplot (2 ,1 ,2)
plot (t , d )
To visualize a discrete time signal, we may use the stem title ( ’ Decaying Exponent i al Function ’)
function. Specifically, stem(n,x) depicts the data con- grid
tained in vector x as a discrete time signal at the time

1/2
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
INSTITUTE OF INFORMATION & COMMUNICATION TECHNOLOGIES
ADVANCED DIGITAL SIGNAL PROCESSING
Lab 2: Generation of commonly used signals using MATLAB

5 Even and Odd Signals 6 Exercise


The even and odd parts of a signal x(t) are computed 1. Generate a discrete time triangular wave of unity
by using the following formulae. amplitude with width 0 and frequency π/8 radians
per second. Plot for 100 seconds (0 to 100 sec).
Even, xe (t) = 1/2 [x(t) + x(−t)]
Odd, xo (t) = 1/2 [x(t) − x(−t)] 2. Draw the following sinusoidal signals for 100
Where, x(−t) is reflected signal of x(t), i.e. the trans- seconds.
formed image obtained is exactly the mirror image of (a) A cos(ω + f )
the parent signal.
(b) A sin(ω + f )
where A = 4; ω = π/8 and f = 30 degrees.
5.1 Example Note: Convert degrees into radians.
Consider a signal which is mathematically represented
3. Draw the following signals
as follows.
 (a) x(t) = 5e−6t
1/2(t + 1) −1 ≤ t ≤ 1
x(t) = (b) y(t) = 3e5t
0 elsewhere
(c) z(t) = 60 sin(20πt)e−6t
(d) x(n) = 2(0.85)n
2 (e) y(n) = 60 sin(20πn)e−6n
4. Draw the signal x[n] = n (ramp function)
1
5. Plot continuous time and discrete time sinc func-
tion (i.e. sin(x)/x) for x between -5 and 5. Use the
−2 −1 1 2 built-in function sinc.

−1 6. Plot a rectangular function of width 3 units. (use


the built-in function rectpuls.
−2 7. Draw a discrete time triangular pulse using the
built-in function tripuls. Plot the function from
-3 to 3 seconds.
The Matlab code to plot this signal is following.
8. Find and plot u(n) − u(n − 5), where u(n) is a dis-
clc , clear all , close all
crete time unit step signal.
t = -1:0.0001:1;
x = 1/2*( t +1) ;
plot (t , x ) , grid
9. Plot the following signals for −5 ≤ t ≤ 5 seconds.
hold on Also plot even and odd parts of each.
line ([ -2 2] ,[0 0] , ’ Color ’ ,[.8 .8 .8])
line ([0 0] ,[ -2 2] , ’ Color ’ ,[.8 .8 .8]) (a) x(t) = cos(t) + sin(t) + cos(t) sin(t)
hold off
(b) x(t) = (1 + t3) cos 3(10t)
Now, even and odd parts of the signal may be plotted
(c) x(n) = [1 1 1 1 0 0 0]
as follows.
clc , clear all , close all (d) y(n) = [1 0 0 1 0 1 1 0 1 1]
t = -1:0.0001:1;
x = 1/2*( t +1) ; Also compute the energy of x(n) and y(n).
x1 = fliplr ( x ) ; % folded version of the signal Hint: Energy of a signal x(n) may be computed as
xe = 1/2*( x + x1 ) ; % Even part sum(abs(x.2 )).
xo = 1/2*( x - x1 ) ; % Odd part
subplot (2 ,1 ,1)
plot (t , xe )
xlabel ( ’ Time ’ )
ylabel ( ’ Even part of x ( t ) ’)
subplot (2 ,1 ,2)
plot (t , xo )
xlabel ( ’ Time ’)
ylabel ( ’ Odd part of x ( t ) ’ )

2/2

You might also like