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

Lab 1 - Introduction To MATLAB and Time Signals

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

Lab 1 - Introduction To MATLAB and Time Signals

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

CPEDSP – Digital Signal Processing

LABORATORY EXERCISES
Name: ___________________________________ Course: ________ Date: ___________
Yr. & Sec.: Lab. No.: 1 Instructor:
___________ _________________________

EXERCISE 1 – INTRODUCTION TO MATLAB AND SIGNALS (CONTINUOUS-TIME AND


DISCRETE-TIME SIGNALS)

I. OBJECTIVES

1. to verify properties of DFT such as periodicity, linearity, circular symmetry


2. to determine N-point in DFT
3. to successfully run a simulation of DFT properties and applications

II. MATERIALS

 PC
 MATLAB R2022a

III. PROCEDURE

1. When you start MATLAB®, the desktop appears in its default layout.

The desktop includes these panels:


 Current Folder — Access your files.
 Command Window — Enter commands at the command line, indicated by the prompt (>>).
 Workspace — Explore data that you create or import from files.
2. As you work in MATLAB, you issue commands that create variables and call functions.
Example, encode ‘a = 1’ in the Command Window and press ‘Enter’. MATLAB adds
variable a to the workspace and displays the result in the Command Window.
a=
1
3. Encode the following:
a = 1 [press Enter]
b = 3 [press Enter]
c = b^2 + cos(a) [press Enter]
What happened every time you press ‘Enter’? Write the result?
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________
______________________________________________________________________________

4. Create a new script by clicking the plus symbol or press Ctrl+N.

CPEDSP – Digital Signal Processing Page 1 of 5


Prepared by: Engr. Eddie G. Santillan, Jr.
5. Editor window will appear. Type the following codes on blank page in the Editor window.
%generate unit Step
clc; %clear console
clear all; %clear all script
close all; %close other scripts
t=-20:0.01:20;
L=length(t);
for i=1:L
if t(i)<0
x1(i)=0;
x2(i)=0;
else
x1(i)=1;
x2(i)=t(i);
end;
end;
figure;
plot(t,x1);
xlabel('t');
ylabel('amplitude');
title('unit step');
grid

6. Save your work by clicking or pressing Ctrl + S. Save it as exp1-1.m.

7. Press the button to start running your program. If there are errors in the codes, an error
message will be displayed in the Command Window.

When there are no errors in the codes. Then, this window will appear.

What continuous-time signal is shown in the window? _________________________________


8. Create a New Script and type the following codes.
%Sum of two signals

CPEDSP – Digital Signal Processing Page 2 of 5


Prepared by: Engr. Eddie G. Santillan, Jr.
clc;
close all;
clear all;
t=0:0.001:1;
L=length(t);
f1=1;
f2=3;
x1=sin(2*pi*f1*t); %first signal x1 = sin(2pi*ft)
x2=sin(2*pi*f2*t);
figure;
subplot(2,1,1);
plot(t,x1,'b',t,x2,'r');
xlabel('t');
ylabel('amplitude');
title('The signals x1(t) and x2(t)');
x3=x1+x2;
subplot(2,1,2);
plot(t,x3);
xlabel('t');
ylabel('amplitude');
title('The sum of x1(t) and x2(t)');
9. Save it as exp1-2.m and run it. Answer the following questions. What is the result of adding the
two signals?

10. Create a New Script and type the following codes.


% Multiplication of two signals
clc;
close all;
clear all;
t=0:0.001:1;
L=length(t);
f1=1;
f2=3;
x1=sin(2*pi*f1*t);
x2=sin(2*pi*f2*t);
figure;
subplot(2,1,1);
plot(t,x1,'b',t,x2,'r');
xlabel('t');
ylabel('amplitude');
title('The signals x1(t) and x2(t)');
x4=x1.*x2;
subplot(2,1,2);
plot(t,x4);
xlabel('t');
ylabel('amplitude');
title('The multiplication of x1(t) and x2(t)');

11. Save it as exp1-3.m and run it. Answer the following questions. What is the result of multiplying
the two signals?

CPEDSP – Digital Signal Processing Page 3 of 5


Prepared by: Engr. Eddie G. Santillan, Jr.
12. Create a New Script and type the following codes.
% Shifting of two signals
clc;
close all;
clear all;
t=0:0.001:1;
L=length(t);
f1=1;
f2=3;
x1=sin(2*pi*f1*t);
x2=sin(2*pi*f2*t);
figure;
subplot(2,1,1);
plot(t,x1,'b',t,x2,'r');
xlabel('t');
ylabel('amplitude');
title('The signals x1(t) and x2(t)');
x3=[zeros(1,100),x2(1:(L-100))];
subplot(2,1,2);
plot(t,x3);
title('the shifting of x2(t)');
xlabel('t');
ylabel('amplitude');
13. Save it as exp1-4.m and run it. Answer the following questions. What is the result of shifting
signal x2(t)?

EXERCISES:
PART 1: DISCRETE-TIME SIGNALS
1. Type the following codes and run it.
clc;
clear all;
close all;
num=input('type the numerator vector');
den=input('type the denominator vector');
N= input(' enter the desired length of the output sequence');
n=0:N-1;
imp=[1 zeros(1,N-1)];
H=filter(num, den, imp);
disp(' the response of the system is ');
disp(H);
stem(n,H);
xlabel('n');
ylabel('h(n)');
title(' Signal response');
2. When you run the codes, you will be prompt with the following requirements in the Command
Window?
type the numerator vector [1 3 –3 2 5 –2 2 4 –4]
type the denominator vector 1
enter the desired length of the output sequence 12

CPEDSP – Digital Signal Processing Page 4 of 5


Prepared by: Engr. Eddie G. Santillan, Jr.
What is the response of the system? ___________________________________________
3. Draw the output diagram of the signal? What type of discrete-time signal is it?
_________________

PART II. (CREATING A DISCRETE-TIME SIGNAL)


The following are codes for the discrete-time output of a unit step signal.
clc;
clear all;
close all;
n=-5:1:15;
L=length(n);
for i=1:L
if n(i)>=0
x1(i)=1;
x2(i)=n(i);
else
x1(i)=0;
x2(i)=0;
end;
end;
figure;
stem(n,x1);
xlabel('n');
ylabel('amplitude');
title('Unit step signal')
grid
1. Write a MATLAB program to generate a delayed unit step signal with a delay of 8 seconds,
then run it and display the result. Draw your output on the space provided below.

CPEDSP – Digital Signal Processing Page 5 of 5


Prepared by: Engr. Eddie G. Santillan, Jr.

You might also like