Objective: % Time (Sampling Freq - 10 HZ) % Amplitude % Frequency % The Command y (Y 0) 0 Removes - Ve Values
Objective: % Time (Sampling Freq - 10 HZ) % Amplitude % Frequency % The Command y (Y 0) 0 Removes - Ve Values
Objective: % Time (Sampling Freq - 10 HZ) % Amplitude % Frequency % The Command y (Y 0) 0 Removes - Ve Values
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
2/2