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

LABEX2 (2)

The document describes a series of laboratory exercises focused on discrete-time systems and their simulation using MATLAB programs. It includes the implementation of moving average filters, LTI systems, and nonlinear systems, along with the analysis of output signals generated from various input frequencies. Key observations and modifications to the programs are discussed, emphasizing the effects of filter length and input signal characteristics on the output.

Uploaded by

tanphat.20052021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

LABEX2 (2)

The document describes a series of laboratory exercises focused on discrete-time systems and their simulation using MATLAB programs. It includes the implementation of moving average filters, LTI systems, and nonlinear systems, along with the analysis of output signals generated from various input frequencies. Key observations and modifications to the programs are discussed, emphasizing the effects of filter length and input signal characteristics on the output.

Uploaded by

tanphat.20052021
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 34

Name: Nguyen Tan phat

Mssv:23161307

Section:

Laboratory Exercise 2
DISCRETE-TIME SYSTEMS: TIME-DOMAIN REPRESENTATION

2.1 SIMULATION OF DISCRETE-TIME SYSTEMS

Project 2.1 The Moving Average System

A copy of Program P2_1 is given below:


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

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.

Signal #1 Signal #2
2 2

1 1
Amplitude

Amplitude
0 0

-1 -1

-2 -2
0 50 100 0 50 100
Time index n Time index n
Input Signal Output Signal
2 2

1 1
Amplitude

Amplitude
0 0

-1 -1

-2 -2
0 50 100 0 50 100
Time index n Time index n

The component of the input x[n] suppressed by the discrete-time system


simulated by this program is -

M = input('Desired length of the filter = ');


num = ones(1,M);

Q2.2 Program P2_1 is modified to simulate the LTI system y[n] = 0.5(x[n]–x[n–
1]) and process the input x[n] = s1[n]+s2[n] resulting in the output
sequence shown below:
% Simulation of an M-point Moving Average Filter
% Generate the input signal
clc; clear all; close all;
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 = [1,-1];
y = filter(num,1,x)/M;
% Display the input and output signals
subplot(2,2,1);
plot(n, s1);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');

2
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;

Signal #1 Signal #2
2 2

1 1
Amplitude

Amplitude
0 0

-1 -1

-2 -2
0 50 100 0 50 100
Time index n Time index n
Input Signal Output Signal
2 2

1 1
Amplitude

Amplitude

0 0

-1 -1

-2 -2
0 50 100 0 50 100
Time index n Time index n

The effect of changing the LTI system on the input is - making a HPF instead
of LPF as before.

Q2.3 Program P2_1 is run for the following values of filter length M and following values
of the frequencies of the sinusoidal signals s1[n] and s2[n]. The output

3
generated for these different values of M and the frequencies are shown below.
From these plots we make the following observations -

F1=0.3,f2=0.47,M=4

Signal #1 Signal #2
2 2

1 1
Amplitude

Amplitude
0 0

-1 -1

-2 -2
0 50 100 0 50 100
Time index n Time index n
Input Signal Output Signal
2 2

1 1
Amplitude

Amplitude

0 0

-1 -1

-2 -2
0 50 100 0 50 100
Time index n Time index n

f1=0.03,f2=0.1,M=4
Signal #1 Signal #2
2 2

1 1
Amplitude

Amplitude

0 0

-1 -1

-2 -2
0 50 100 0 50 100
Time index n Time index n
Input Signal Output Signal
2 2

1 1
Amplitude

Amplitude

0 0

-1 -1

-2 -2
0 50 100 0 50 100
Time index n Time index n

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 :

4
n=0:100;
a=pi/200;
b=0;
arg=(a*n.*n+b*n);
x=cos(arg);
M=input("nhap gia tri M :");
num=[ones(1,M)];
y=filter(num,1,x)/M;
subplot(211);
plot(n,x);
title("x");
subplot(212);
plot(n,y);
title("y");

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

x
1

0.5

-0.5

-1
0 10 20 30 40 50 60 70 80 90 100

y
1

0.5

-0.5

-1
0 10 20 30 40 50 60 70 80 90 100

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 :

5
Project 2.2 (Optional) A Simple Nonlinear Discrete-Time System

A copy of Program P2_2 is given below:


% Program P2_2
% 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');

Answers:

Q2.5 The sinusoidal signals with the following frequencies as the input signals were
used to generate the output signals :

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]

