Reference: DSP LAB by Sanjit K. Mitra
Reference: DSP LAB by Sanjit K. Mitra
Laboratory Exercise 3
MATLAB SIGNAL PLOTTING AND OPERATIONS
Reference: DSP LAB by Sanjit k. Mitra
Objective
Material
MATLAB r2020a or any version
Procedures
7. Run the matlab application and open an Editor (ctrl + N)
8. For the AM signal y[n], A is the amplitude, xL[n]) is the modulating signal (low frequency), xH[n]
is the carrier (high frequency) and m is the modulation index.
Write the following scripts. This will generate and plot an AM signal
%% PART 1
% Generate amplitude modulated sequence
clf;
n = 0:100;
m = 0.4;
fH = 0.1;
fL = 0.01;
xH = sin(2*pi*fH*n);
xL = sin(2*pi*fL*n);
y = (1+m*xL).*xH;
stem(n,y);
grid;
xlabel(’Time index n’);
ylabel(’Amplitude’);
%% Part 2
% Generation of a swept frequency sinusoidal sequence
n = 0:100;
a = pi/2/100;
b=0;
arg = a*n.*n + b*n;
x = cos(arg);
clf;
stem(n, x);
axis([0,100,-1.5,1.5]);
title(’Swept-Frequency Sinusoidal Signal’);
xlabel(’Time index n’);
ylabel(’Amplitude’);
grid; axis;
14. Write the following scripts. This will generate and plot approximated random signal
%% PART 3
% Signal Smoothing by Averaging
clf;
R = 51;
d = 0.8*(rand(R,1) - 0.5); % Generate random noise
m = 0:R-1;
s = 2*m.*(0.9.^m); % Generate uncorrupted signal
x=s+d’; %Generate noise corrupted signal
subplot(2,1,1);
plot(m,d’,’r-’,m,s,’g--’,m,x,’b-.’);
xlabel(’Time index n’);
ylabel(’Amplitude’);
legend(’d[n] ’,’s[n] ’,’x[n] ’);
x1 = [0 0 x];
x2 = [0 x 0];
x3 = [x 0 0];
y = (x1 + x2 + x3)/3;
subplot(2,1,2);
plot(m,y(2:R+1),’r-’,m,s,’g--’);
legend(’y[n] ’,’s[n] ’);
xlabel(’Time index n’);
ylabel(’Amplitude’);
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.
8. Modify the script for PART 1 to create a smoother AM signal. You can have any time limit.
a.
b.
10. Write a script that will create sawtooth waves
a.
b.
Paste the screenshots of your answers on a ms word document with the answers to the questions. Use the
format below
LABORATORY EXERCISE NO. 3
___________TITLE__________
Name : ___________________________________________
Section: _______________________________
Task:
3.
4.
Questions:
3. ___________
4. __________
LABORATORY EXERCISE NO. 3
MATLAB SIGNAL PLOTTING AND OPERATIONS
Name : Soriano,
Gallano, John Carlo D.
Edwin A._________
Section: _______________________________
PROCEDURE ANSWERS:
8.
11.
14.
TASK ANSWERS:
1.
Ac=5
AM=1
Fc=16
Fm=0.02
m=1
tl=linspace(0,600,600)
y1=sin(2*pi*Fm*tl)
y2=sin(2*pi*Fc*tl)
Y=(1+m.*y1).*(Ac.*y2)
subplot(3,1,1)
plot(tl,y1)
xlabel('Time Index')
ylabel('Amplitude')
title('message signal')
subplot(3,1,2)
plot(tl,y2)
xlabel('Time Index')
ylabel('Amplitude')
title('Carrier signal')
subplot(3,1,3)
plot(tl,y2)
xlabel('Time Index')
ylabel('Amplitude')
title('Modulated signal')
2.A.
L=30;
A=2.25;
N=15
omega=2*pi/N
T=0:omega:(L-1)*omega
X=0:L-1
Vsquare=A*square(T,65)
hold On
stem(X,Vsquare)
subplot(2,1,1);
xlabel('Time Index n')
ylabel('Amplitude')
title('square Wave')
2.B
L=30;
A=2.25;
N=15
omega=2*pi/N
T=0:omega:(L-1)*omega
X=0:L-1
Vsquare=A*square(T,30)
hold On
stem(X,Vsquare)
subplot(2,1,1);
xlabel('Time Index n')
ylabel('Amplitude')
title('square Wave')
3.A
L=60;
A=4;
N=20
omega=2*pi/N
T=0:omega:(L-1)*omega
X=0:L-1
Vsaw=A*sawtooth(T)
hold On
stem(X,Vsaw)
subplot(2,1,1);
xlabel('Time Index n')
ylabel('Amplitude')
title('Saw Tooth Wave')
3.B
L=60;
A=4;
N=20
omega=2*pi/N
T=0:omega:(L-1)*omega
X=0:L-1
Vsaw=A*sawtooth(T,.5)
hold On
stem(X,Vsaw)
subplot(2,1,1);
xlabel('Time Index n')
ylabel('Amplitude')
title('Saw Tooth Wave')
QUESTIONS:
1. How can you modify the frequencies of the swept frequency signal (PART 2)?
I can modify the frequencies of the swept frequency signal (PART 2) through changing the axix
values.
2. For the PART 3: signal smoothing and averaging, what are the relationships between signals x, x1,
x2 and x3?
Through the signals 1. x, x1, x2 and x3, it just indicate the result of the wave.