0% found this document useful (0 votes)
59 views

Lab 02A-Signals and Wave Form Generation: Objectives

This document provides instructions for a lab experiment on generating and visualizing signals in MATLAB. The objectives are to generate simple and complex signals and view their waveforms. Common basic signals discussed include unit impulse, unit step, ramp, sinusoidal, and exponential signals for both continuous and discrete time. The document provides the code to generate these signals and display their waveforms. It also lists additional problems, such as generating specified signals and using sinusoidal functions to represent other signals. Students are instructed to complete the problems, attach code and results, and submit their work for feedback and grading.

Uploaded by

Aleena Qureshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
59 views

Lab 02A-Signals and Wave Form Generation: Objectives

This document provides instructions for a lab experiment on generating and visualizing signals in MATLAB. The objectives are to generate simple and complex signals and view their waveforms. Common basic signals discussed include unit impulse, unit step, ramp, sinusoidal, and exponential signals for both continuous and discrete time. The document provides the code to generate these signals and display their waveforms. It also lists additional problems, such as generating specified signals and using sinusoidal functions to represent other signals. Students are instructed to complete the problems, attach code and results, and submit their work for feedback and grading.

Uploaded by

Aleena Qureshi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1|Page Digital Signal Processing

Lab 02A- Signals and Wave form generation

Lab Engineer: Muhammad Hammad

1. Objectives:
(a). To generate some simple and complex signals and visualize them

2. Time Required: 3 hrs


3. Programming Language: MATLAB
4. Software Required:
(a). Windows/Linux OS
(b). MATLAB 7 or above
5. Signals: All the signals have to be either vectors (row or column), or matrices in MATLAB of
finite length. The index of the vector usually corresponds to time, and it always has to be 1 to N, if
N is assumed to be the length of the vector. MATLAB has the power to perform vector operations
quite efficiently, implying that processing of signals is easy.
As a general rule, discrete signals are viewed using ‘stem’ and indices must be plotted on the axis.
It’s always a good habit to label all the axes and title the figures properly.

Common basic signals are

▪ Discrete – Time signals:


1, for n = 0
▪ Unit impulse sequence. x(n) =  (n) = 
0, otherwise
1, for n  0
▪ Unit step sequence. x(n) = u(n) = 
0, otherwise
n, for n  0
▪ Unit ramp sequence. x (n) = r (n) = 
0, otherwise
▪ Sinusoidal sequence. x(n) = A sin(n +  ) .
▪ Exponential sequence. x(n) = A an, where A and a are constant.

▪ Continuous – time signals:


1, for t = 0
▪ Unit impulse signal.x ( t ) =  ( t ) = 
 0, otherwise
1, for t  0
▪ Unit step signal. x (t ) = u ( t ) = 
0, otherwise
t , for t  0
x(t ) = r (t ) = 
▪ Unit ramp signal. 0, otherwise