The output signals generated for each of the above input signals are displayed
below:

6
Input Signal
1

0.5

Amplitude 0

-0.5

-1
0 20 40 60 80 100 120 140 160 180 200
Time index n
Output signal
1
Amplitude

0.5

0
0 20 40 60 80 100 120 140 160 180 200
Time index n

The output signals depend on the frequencies of the input signal according to the
following rules:
y = x2.*x2-x1.*x3;

This observation can be explained mathematically as follows :

Q2.6 The output signal generated by using sinusoidal signals of the form x[n] =
sin(on) + K as the input signal is shown below for the following values of o
and K-

f=0.25

Input Signal
1

0.5
Amplitude

-0.5

-1
0 20 40 60 80 100 120 140 160 180 200
Time index n
Output signal
2

1.5
Amplitude

0.5

0
0 20 40 60 80 100 120 140 160 180 200
Time index n

7
f=0.5

Input Signal
1

0.5
Amplitude

-0.5

-1
0 20 40 60 80 100 120 140 160 180 200
Time index n
Output signal
1
Amplitude

0.5

0
0 20 40 60 80 100 120 140 160 180 200
Time index n

The dependence of the output signal yt[n] on the DC value K can be explained as -

Project 2.3 Linear and Nonlinear Systems

A copy of Program P2_3 is given below:


% 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');
title('Output Due to Weighted Input: a \cdot x_{1}[n] + b \cdot x_{2}
[n]');
subplot(3,1,2)
stem(n,yt);

8
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');

Answers:

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 :

Output Due to Weighted Input: a x1[n] + b x2[n]


20

10
Amplitude

-10

-20
0 5 10 15 20 25 30 35 40

Weighted Output: a y1[n] + b y2[n]


20

10
Amplitude

-10

-20
0 5 10 15 20 25 30 35 40

-15 Difference Signal


10
4

2
Amplitude

-2

-4

5 10 15 20 25 30 35 40
Time index n

The two sequences are -


x1 = cos(2*pi*0.1*n);
x2 = cos(2*pi*0.4*n);

The system is - x = a*x1 + b*x2;

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:
A=2 ; B=-4 f1=0.1 f2=0.4 A=3 ; B= -6 f1=f2=0.4 A=-8 ; B= 8 F1= 0.2 F2=0.4
n=0:40; n=0:40; clf;
x1=cos(2*pi*0.1*n); x1=cos(2*pi*0.4*n); n=0:40;
x2=cos(2*pi*0.4*n); x2=cos(2*pi*0.4*n); x1=cos(2*pi*0.2*n);
a=2; a=3; x2=cos(2*pi*0.4*n);
b=-4; b=-6; a=-8;

9
x=a*x1+b*x2; x=a*x1+b*x2; b=8;
num=[2.2403, 2.4908, num=[2.2403, 2.4908, x=a*x1+b*x2;
2.2403]; 2.2403]; num=[2.2403, 2.4908,
den=[1, -0.4, 0.75]; den=[1, -0.4, 0.75]; 2.2403];
y1=filter(num,den,x1); y1=filter(num,den,x1); den=[1, -0.4, 0.75];
y2=filter(num,den,x2); y2=filter(num,den,x2); y1=filter(num,den,x1);
y3=filter(num,den,x); y3=filter(num,den,x); y2=filter(num,den,x2);
y=a*y1+b*y2; y=a*y1+b*y2; y3=filter(num,den,x);
d=y3-y; d=y3-y; y=a*y1+b*y2;
subplot(311); subplot(311); d=y3-y;
stem(n,y3); stem(n,y3); subplot(311);
subplot(312); subplot(312); stem(n,y3);
stem(n,y); stem(n,y); subplot(312);
subplot(313); subplot(313); stem(n,y);
stem(n,d); stem(n,d); subplot(313);
stem(n,d);

The plots generated for each of the above three cases are shown below :

20 20

0
0
-20

-20 -40
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40

20 20

0
0
-20

-20 -40
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40

10 -15 10 -14
5 1

0 0

-5 -1
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40

100

-100
0 5 10 15 20 25 30 35 40

100

-100
0 5 10 15 20 25 30 35 40
10 -14
2

-2

0 5 10 15 20 25 30 35 40

Based on these plots we can conclude that the system with different weights is -

LINEAR SYSTEM

Q2.9 Program 2_3 was run with the following non-zero initial conditions :

% Program P2_3

10
% 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, 1]; % 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');
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');

