You are on page 1of 4

Signals Spectra and Signal Processing

Laboratory Exercise 2

MATLAB SIGNAL PLOTTING

Objective

Plot basic signals and signal sequence

Material
MATLAB r2020a or any version

Procedures

1. Run the matlab application and open an Editor (ctrl + N)

2. Write the following scripts. This will generate and plot unit impulse sequence

%% PART 1
% Generation of a Unit impulse 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]);

3. Save the script from editor with .m file extension


4. Run the script (ctrl + Enter) and study the output.

5. Write the following scripts. This will generate and plot complex exponential sequence

%% Part 2
% Generation of a complex exponential sequence
clf;
c = -(1/12)+(pi/6)*i;
K=2;
n = 0:40;
x = K*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
xlabel(’Time index n’);ylabel(’Amplitude’);
title(’Real part’);
subplot(2,1,2);
stem(n,imag(x));
xlabel(’Time index n’);ylabel(’Amplitude’);
title(’Imaginary part’);

6. Save the script from editor with .m file extension


7. Run the script (or ctrl + Enter) and study the output.

8. Write the following scripts. This will generate and plot sinusoidal signal

%% PART 3
% Generation of a sinusoidal sequence
n = 0:40;
f = 0.1;
phase = 0;
A = 1.5;
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’);
axis;

9. Save the script from editor with .m file extension


10. Run the script (or ctrl + Enter) and study the output.

Task

Perform the following tasks and record the answers. Provide the screenshots of the scripts
used, results, and workspace, and graph. You can use matlab for pc or matlab for android.

Answer the questions after performing the task

Use minimum command lines and number of scripts as possible.

1. Write a script creating a unit step signal


2. Write a script creating a real value exponential signal
3. Write a script creating a real value exponential signal decaying from amplitude 4
4. Write a script creating a sine wave with 3 units amplitude and length of 50
Critical Thinking Questions:

1. Did you tried to copy the script and paste it on the editor? If you did or if you will do it,
what will happened after you tried to run the script?
2. What are the errors you encountered while performing the laboratory procedures? How
did you correct those errors?
3. What are the functions of these commands and operations:

title
xlabel
clf
=
==
^
.^

Paste the screenshots of your answers on a ms word document with the answers to the
questions. Use the format below
LABORATORY EXERCISE NO. 2

___________TITLE__________

Name : ___________________________________________

Section: ___________________________________________

Task:

1.

2.

Questions:

1. ___________
2. ___________

You might also like