▪ Sinusoidal signal. x ( t ) = A sin((t+  ) .


▪ Exponential signal. x ( t ) = A e
at , where A and a are constant.
a
2|Page Digital Signal Processing

6. Procedure for Signal generation:

1. Start the program


2. Get the inputs for signal generation
3. Use the appropriate library function
4. Display the waveform

Source code:

%WAVE FORM GENERATION


%CT SIGNAL
%UNIT IMPULSE
clc;
clear all;
close all;
t1=-3:1:3;
x1=[0,0,0,1,0,0,0];
subplot(2,3,1);
plot(t1,x1);
xlabel('time');
ylabel('Amplitude');
title('Unit impulse signal');
%UNIT STEP SIGNAL
t2=-5:1:25;
x2=[zeros(1,5),ones(1,26)];
subplot(2,3,2);
plot(t2,x2);
xlabel('time');
ylabel('Amplitude');
title('Unit step signal');
%EXPONENTIAL SIGNAL
a=input('Enter the value of a:');
t3=-10:1:20;
x3=exp(-1*a*t3);
subplot(2,3,3);
plot(t3,x3);
xlabel('time');
ylabel('Amplitude');
title('Exponential signal');
%UNIT RAMP SIGNAL
t4=-10:1:20;
3|Page Digital Signal Processing

x4=t4;
subplot(2,3,4);
plot(t4,x4);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
A=input('Enter the amplitude:');
f=input('Enter the frequency:');
t5=-10:1:20;
x5=A*sin(2*pi*f*t5);
subplot(2,3,5);
plot(t5,x5)
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%RANDOM SIGNAL
t6=-10:1:20;
x6=rand(1,31);
subplot(2,3,6);
plot(t6,x6);
xlabel('time');
ylabel('Amplitude');
title('Random signal');

%WAVE FORM GENERATION


%DT SIGNAL
%UNIT IMPULSE
clc;
clear all;
close all;
n1=-3:1:3;
x1=[0,0,0,1,0,0,0];
subplot(2,3,1);
stem(n1,x1);
xlabel('time');
ylabel('Amplitude');
title('Unit impulse signal');
%UNIT STEP SIGNAL
n2=-5:1:25;
x2=[zeros(1,5),ones(1,26)];
subplot(2,3,2);
4|Page Digital Signal Processing

stem(n2,x2);
xlabel('time');
ylabel('Amplitude');
title('Unit step signal');
%EXPONENTIAL SIGNAL
a=input('Enter the value of a:');
n3=-10:1:20;
x3=power(a,n3);
subplot(2,3,3);
stem(n3,x3);
xlabel('time');
ylabel('Amplitude');
title('Exponential signal');
%UNIT RAMP SIGNAL
n4=-10:1:20;
x4=n4;
subplot(2,3,4);
stem(n4,x4);
xlabel('time');
ylabel('Amplitude');
title('Unit ramp signal');
%SINUSOIDAL SIGNAL
A=input('Enter the amplitude:');
f=input('Enter the frequency:');
n5=-10:1:20;
x5=A*sin(2*pi*f*n5);
subplot(2,3,5);
stem(n5,x5);
xlabel('time');
ylabel('Amplitude');
title('Sinusoidal signal');
%RANDOM SIGNAL
n6=-10:1:20;
x6=rand(1,31);
subplot(2,3,6);
stem(n6,x6);
xlabel('time');
ylabel('Amplitude');
title('Random signal');
5|Page Digital Signal Processing

7. Results

Continuous time:

Discrete time:

Output Waveform (Continuous time):


6|Page Digital Signal Processing

Output Waveform (Discrete Time):


7|Page Digital Signal Processing

8. Problem 1: Creation of Signals


a) We will often need the functions for these general signals:
• a unit impulse: δ(n-n0) of desired length
• a unit step: u(n-n0) of desired length
• shifter: a function which gives the input signal an arbitrary shift of n0
b) Generate the following signals in MATLAB:
x1[n] = 2 δ(n + 2) - δ(n-4), -5 ≤ n ≤ 5
x2[n] = n(u[n] – u[n-10]) + 10 exp(-0.3(n-10)) (u[n-10]-u[n-20]) 0 ≤ n ≤ 20
x3[n] = cos(0.04πn) + 0.02w[n], for 0 ≤ n ≤ 50,
where w[n] is a gaussian random signal
x4[n] is signal of four periods of sequence [5,4,3,2,1], in the range -10 ≤ n ≤ 9

c) Sinusoids--- the most general category of signals. Yes, it’s true. Believe it or not, every signal in this
universe contains nothing but sinusoids. We’ll explore this aspect in detail in our later labs, but for now,
these signals are quite interesting and beautiful to be looked in detail.
x1[n] = sin (
17
π
n), 0 ≤ n ≤ 25
x2[n] = cos (17πn), -15 ≤ n ≤ 15
x3[n] = sin (3 π n), -10 ≤ n ≤ 10
x4[n] = cos (23πn), 0 ≤ n ≤ 50
See the figures for each of the signals and comment about each with the aspect of even and odd, periodic
and aperiodic etc. Can you think of representing x3[n] without trigonometric functions?
We would be dealing with sinusoids quite frequently in future. It’s a good idea if we can understand the
mathematics of a sinusoidal signal and write a general function for it.
(i) Write a function to generate a sinusoid of given specifications: it should take six parameters: Freq,
Amplitude, Initial Phase, Sampling Freq., Start-Time, Stop Time.
(ii) Generate: s(t) = 50cos(2pi*1200*t + pi/4), using the above function.
If you are done with the simple practice session, Change the start and stop time in the above function to
generate a cosine which appears to be a sine.
(iii) Complex Exponentials: Generate x0[n] = exp(j*n/3), for some range and see its
real and imaginary parts separately. Also make the following signals:
• x1[n] = e(-0.1+j0.3)n, -10 ≤ n ≤ 10
• x2[n] = an u[n], where a=0.9, and 1.1 for -50 ≤ n ≤ 100
• x3[n] = 3 sin (17πn) + j 4 cos (17πn), 0 ≤ n ≤ 25

You may like to listen to these sinusoids, or some of these. Use MATLAB’s ‘sound’ to play your signal
at the sound card. What’s ‘fs’ in this sound? Explore ‘wavread’, ‘wavwrite’ also, and try to understand
the phenomenon involved. Play some sinusoids of audible frequency range. What happens if we use our
functions double, half, fliplr etc before playing the sinusoid?
8|Page Digital Signal Processing

Summary: This lab gives a tutorial about generating different continuous and discrete time signals
in MATLAB.

Instructions:
1. Do it yourself.
2. Attach Extra sheets for the problems which should include the code and its results screen shots.
3. Submit it before leaving until been specified by teacher
4. After marking, these will be deposited with teacher for record.

Name of Student, Student ID, Class and Section: ___________________________________


Feed Back by Student: (Please do not complain about less time)

Marks Obtained & Observation by Lab Engineer: ________________________________________

Dept. EE Military College of Signals, NUST

You might also like