The plots generated are shown below -

Output Due to Weighted Input: a x 1 [n] + b x 2 [n]


20
Amplitude

-20
0 5 10 15 20 25 30 35 40
Weighted Output: a y 1 [n] + b y 2 [n]
10
Amplitude

-10

-20
0 5 10 15 20 25 30 35 40

Difference Signal
Amplitude

-1
0 5 10 15 20 25 30 35 40
Time index n

11
Based on these plots we can conclude that the system with nonzero initial
conditions is :

NONLINEAR SYTEM

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 :
A=2 ; B=-4 f1=0.1 f2=0.4 A=3 ; B= -6 f1=f2=0.4 A=-8 ; B= 8 F1= 0.2 F2=0.4
ic=[0,1] ic=[0,2]

n=0:40; n=0:40; clf;


x1=cos(2*pi*0.1*n); x1=cos(2*pi*0.4*n); n=0:40;
x2=cos(2*pi*0.4*n); x2=cos(2*pi*0.4*n); x1=cos(2*pi*0.2*n);
a=2; a=3; x2=cos(2*pi*0.4*n);
b=-4; b=-6; a=-8;
x=a*x1+b*x2; x=a*x1+b*x2; b=8;
num=[2.2403, 2.4908, num=[2.2403, 2.4908, x=a*x1+b*x2;
2.2403]; 2.2403]; num=[2.2403, 2.4908,
den=[1, -0.4, 0.75]; den=[1, -0.4, 0.75]; 2.2403];
ic=[0, 1] ic=[0, 2]; den=[1, -0.4, 0.75];
y1=filter(num,den,x1,ic) y1=filter(num,den,x1,ic) ic=[0,3]
; ; y1=filter(num,den,x1,ic)
y2=filter(num,den,x2,ic) y2=filter(num,den,x2,ic) ;
; ; y2=filter(num,den,x2,ic)
y3=filter(num,den,x,ic); y3=filter(num,den,x,ic); ;
y=a*y1+b*y2; y=a*y1+b*y2; y3=filter(num,den,x,ic);
d=y3-y; d=y3-y; y=a*y1+b*y2;
subplot(311); subplot(311); d=y3-y;
stem(n,y3); stem(n,y3); subplot(311);
subplot(312); subplot(312); stem(n,y3);
stem(n,y); stem(n,y); subplot(312);
subplot(313); subplot(313); stem(n,y);
stem(n,d); stem(n,d); subplot(313);
stem(n,d);

The plots generated for each of the above three cases are shown below :

12
Output Due to Weighted Input: a x 1[n] + b x 2 [n]
5
20
Amplitude
0
0

-5
-20
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
Weighted Output: a y 1[n] + b y 2 [n]
10
10
Amplitude

0 0
-10

-20 -10
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40

Difference Signal 10
Amplitude

1 5

0 0

-1 -5
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
Time index n

100

-100
0 5 10 15 20 25 30 35 40

100

-100
0 5 10 15 20 25 30 35 40

-2
0 5 10 15 20 25 30 35 40

Based on these plots we can conclude that the system with nonzero initial
conditions and different weights is -

NONLINEAR SYTEM

Q2.11 Program P2_3 was modified to simulate the system :

y[n] = x[n]x[n–1]

The output sequences y1[n], y2[n],and y[n]of the above system generated
by running the modified program are shown below :

clf;
n=0:40;
x1=cos(2*pi*0.2*n);

13
x2=cos(2*pi*0.4*n);
a=2;
b=-3;
x=a*x1 + b*x2;
y=x.*[0 x(1:40)];
yt=a*x1.*[0 x1(1:40)] + b*x2.*[0 x2(1:40)];
d=y-yt;
subplot(311);
stem(n,y);
subplot(312);
stem(n,yt);
subplot(313);
stem(n,d);

10

-10
0 5 10 15 20 25 30 35 40

0
0 5 10 15 20 25 30 35 40

-5

-10
0 5 10 15 20 25 30 35 40

Comparing y[n] with yt[n] we conclude that the two sequences are - not the
same

This system is - NONLINER

Project 2.4 Time-invariant and Time-varying Systems

A copy of Program P2_4 is given below:


% Program P2_4
% 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]

14
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;

Answers:

Q2.12 The output sequences y[n] and yd[n-10] generated by running Program P2_4
are shown below -

Output y[n]
20
Amplitude

-20
0 5 10 15 20 25 30 35 40
Output due to Delayed Input x[n Ð10]
20
Amplitude

-20
0 5 10 15 20 25 30 35 40
Difference Signal
1
Amplitude

-1
0 5 10 15 20 25 30 35 40
Time index n

These two sequences are related as follows - y[n] = yd[n- 10].

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 - 5, 10,15

are shown below -

15
D=5 D=10 D=15

Output y[n] Output y[n] Output y[n]


20 20 20

Amplitude
Amplitude

Amplitude
0 0 0

-20 -20 -20


0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
Output due to Delayed Input x[n Ð5] Output due to Delayed Input x[n Ð10] Output due to Delayed Input x[n Ð15]
20 20 20

Amplitude
Amplitude

Amplitude
0 0 0

-20 -20 -20


0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
Difference Signal Difference Signal Difference Signal
1 1 1

Amplitude
Amplitude

Amplitude
0 0 0

-1 -1 -1
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
Time index n Time index n Time index n

In each case, these two sequences are related as follows - y(n)=y(n-D)

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 - 0.1-0.3, 0.2-0.4, 0.3-0.6

are shown below

D=4

0.1-0.3 0.2-0.4 0.3-0.6

Output y[n] Output y[n] Output y[n]


20 50 5
Amplitude

Amplitude
Amplitude

0 0 0

-20 -5
-50
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40

Output due to Delayed Input x[n Ð4] Output due to Delayed Input x[n Ð4] Output due to Delayed Input x[n Ð4]
20 50 5
Amplitude

Amplitude
Amplitude

0 0 0

-20 -5
-50
0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
0 5 10 15 20 25 30 35 40
Difference Signal Difference Signal
Difference Signal 1 1
1
Amplitude

Amplitude
Amplitude

0 0
0

-1 -1
-1 0 5 10 15 20 25 30 35 40 0 5 10 15 20 25 30 35 40
0 5 10 15 20 25 30 35 40
Time index n Time index n
Time index n

In each case, these two sequences are related as follows - y(n)=y(n-D)

16
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=[0,8]

Output y[n]
10
Amplitude

-10
0 5 10 15 20 25 30 35 40
Output due to Delayed Input x[n Ð4]
10
Amplitude

-10
0 5 10 15 20 25 30 35 40
Difference Signal
5
Amplitude

-5
0 5 10 15 20 25 30 35 40
Time index n

These two sequences are related as follows - yn and y(n-D) are not the shifted
versions each

other.

The system is - Time-varying

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 -
f1=0.1, f2=0.3; f1=0.2 f2=0.4,

are shown below -

f1=0.1, f2=0.3 f1=0.2 f2=0.4,

Output y[n] Output y[n]


50
20
Amplitude
Amplitude

0 0

-20 -50
0 5 10 15 20 25 30 35 40
0 5 10 15 20 25 30 35 40
Output due to Delayed Input x[n Ð10]
Output due to Delayed Input x[n Ð10] 50
20
Amplitude
Amplitude

0
0

-50
-20 0 5 10 15 20 25 30 35 40
0 5 10 15 20 25 30 35 40 Difference Signal
Difference Signal 5
Amplitude

5
Amplitude

0
-5
0 5 10 15 20 25 30 35 40
-5 Time index n
0 5 10 15 20 25 30 35 40
Time index n

17
In each case, these two sequences are related as follows - yn and y(n-D) are not the
shifted versions each

The system is - Time-varying

Q2.17 The modified Program 2_4 simulating the system

y[n] = n x[n] + x[n-1]

is given below:
n=0:40;D=10;a=3;b=-2;
x = a*cos(2*pi*0.1*n) + b*cos(2*pi*0.4*n);
xd=[zeros(1,D) x];
nd=0:length(xd)-1;
y=n.*x+[0 x(1:40)];
yd=nd.*xd+[0 xd(1:length(xd)-1)];
d=y-yd(1+D:41+D);
subplot(311);
stem(n,y);
subplot(312);
stem(n,yd(1:41));
subplot(313);
stem(n,d(1:41));

The output sequences y[n] and yd[n-10] generated by running modified


Program P2_4 are shown below -

200

-200
0 5 10 15 20 25 30 35 40

200

-200
0 5 10 15 20 25 30 35 40

50

-50
0 5 10 15 20 25 30 35 40

These two sequences are related as follows - yn and y(n-D) are not the shifted
versions each

18
The system is -Time-varying

Q2.18 (optional) The modified Program P2_3 to test the linearity of the system of Q2.18 is
shown below:
% 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;
y = n.*x+[0,x(1:40)];
yt = a*(n.*x1+[0 x1(1:40)])+b*(n.*x2+[0 x2(1:40)]);
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');
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');

The outputs y[n]and yt[n] obtained by running the modified program P2_3 are
shown below:

Output Due to Weighted Input: a x 1 [n] + b x 2 [n]


200
Amplitude

-200
0 5 10 15 20 25 30 35 40

Weighted Output: a y 1 [n] + b y 2 [n]


200
Amplitude

-200
0 5 10 15 20 25 30 35 40

10 -14 Difference Signal


Amplitude

0 5 10 15 20 25 30 35
Time index n

19
The two sequences are - almost similar

The system is - LINEAR

2.2 LINEAR TIME-INVARIANT DISCRETE-TIME SYSTEMS

Project 2.5 Computation of Impulse Responses of LTI Systems

A copy of Program P2_5 is shown below:


% Program P2_5
% 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;

Answers:

Q2.19 The first 41 samples of the impulse response of the discrete-time system of Project
2.3 generated by running Program P2_5 is given below:

Impulse Response
4

2
Amplitude

-1

-2

-3
0 5 10 15 20 25 30 35 40
Time index n

Q2.20 The required modifications to Program P2_5 to generate the impulse response of
the following causal LTI system :

y[n] + 0.71y[n-1] – 0.46y[n-2] – 0.62y[n-3]

20
= 0.9x[n] – 0.45x[n-1] + 0.35x[n-2] + 0.002x[n-3]

are given below:

% Program P2_5
% Compute the impulse response y
clf;
N = 45;
den = [1 0.71 -0.46 -0.62 ];
num = [0.9 -0.45 0.35 0.002];
y = impz(num,den,N);
% Plot the impulse response
stem(y);
xlabel('Time index n'); ylabel('Amplitude');
title('Impulse Response'); grid;

The first 45 samples of the impulse response of this discrete-time system


generated by running the modified is given below :
Impulse Response
2

1.5

1
Amplitude

0.5

-0.5

-1

-1.5
0 5 10 15 20 25 30 35 40 45
Time index n

21
Q2.21 The MATLAB program to generate the impulse response of a causal LTI system of
Q2.20 using the filter command is indicated below:

% Program P2_5
% Compute the impulse response y
clf;
N = 40;
den = [1 0.71 -0.46 -0.62 ];
num = [0.9 -0.45 0.35 0.002];
x=[1 zeros(1,39)];
ic = [0, 0];
y = filter(num,den,x);
% Plot the impulse response
stem(y);
xlabel('Time index n'); ylabel('Amplitude');
title('Impulse Response'); grid;

The first 40 samples of the impulse response generated by this program are shown
below:

Impulse Response
2

1.5

1
Amplitude

0.5

-0.5

-1

-1.5
0 5 10 15 20 25 30 35 40
Time index n
Comparing the above response with that obtained in Question Q2.20 we conclude
- SAME

22
Q2.22 The MATLAB program to generate and plot the step response of a causal LTI
system is indicated below:
% Program P2_5
% Compute the impulse response y
clf;
N = 40;
den = [1 0.71 -0.46 -0.62 ];
num = [0.9 -0.45 0.35 0.002];
x=[ones(1,40)];
ic = [0, 0];
y = filter(num,den,x);
% Plot the impulse response
stem(y);
xlabel('Time index n'); ylabel('Amplitude');
title('Impulse Response'); grid;

The first 40 samples of the step response of the LTI system of Project 2.3 are
shown below:
Impulse Response

1.2

0.8
Amplitude

0.6

0.4

0.2

-0.2
0 5 10 15 20 25 30 35 40
Time index n

Project 2.6 Cascade of LTI Systems

A copy of Program P2_6 is given below:


% Program P2_6
% Cascade Realization
clf;
x = [1 zeros(1,40)]; % Generate the input
n = 0:40;
% Coefficients of 4th order system

23
den = [1 1.6 2.28 1.325 0.68];
num = [0.06 -0.19 0.27 -0.26 0.12];
% Compute the output of 4th order system
y = filter(num,den,x);
% Coefficients of the two 2nd order systems
num1 = [0.3 -0.2 0.4];den1 = [1 0.9 0.8];
num2 = [0.2 -0.5 0.3];den2 = [1 0.7 0.85];
% Output y1[n] of the first stage in the cascade
y1 = filter(num1,den1,x);
% Output y2[n] of the second stage in the cascade
y2 = filter(num2,den2,y1);
% Difference between y[n] and y2[n]
d = y - y2;
% Plot output and difference signals
subplot(3,1,1);
stem(n,y);
ylabel('Amplitude');
title('Output of 4th order Realization'); grid;
subplot(3,1,2);
stem(n,y2)
ylabel('Amplitude');
title('Output of Cascade Realization'); grid;
subplot(3,1,3);
stem(n,d)
xlabel('Time index n');ylabel('Amplitude');
title('Difference Signal'); grid;

Answers:

Q2.23 The output sequences y[n], y2[n], and the difference signal d[n] generated
by running Program P2_6 are indicated below:

24
Output of 4th order Realization
1

Amplitude
0

-1
0 5 10 15 20 25 30 35 40
Output of Cascade Realization
1
Amplitude

-1
0 5 10 15 20 25 30 35 40

10 -15 Difference Signal


5
Amplitude

-5
0 5 10 15 20 25 30 35 40
Time index n

The relation between y[n] and y2[n] is - almost similar

Q2.24 The sequences generated by running Program P2_6 with the input changed to a
sinusoidal sequence are as follows :

Output of 4th order Realization


1
Amplitude

-1
0 5 10 15 20 25 30 35 40
Output of Cascade Realization
1
Amplitude

-1
0 5 10 15 20 25 30 35 40

10 -15 Difference Signal


5
Amplitude

-5
0 5 10 15 20 25 30 35 40
Time index n

The relation between y[n] and y2[n] in this case is - almost similar

Q2.25 The sequences generated by running Program P2_6 with non-zero initial condition
vectors are now as given below:

25
Output of 4th order Realization
10

Amplitude
5

-5
0 5 10 15 20 25 30 35 40
Output of Cascade Realization
10
Amplitude

-10
0 5 10 15 20 25 30 35 40
Difference Signal
10
Amplitude

-10
0 5 10 15 20 25 30 35 40
Time index n

The relation between y[n] and y2[n] in this case is - DIFFERENT

Q2.26 The modified Program P2_6 with the two 2nd-order systems in reverse order and
with zero initial conditions is displayed below :
% Program P2_6
% Cascade Realization
clf;
x = [1 zeros(1,40)]; % Generate the input
n = 0:40;
% Coefficients of 4th order system
den = [1 1.6 2.28 1.325 0.68];
num = [0.06 -0.19 0.27 -0.26 0.12];
% Compute the output of 4th order system
ic=[0 0 0 0]
y = filter(num,den,x,ic);
% Coefficients of the two 2nd order systems
num1 = [0.3 -0.2 0.4];den1 = [1 0.9 0.8];
num2 = [0.2 -0.5 0.3];den2 = [1 0.7 0.85];
% Output y1[n] of the first stage in the cascade
ic1=[0 0]
y1 = filter(num2,den2,x,ic2);
% Output y2[n] of the second stage in the cascade
ic2=[0 0]
y2 = filter(num1,den1,y1,ic1);
% Difference between y[n] and y2[n]
d = y - y2;
% Plot output and difference signals
subplot(3,1,1);
stem(n,y);
ylabel('Amplitude');
title('Output of 4th order Realization'); grid;
subplot(3,1,2);
stem(n,y2)
ylabel('Amplitude');
title('Output of Cascade Realization'); grid;
subplot(3,1,3);
stem(n,d)

26
xlabel('Time index n');ylabel('Amplitude');
title('Difference Signal'); grid;

The sequences generated by running the modified program are sketched below :

Output of 4th order Realization


1
Amplitude

-1
0 5 10 15 20 25 30 35 40
Output of Cascade Realization
1
Amplitude

-1
0 5 10 15 20 25 30 35 40

10 -15 Difference Signal


5
Amplitude

-5
0 5 10 15 20 25 30 35 40
Time index n

