LABEX4 Solved DSP

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 16

Name:Urooj Marvi

Section:

Laboratory Exercise 4
DISCRETE-TIME SYSTEMS: TIME-DOMAIN REPRESENTATION-I

2.1 SIMULATION OF DISCRETE-TIME SYSTEMS

Project 2.1 The Moving Average System

A copy of Program P2_1 is given below:

< 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. >

x[n] suppressed by the discrete-time system simulated by this program is


The component of the input
– s2 component is suppressed because of higher frequency

2.2 Run the following program and observe the output and comment on your results;

% Modification of P2_1 to convert it to a high pass 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 high pass filter
M = input('Desired length of the filter = ');
% By comparing eq. (2.13) to (2.3), you can see that "num"
% actually contains the impulse response (times the constant
% M). What we are actually doing in Q2.2 is multiplying the
% impulse response of the low pass filter in P2_1 by the
% sequency (-1)^n. This shifts the low pass frequency
% response up to be centered at f=0.25, making it a high
% pass filter.
num = (-1).^[0:M-1];
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);

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 –

Use the following set of values ;

1. f1=0.05; f2=0.47; M=15

2. f1=0.05; f2=0.10; M=3

3. f1=0.30; f2=0.47; M=4


< Insert MATLAB figure(s)s here. Copy from figure window(s)s and paste. >

1. f1=0.05; f2=0.47; M=15

3
2. f1=0.05; f2=0.10; M=3

3. f1=0.30; f2=0.47; M=4

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;

The output signal generated by running this program is plotted below .

< 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:

Project 2.3 Linear and Nonlinear Systems

A copy of Program P2_3 is given below:

< Insert program code here. Copy from m-file(s) and paste. >

Answers: % Program P2_3


% Generate the input sequences
clf;
n = 0:40;
a = 2;b = -3;
x1 = cos(2*pi*0.1*n);
x2 = cos(2*pi*0.4*n);
x = a*x1 + b*x2;
num = [2.2403 2.4908 2.2403];
den = [1 -0.4 0.75];
ic = [0 0]; % Set zero initial conditions
y1 = filter(num,den,x1,ic); % Compute the output y1[n]
y2 = filter(num,den,x2,ic); % Compute the output y2[n]
y = filter(num,den,x,ic); % Compute the output y[n]
yt = a*y1 + b*y2;
d = y - yt; % Compute the difference output d[n]
% Plot the outputs and the difference signal
subplot(3,1,1)
stem(n,y);
ylabel('Amplitude');

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 :

Use the following three different values;


1. a=1; b=-1; f1=0.05; f2=0.4;

7
2. a=10; b=2; f1=0.10; f2=0.25;

3. a=2; b=10; f1=0.15; f2=0.20;

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]

The plots generated are shown below -

< 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. >

1. a=1; b=-1; f1=0.05; f2=0.4;

2. a=10; b=2; f1=0.10; f2=0.25;

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

Project 2.4 Time-invariant and Time-varying Systems

A copy of Program P2_4 is given below:

< 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. >

These two sequences are related as follows -

The system is – time invariant

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

The system is – time invariant

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;

are shown below -


< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
1. f1=0.05; f2=0.40;

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.

The system is - time invariant

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

The system is – time variant

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 –

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;
are shown below –
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
1. f1=0.05; f2=0.40;

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

The system is – time invariant

Date: 9/19/2023 Signature:

16

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy