Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
7 views14 pages

Report Week 2

Uploaded by

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

Report Week 2

Uploaded by

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

Laboratory Exercise 2 Page 1

Name: Trần Thanh Nguyên


Section: 23119087

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

2 SIMULATION OF DISCRETE-TIME SYSTEMS

Project 2.1: The Moving Average System

A copy of Program P2_1 is given below:

Listing 1: Program P2_1


1 % Program P2_1
2 % Simulation of an M−point Moving Average Filter
3 % Generate the input signal
4 n = 0:100;
5 s1 = cos(2*pi*0.05*n); % A low frequency sinusoid
6 s2 = cos(2*pi*0.47*n); % A high frequency sinusoid
7 x = s1+s2;
8 % Implementation of the moving average filter
9 M = input('Desired length of the filter = ');
10 num = ones(1,M);
11 y = filter(num,1,x)/M;
12 % Display the input and output signals
13 clf;
14 subplot(2,2,1);
15 plot(n,s1);
16 axis([0, 100, −2, 2]);
17 xlabel('Time index n'); ylabel('Amplitude');
18 title('Signal # 1');
19 subplot(2,2,2);
20 plot(n,s2);
21 axis([0, 100, −2, 2]);
22 xlabel('Time index n'); ylabel('Amplitude');
23 title('Signal # 2');
24 subplot(2,2,3);
25 plot(n,x);
26 axis([0, 100, −2, 2]);
27 xlabel('Time index n'); ylabel('Amplitude');
28 title('Input Signal');
29 subplot(2,2,4);
30 plot(n,y);
31 axis([0, 100, −2, 2]);
32 xlabel('Time index n'); ylabel('Amplitude');
33 title('Output Signal');
34 axis;

Answers:
Laboratory Exercise 2 Page 2

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.

Hình 1: Output sequence for Q2.1

The component of the input x[n] suppressed by the discrete-time system simulated by this program is

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:

Hình 2: Output sequence for Q2.2


Laboratory Exercise 2 Page 3

The effect of changing the LTI system on the input is

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 generated for these different values of M and the frequencies
are shown below. From these plots we make the following observations:

Hình 3: Output sequences for different values of M and frequencies

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:

Listing 2: Modified Program P2_1 for Q2.4


1 function Q2_4()
2 % Generate swept−frequency sinusoidal signal
3 n = 0:100;
4 f_min = 0;
5 f_max = 0.5;
6 % Linear frequency sweep
7 f_inst = f_min + (f_max − f_min) * n / max(n);
8 x = cos(2*pi * cumsum(f_inst) / 101);
9
10 % Apply moving average filter with M = 2
11 M = 2;
12 num = ones(1,M);
13 y1 = filter(num,1,x)/M;
Laboratory Exercise 2 Page 4

14
15 % Apply modified system y[n] = 0.5(x[n] − x[n−1])
16 num2 = 0.5*[1 −1];
17 y2 = filter(num2, 1, x);
18
19 figure;
20 subplot(3,1,1);
21 plot(n,x);
22 title('Swept−frequency Input Signal');
23 xlabel('Time index n'); ylabel('Amplitude');
24
25 subplot(3,1,2);
26 plot(n,y1);
27 title('Output of Moving Average Filter (M=2)');
28 xlabel('Time index n'); ylabel('Amplitude');
29
30 subplot(3,1,3);
31 plot(n,y2);
32 title('Output of Difference Filter');
33 xlabel('Time index n'); ylabel('Amplitude');
34 end
35 Q2_4()

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

Hình 4: Output signal for swept-frequency input

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:
Laboratory Exercise 2 Page 5

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

A copy of Program P2_2 is given below:

Listing 3: Program P2_2


1 % Insert program code here. Copy from m−file(s) and paste.

Answers:

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

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

Hình 5: Output signals for different input frequencies

The output signals depend on the frequencies of the input signal according to the following rules:

This observation can be explained mathematically as follows:

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

Hình 6: Output signals with DC component

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:


Laboratory Exercise 2 Page 6

Listing 4: Program P2_3


1 % Insert program code here. Copy from m−file(s) and paste.

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:

Hình 7: Weighted inputs and outputs comparison

The two sequences are

The system is

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:

Hình 8: System response for different weights and frequencies

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

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

The plots generated are shown below:

Hình 9: System response with non-zero initial conditions

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

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:

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

Hình 10: System response with non-zero initial conditions and different weights

Based on these plots we can conclude that the system with nonzero initial conditions and different weights
is
Laboratory Exercise 2 Page 7

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:

Hình 11: Modified system output sequences

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

This system is

Project 2.4: Time-invariant and Time-varying Systems

A copy of Program P2_4 is given below:

Listing 5: Program P2_4


1 % Insert program code here. Copy from m−file(s) and paste.

Answers:

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

Hình 12: Output sequences for Q2.12

These two sequences are related as follows:

The system is

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 are shown below:

Hình 13: Output sequences for different delay values

In each case, these two sequences are related as follows:

The system is
Laboratory Exercise 2 Page 8

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 are shown below:

Hình 14: Output sequences for different input frequencies

In each case, these two sequences are related as follows:

The system is

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:

Hình 15: Output sequences with non-zero initial conditions

These two sequences are related as follows:

The system is

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 are shown below:

Hình 16: Output sequences with non-zero initial conditions and different frequencies

In each case, these two sequences are related as follows:

The system is

Q2.17 The modified Program P2_4 simulating the system


y[n] = n · x[n] + x[n − 1]
is given below:

Listing 6: Modified Program P2_4 for Q2.17


1 % Insert program code here. Copy from m−file(s) and paste.

The output sequences y[n] and yd [n − 10] generated by running modified Program P2_4 are shown below:

Hình 17: Output sequences for time-varying system

These two sequences are related as follows:


Laboratory Exercise 2 Page 9

The system is

Q2.18 (optional) The modified Program P2_3 to test the linearity of the system of Q2.17 is shown below:

Listing 7: Modified Program P2_3 for Q2.18


1 % Insert program code here. Copy from m−file(s) and paste.

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

Hình 18: Linearity test results

The two sequences are

The system is

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

Listing 8: Program P2_5


1 % Insert program code here. Copy from m−file(s) and paste.

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:

Hình 19: Impulse response (41 samples)

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] = 0.9x[n] − 0.45x[n − 1] + 0.35x[n − 2] + 0.002x[n − 3]

are given below:


Laboratory Exercise 2 Page 10

Listing 9: Modified Program P2_5 for Q2.20


1 % Insert program code here. Copy from m−file(s) and paste.

The first 45 samples of the impulse response of this discrete-time system generated by running the modified
program is given below:

Hình 20: Impulse response (45 samples)

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:

Listing 10: Program using filter command


1 % Insert program code here. Copy from m−file(s) and paste.

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

Hình 21: Impulse response using filter command

Comparing the above response with that obtained in Question Q2.20 we conclude:

Q2.22 The MATLAB program to generate and plot the step response of a causal LTI system is indicated
below:

Listing 11: Step response program


1 % Insert program code here. Copy from m−file(s) and paste.

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

Hình 22: Step response

Project 2.6: Cascade of LTI Systems

A copy of Program P2_6 is given below:

Listing 12: Program P2_6


1 % Insert program code here. Copy from m−file(s) and paste.
Laboratory Exercise 2 Page 11

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:

Hình 23: Cascade system outputs

The relation between y[n] and y2 [n] is

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

Hình 24: Cascade system with sinusoidal input

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

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

Hình 25: Cascade system with non-zero initial conditions

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

Q2.26 The modified Program P2_6 with the two 2nd-order systems in reverse order and with zero initial
conditions is displayed below:

Listing 13: Modified Program P2_6 (reverse order)


1 % Insert program code here. Copy from m−file(s) and paste.

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

Hình 26: Reversed cascade system

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

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:

Hình 27: Reversed cascade with non-zero initial conditions


Laboratory Exercise 2 Page 12

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

Project 2.7: Convolution

A copy of Program P2_7 is reproduced below:

Listing 14: Program P2_7


1 % Insert program code here. Copy from m−file(s) and paste.

Answers:

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

Hình 28: Convolution results

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

The reason for using x1 [n] as the input, obtained by zero-padding x[n], for generating y1 [n] is:

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:

Listing 15: Modified Program P2_7 for Q2.29


1 % Insert program code here. Copy from m−file(s) and paste.

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

Hình 29: Modified convolution results

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

Project 2.8: Stability of LTI Systems

A copy of Program P2_8 is given below:


Laboratory Exercise 2 Page 13

Listing 16: Program P2_8


1 % Insert program code here. Copy from m−file(s) and paste.

Answers:

Q2.30 The purpose of the for command is

The purpose of the end command is

Q2.31 The purpose of the break command is

Q2.32 The discrete-time system of Program P2_8 is

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

Hình 30: Impulse response for stability analysis

The value of |h(K)| here is

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

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

From this value we can conclude that the system is

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

Listing 17: Modified Program P2_8 for Q2.33


1 % Insert program code here. Copy from m−file(s) and paste.

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

Hình 31: Modified system impulse response

The values of |h(K)| here are

From this value and the shape of the impulse response we can conclude that the system is
Laboratory Exercise 2 Page 14

Project 2.9: Illustration of the Filtering Concept

A copy of Program P2_9 is given below:

Listing 18: Program P2_9


1 % Insert program code here. Copy from m−file(s) and paste.

Answers:

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

Hình 32: Filtering demonstration

The filter with better characteristics for the suppression of the high frequency component of the input signal
x[n] is

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:

Listing 19: Modified Program P2_9 for Q2.35


1 % Insert program code here. Copy from m−file(s) and paste.

Hình 33: Filtering with swept frequency input

The filter with better characteristics for the suppression of the high frequency component of the input signal
x[n] is

You might also like