The relation between y[n] and y2[n] in this case is -almost similar

Q2.27 The sequences generated by running the modified Program P2_6 with the two 2nd-
order systems in reverse order and with non-zero initial conditions are displayed
below:

Output of 4th order Realization


10
Amplitude

-5
0 5 10 15 20 25 30 35 40
Output of Cascade Realization
10
Amplitude

-10
0 5 10 15 20 25 30 35 40
Difference Signal
5
Amplitude

-5

0 5 10 15 20 25 30 35 40
Time index n

The relation between y[n] and y2[n] in this case is - different

Project 2.7 Convolution

27
A copy of Program P2_7 is reproduced below:
% Program P2_7
clf;
h = [3 2 1 -2 1 0 -4 0 3]; % impulse response
x = [1 -2 3 -4 3 2 1]; % input sequence
y = conv(h,x);
n = 0:14;
subplot(2,1,1);
stem(n,y);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Obtained by Convolution'); grid;
x1 = [x zeros(1,8)];
y1 = filter(h,1,x1);
subplot(2,1,2);
stem(n,y1);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Generated by Filtering'); grid;

Answers:

Q2.28 The sequences y[n] and y1[n] generated by running Program P2_7 are shown
below:

Output Obtained by Convolution


20

10
Amplitude

-10

-20
0 2 4 6 8 10 12 14
Time index n
Output Generated by Filtering
20

10
Amplitude

-10

-20
0 2 4 6 8 10 12 14
Time index n

The difference between y[n] and y1[n] is - SAME

The reason for using x1[n] as the input, obtained by zero-padding x[n], for
generating y1[n] is - SINCE N HAS 15 VALUES, X HAS ONLY 7 VALUES, THE
FILTER FUNCTION SHOWS THE NUMBER OF BNAGWF VALUES AS THE

28
NUMBER OF INPUT VALUES, SO I ADD 8 ZEROES TO NOT AFFECT THE
RESULT, BUT THE NUMBER OF VALUES IS STILL CORRECT FOR N

Q2.29 The modified Program P2_7 to develop the convolution of a length-15 sequence
h[n] with a length-10 sequence x[n]is indicated below:
% Program P2_7
clf;
h = [ 9 1 0 5 7 3 6 4 19 12 13 14 0 15 8 ]; % impulse response
x = [10 9 8 7 6 5 4 3 2 1 ]; % input sequence
y = conv(h,x);
n = 0:23;
subplot(2,1,1);
stem(n,y);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Obtained by Convolution'); grid;
x1 = [x zeros(1, 14)];
y1 = filter(h,1,x1);
subplot(2,1,2);
stem(n,y1);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Generated by Filtering'); grid;

The sequences y[n] and y1[n] generated by running modified Program P2_7 are shown
below:

Output Obtained by Convolution


600
Amplitude

400

200

0
0 5 10 15 20 25
Time index n
Output Generated by Filtering
600
Amplitude

400

200

0
0 5 10 15 20 25
Time index n

The difference between y[n] and y1[n] is - THEY ARE SAME

Project 2.8 Stability of LTI Systems

29
A copy of Program P2_8 is given below:
% Program P2_8
% Stability test based on the sum of the absolute
% values of the impulse response samples
clf;
num = [1 -0.8]; den = [1 1.5 0.9];
N = 200;
h = impz(num,den,N+1);
parsum = 0;
for k = 1:N+1;
parsum = parsum + abs(h(k));
if abs(h(k)) < 10^(-6), break, end
end
% Plot the impulse response
n = 0:N;
stem(n,h)
xlabel('Time index n'); ylabel('Amplitude');
% Print the value of abs(h(k))
disp('Value =');disp(abs(h(k)));

Answers:

Q2.30 The purpose of the for command is - Repeat statements a specific number of times.

The purpose of the end command is - Terminate scope of FOR, WHILE, SWITCH,

TRY, and IF statements.

for biến = giá_trị_bắt_đầu : bước_nhảy while: điều_kiện while điều_kiện


% Các câu lệnh thực hiện khi điều
% Một số câu lệnh
giá_trị_kết_thúc kiện còn đúng if điều_kiện_dừng
% Các câu lệnh thực thi trong vòng lặp break; % Thoát khỏi vòng lặp ngay lập
end tức
end end
% Các câu lệnh tiếp theo
end

Q2.31 The purpose of the break command is - Terminate execution of WHILE or FOR
loop.

