LABEX4 Solved DSP
LABEX4 Solved DSP
LABEX4 Solved DSP
Section:
Laboratory Exercise 4
DISCRETE-TIME SYSTEMS: TIME-DOMAIN REPRESENTATION-I
< Insert program code here. Copy from m-file(s) and paste. >
Answers: % Program P2_1
% 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;
1
Q2.1 The output sequence generated by running the above program for M = 2 with x[n] = s1[n]+s2[n] as
the input is shown below.
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
2.2 Run the following program and observe the output and comment on your results;
2
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;
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
Comment : In this figure we can see that low frequency signal is being
suppressed.
Q2.3 Program P2_1 is run for the following values of filter length M and following values of the fre quencies
of the sinusoidal signals s1[n] and s2[n]. The output generated for these different values of M and
the frequencies are shown below. From these plots we make the following observations –
3
2. f1=0.05; f2=0.10; M=3
4
Q2.4 The required modifications to Program P2_1 by changing the input sequence to a swept-frequency
sinusoidal signal (length 101, minimum frequency 0, and a maximum frequency 0.5) as the input signal
(see Program P1_7) are listed below:
< Insert program code here. Copy from m-file(s) and paste. >
clc;
clear all;
close all;
% Program P2_1
% Simulation of an M-point Moving Average Filter
% Generate the input signal
n = 0:100;
a = pi/202;
b =0;
M = input('Desired length of the filter = ');
arg = a*n.*n + b*n;
x = cos(arg);
num = ones(1,M);
y = filter(num,1,x)/M;
% Display the input and output signals
clf;
subplot(2,1,1);
plot(n, x);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Urooj Minimum frequency');
subplot(2,1,2);
plot(n, y);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Maximum Frequency');
axis;
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
5
The results of Questions Q2.1 and Q2.2 from the response of this system to the swept-frequency signal
can be explained as follows:
< Insert program code here. Copy from m-file(s) and paste. >
6
title('Output Due to Weighted Input: a \cdot x_{1}[n] + b \cdot x_{2}
[n]');
subplot(3,1,2)
stem(n,yt);
ylabel('Amplitude');
title('Weighted Output: a \cdot y_{1}[n] + b \cdot y_{2}[n]');
subplot(3,1,3)
stem(n,d);
xlabel('Time index n');ylabel('Amplitude');
title('Difference Signal');
Q2.7 The outputs y[n], obtained with weighted input, and yt[n], obtained by combining the two outputs
y1[n] and y2[n] with the same weights, are shown below along with the difference between the two
signals: are approximately similar these both signals are linear.
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
The two sequences are - approximately same and the difference between
them is zero.
The system is - linear
Q2.8 Program P2_3 was run for the following three different sets of values of the weighting constants, a and
b, and the following three different sets of input frequencies :
The plots generated for each of the above three cases are shown below :
7
2. a=10; b=2; f1=0.10; f2=0.25;
8
Based on these plots we can conclude that the system with different weights is – Linear
Q2.9 Program 2_3 was run with the following non-zero initial conditions – ic=[5 10]
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
Based on these plots we can conclude that the system with nonzero initial conditions is – non linear
Q2.10 Program P2_3 was run with nonzero initial conditions and for the following three different sets of
values of the weighting constants, a and b, and the following three different sets of input frequencies :
Use the following three different values;
The plots generated for each of the above three cases are shown below :
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
9
3. a=2; b=10; f1=0.15; f2=0.20;
Based on these plots we can conclude that the system with nonzero initial conditions and different
weights is – non linear
< Insert program code here. Copy from m-file(s) and paste. >
Answers: % Program P2_4
clc;
clear all;
close all;% 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);
10
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('Urooj 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;
Q2.12 The output sequences y[n] and yd[n-10] generated by running Program P2_4 are shown below -
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
Q2.13 The output sequences y[n] and yd[n-D] generated by running Program P2_4 for the following
values of the delay variable D – 2; 6; 8. are shown below -
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
D=2
11
D=6
D=8
In each case, these two sequences are related as follows – the difference between is zero
Q2.14 The output sequences y[n] and yd[n-10] generated by running Program P2_4 for the following
values of the input frequencies –
12
Use the following three different values ;
1. f1=0.05; f2=0.40;
2. f1=0.10; f2=0.25;
3. f1=0.15; f2=0.20;
2. f1=0.10; f2=0.25;
13
3. f1=0.15; f2=0.20;
In each case, these two sequences are related as follows - the difference b/w them is zero.
Q2.15 The output sequences y[n] and yd[n-10] generated by running Program P2_4 for non-zero initial
conditions are shown below – ic=[5 10]
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
14
These two sequences are related as follows – there is difference between them
Q2.16 The output sequences y[n] and yd[n-10] generated by running Program P2_4 for non-zero initial
conditions and following values of the input frequencies –
2. f1=0.10; f2=0.25;
3. f1=0.15; f2=0.20;
15
In each case, these two sequences are related as follows – difference between them is zero
16