You are on page 1of 16

Signals Spectra and Signal Processing

Laboratory Exercise 4
Signal Systems
Reference: DSP LAB by Sanjit k. Mitra

Objective

Plot signal sequence of different systems


Understand the operations in signal systems

Material
MATLAB r2020a or any version

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

18. This is for a moving average filter system, composed of sum of several sinusoidal signals.

Write the following scripts. This will generate and plot an AM signal

%% PART 1
% Moving Average System
% Simulation of an M-point Moving Average Filter
% Generate the input signal
n = 0:100;
s1 = cos(2*pi*0.05*n); % A low frequency sinusoid
s2 = cos(2*pi*0.47*n); % A high frequency sinusoid
x = s1+s2;
% Implementation of the moving average filter
M = input(’Desired length of the filter = ’);
num = ones(1,M);
y = filter(num,1,x)/M;
% Display the input and output signals
clf;
subplot(2,2,1);
plot(n,s1);
axis([0, 100, -2, 2]);
xlabel(’Time index n’); ylabel(’Amplitude’);
title(’Signal # 1’);
subplot(2,2,2);
plot(n,s2);
axis([0, 100, -2, 2]);
xlabel(’Time index n’); ylabel(’Amplitude’);
title(’Signal # 2’);
subplot(2,2,3);
plot(n,x);
axis([0, 100, -2, 2]);
xlabel(’Time index n’); ylabel(’Amplitude’);
title(’Input Signal’);
subplot(2,2,4);
plot(n,y);
axis([0, 100, -2, 2]);
xlabel(’Time index n’); ylabel(’Amplitude’);
title(’Output Signal’);
axis;

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


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

21. Write the following scripts. This will generate a discrete time non-linear signal, composed of
sum of two sinusoidal sequence

%% Part 2
% A Simple Nonlinear Discrete-Time System
% Generate a sinusoidal input signal
clf;
n = 0:200;
x = cos(2*pi*0.05*n);
% Compute the output signal
x1 = [x 0 0]; % x1[n] = x[n+1]
x2 = [0 x 0]; % x2[n] = x[n]
x3 = [0 0 x]; % x3[n] = x[n-1]
y = x2.*x2 - x1.*x3;
y = y(2:202);
% Plot the input and output signals
subplot(2,1,1)
plot(n,x)
xlabel(’Time index n’);ylabel(’Amplitude’);
title(’Input Signal’)
subplot(2,1,2)
plot(n,y)
xlabel(’Time index n’);ylabel(’Amplitude’);
title(’Output signal’);

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


23. Run the script (or ctrl + Enter) and study the output.
24. Write the following scripts. This will simulate the system:
y[n]-0.4 y[n-1]+0.75 y[n-2]=2.2403 x[n]+2.4908 x[n-1]+2.2403 x[n-2]

the script will generate and plot two different input sequences x[n] and x[n-D], and to compute
and plot the corresponding output sequences y1[n], y2[n], and the difference y1[n] - y2[n + D].
This

%% PART 3
%Time-Invariant and Time-Varying Systems
% Generate the input sequences
clf;
n = 0:40; D = 10;a = 3.0;b = -2;
x = a*cos(2*pi*0.1*n) + b*cos(2*pi*0.4*n);
xd = [zeros(1,D) x];
num = [2.2403 2.4908 2.2403];
den = [1 -0.4 0.75];
ic = [0 0];% Set initial conditions
% Compute the output y[n]
y = filter(num,den,x,ic);
% Compute the output yd[n]
yd = filter(num,den,xd,ic);
% Compute the difference output d[n]
d=y-yd(1+D:41+D);
% Plot the outputs
subplot(3,1,1)
stem(n,y);
ylabel(’Amplitude’);
title(’Output y[n]’);grid;
subplot(3,1,2)
stem(n,yd(1:41));
ylabel(’Amplitude’);
title([’Output Due to Delayed Input x[n ’, num2str(D),’]’]);grid;
subplot(3,1,3)
stem(n,d);
xlabel(’Time index n’); ylabel(’Amplitude’);
title(’Difference Signal’);grid;
25. Save the script from editor with .m file extension
26. Run the script (or ctrl + Enter) and study the output.
27. Write the following scripts. This will compute and plot the impulse responses of the system
described by Equation:
y[n]-0.4 y[n-1]+0.75 y[n-2]=2.2403 x[n]+2.4908 x[n-1]+2.2403 x[n-2].

%% PART 4
%Computation of Impulse Responses of LTI Systems
% Compute the impulse response y
clf;
N = 40;
num = [2.2403 2.4908 2.2403];
den = [1 -0.4 0.75];
y = impz(num,den,N);
% Plot the impulse response
stem(y);
xlabel(’Time index n’); ylabel(’Amplitude’);
title(’Impulse Response’); grid;
28. Save the script from editor with .m file extension
29. Run the script (or ctrl + Enter) and study the output.

Task and Critical Thinking Questions:

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. For the Part 1, run the program for M=2 to generate the output signal with
x[n] = s1[n]+ s2[n] as the input. Which component of the input x[n] is suppressed by the
discrete time system simulated by this program?

2. Run Program of Part 1 for other values of filter length M, and various values of the frequencies
of the sinusoidal signals s1[n] and s2[n]. record the results. What are the significant changes in
the output? Explain your answers
3. Part 2: use sinusoidal signals with different frequencies as the input signals and compute the
output signal for each input. How do the output signals depend on the frequencies of the input
signal?

4. Run Program of Part 3 and compare the output sequences y[n] and yd[n - 10]. What is the
relation between these two sequences? Is this system time-invariant? Justify your answer

5. Modify the script for PART 3 to simulate the system with the equation:

y[n]=nx[n]+x[n - 1] and determine whether this system is time-invariant or not

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

Name : ___________________________________________
Section: _______________________________
Task and Critical Thinking Questions
5.

Explanation/answer:______________________________________

6.

7.
LABORATORY EXERCISE NO. 4
SIGNAL SYSTEMS

Name : Soriano,
Gallano, John Carlo D.
Edwin A._________
Section: _______________________________

PROCEDURE ANSWERS:
18.
21.

24.
27.

TASK ANSWERS:
Task and Critical Thinking Questions:
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. For the Part 1, run the program for M=2 to generate the output signal with
x[n] = s1[n]+ s2[n] as the input. Which component of the input x[n] is suppressed by the
discrete time system simulated by this program?
The component of the input x[n] that is suppressed by the discrete time system simulated by
this program is the high frequency one, which is the signal #2.

2. Run Program of Part 1 for other values of filter length M, and various values of the frequencies
of the sinusoidal signals s1[n] and s2[n]. record the results. What are the significant changes in
the output? Explain your answers
At f1=.05 f2=.47 M=50

At f1=.4 f2=.47 M=6


As seen from plots, thus filter results to more of the smoothing lines in comparison to the plots made in
case M=2. So to speak, s1 and s2 are high frequency. Similarly, they are both substantially attenuated in
the output.

At f1=.3 f2=.1 M=1


In my view, as seen from this plots, s2, which is the higher frequency input, is attenuated slightly as it is
compared with s1 in the system output.
%% PART 1
% Moving Average System
% Simulation of an M-point Moving Average Filter
% Generate the input signal
n = 0:100;
s1 = cos(2*pi*0.4*n); % A low frequency sinusoid
s2 = cos(2*pi*0.47*n); % A high frequency sinusoid
x = s1+s2;
% Implementation of the moving average filter
M = input('Desired length of the filter = ');
num = ones(1,M);
y = filter(num,1,x)/M;
% Display the input and output signals
clf;
subplot(2,2,1);
plot(n,s1);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal # 1');
subplot(2,2,2);
plot(n,s2);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal # 2');
subplot(2,2,3);
plot(n,x);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Input Signal');
subplot(2,2,4);
plot(n,y);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Signal');
axis;

3. Part 2: use sinusoidal signals with different frequencies as the input signals and compute the
output signal for each input. How do the output signals depend on the frequencies of the input
signal?
At f=.5

at f=.35

At f=0.25
It can be seen from this figure that the output seems to be spending on input for its amplitude.

%% Part 2
% A Simple Nonlinear Discrete-Time System
% Generate a sinusoidal input signal
clf;
n = 0:200;
x = cos(2*pi*.25*n);
% Compute the output signal
x1 = [x 0 0]; % x1[n] = x[n+1]
x2 = [0 x 0]; % x2[n] = x[n]
x3 = [0 0 x]; % x3[n] = x[n-1]
y = x2.*x2 - x1.*x3;
y = y(2:202);
% Plot the input and output signals
subplot(2,1,1)
plot(n,x)
xlabel('Time index n');ylabel('Amplitude');
title('Input Signal')
subplot(2,1,2)
plot(n,y)
xlabel('Time index n');ylabel('Amplitude');
title('Output signal');

4. Run Program of Part 3 and compare the output sequences y[n] and yd[n - 10]. What is the
relation between these two sequences? Is this system time-invariant? Justify your answer
These two sequences are related as follows – y[n-10] = yd[n]. The system is
Time Invariant.
%% PART 3
%Time-Invariant and Time-Varying Systems
% Generate the input sequences
clf;
n = 0:40; D = 10;a = 3.0;b = -2;
x = a*cos(2*pi*0.1*n) + b*cos(2*pi*0.4*n);
xd = [zeros(1,D) x];
num = [2.2403 2.4908 2.2403];
den = [1 -0.4 0.75];
ic = [0 0];% Set initial conditions
% Compute the output y[n]
y = filter(num,den,x,ic);
% Compute the output yd[n]
yd = filter(num,den,xd,ic);
% Compute the difference output d[n]
d=y-yd(1+D:41+D);
% Plot the outputs
subplot(3,1,1)
stem(n,y);
ylabel('Amplitude');
title('Output y[n]');grid;
subplot(3,1,2)
stem(n,yd(1:41));
ylabel('Amplitude');
title(['Output Due to Delayed Input x[n ', num2str(D),']']);grid;
subplot(3,1,3)
stem(n,d);
xlabel('Time index n'); ylabel('Amplitude');
title('Difference Signal');grid;

5. Modify the script for PART 3 to simulate the system with the equation:

y[n]=nx[n]+x[n - 1] and determine whether this system is time-invariant or not


%% PART 3
%Time-Invariant and Time-Varying Systems
% Generate the input sequences
clf;
n = 0:40; D = 10;a = 3.0;b = -2;
x = a*cos(2*pi*0.1*n) + b*cos(2*pi*0.4*n);
xd = [zeros(1,D) x];
num = [2.2403 2.4908 2.2403];
den = [1 -0.4 0.75];
ic = [0 0];% Set initial conditions
% Compute the output y[n]
y = filter(num,den,x,ic);
% Compute the output yd[n]
yd = filter(num,den,xd,ic);
% Compute the difference output d[n]
d=y-yd(1+D:41+D);
% Plot the outputs
subplot(3,1,1)
stem(n,y);
ylabel('Amplitude');
title('Output y[n]');grid;
subplot(3,1,2)
stem(n,yd(1:41));
ylabel('Amplitude');
title(['Output Due to Delayed Input x[n ', num2str(D),']']);grid;
subplot(3,1,3)
stem(n,d);
xlabel('Time index n'); ylabel('Amplitude');
title('Difference Signal');grid;

You might also like