Q2.32 The discrete-time system of Program P2_8 is - num = [1-0.8]; den = [1 1.5
0.9]

The impulse response generated by running Program P2_8 is shown below :

30
3

1
Amplitude

-1

-2

-3
0 20 40 60 80 100 120 140 160 180 200
Time index n

The value of |h(K)| here is - Value =

1.6761e-05

From this value and the shape of the impulse response we can conclude that the
system is - stable

By running Program P2_8 with a larger value of N the new value of | h(K)|is -
9.1752e-07

From this value we can conclude that the system is - stable

Q2.33 The modified Program P2_8 to simulate the discrete-time system of Q2.33 is given
below:

% Program P2_8
% Stability test based on the sum of the absolute
% values of the impulse response samples
clf;
num = [1 -4 3]; den = [1 -1.7 1];
N = 200;
h = impz(num,den,N+1);
parsum = 0;
for k = 1:N+1;
parsum = parsum + abs(h(k));
if abs(h(k)) < 10^(-6), break, end
end
% Plot the impulse response
n = 0:N;
stem(n,h)
xlabel('Time index n'); ylabel('Amplitude');

31
% Print the value of abs(h(k))
disp('Value =');disp(abs(h(k)));

The impulse response generated by running the modified Program P2_8 is shown
below:

2.5

1.5

0.5
Amplitude

-0.5

-1

-1.5

-2

-2.5
0 20 40 60 80 100 120 140 160 180 200
Time index n

The values of |h(K)| here are - 2.0321

From this value and the shape of the impulse response we can conclude that the
system is - stable

Project 2.9 Illustration of the Filtering Concept

A copy of Program P2_9 is given below:


% Program P2_9
% Generate the input sequence
clf;
n = 0:299;
x1 = cos(2*pi*10*n/256);
x2 = cos(2*pi*100*n/256);
x = x1+x2;
% Compute the output sequences
num1 = [0.5 0.27 0.77];
y1 = filter(num1,1,x); % Output of System #1
den2 = [1 -0.53 0.46];
num2 = [0.45 0.5 0.45];
y2 = filter(num2,den2,x); % Output of System #2
% Plot the output sequences

32
subplot(2,1,1);
plot(n,y1);axis([0 300 -2 2]);
ylabel('Amplitude');
title('Output of System #1'); grid;
subplot(2,1,2);
plot(n,y2);axis([0 300 -2 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output of System #2'); grid;

Answers:

Q2.34 The output sequences generated by this program are shown below :

Output of System #1
2

1
Amplitude

-1

-2
0 50 100 150 200 250 300

Output of System #2
2

1
Amplitude

-1

-2
0 50 100 150 200 250 300
Time index n

The filter with better characteristics for the suppression of the high frequency
component of the input signal x[n] is -#system 2
y2 = filter(num2,den2,x); % Output of System #2
% Plot the output sequences

Q2.35 The required modifications to Program P2_9 by changing the input sequence to a
swept sinusoidal sequence (length 301, minimum frequency 0, and maximum
frequency 0.5) are listed below along with the output sequences generated by the
modified program:
clc; clear all; close all;
n = 0:300;
a = pi/600;
b = 0;
arg = a*n.*n + b*n;
x = cos(arg);
% Compute the output sequences
num1 = [0.5 0.27 0.77];
y1 = filter(num1,1,x); % Output of System #1
den2 = [1 -0.53 0.46];
num2 = [0.45 0.5 0.45];
y2 = filter(num2,den2,x); % Output of System #2
% Plot the output sequences

33
subplot(2,1,1);
plot(n,y1);axis([0 300 -2 2]);
ylabel('Amplitude');
title('Output of System #1'); grid;
subplot(2,1,2);
plot(n,y2);axis([0 300 -2 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output of System #2'); grid;

Output of System #1
2

1
Amplitude

-1

-2
0 50 100 150 200 250 300

Output of System #2
2

1
Amplitude

-1

-2
0 50 100 150 200 250 300
Time index n

The filter with better characteristics for the suppression of the high frequency
component of the input signal x [n] is - SYSTEM #2
den2 = [1 -0.53 0.46];
num2 = [0.45 0.5 0.45];
y2 = filter(num2,den2,x); % Output of System #2

Date: 14/4/2025 Signature: Nguyen Tan Phat

34

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