BÁO CÁO CUỐI KÌ THÍ NGHIỆM DSP Laboratory Exercise 1 DISCRETE TIME SIGNALS TIME DOMAIN REPRESENTATION 1 1 GENERATION OF SEQUENCES Project 1 1 Unit sample and unit step sequences A copy of Program P1 1 is given below % Program P1 1 clf; n = 10 20; u = zeros(1,10) 1 zeros(1,20); stem(n,u); xlabel(Time index n);ylabel(Amplitude); title(Unit Sample Sequence); axis( 10 20 0 1 2); Q1 1 The unit sample sequence un generated by running Program P1 1 is shown below Q1 2 The purpose of clf comm.
Trang 1BÁO CÁO CUỐI KÌ THÍ NGHIỆM DSP
Laboratory Exercise 1 DISCRETE-TIME SIGNALS: TIME-DOMAIN REPRESENTATION
1.1 GENERATION OF SEQUENCES
Project 1.1 Unit sample and unit step sequences
A copy of Program P1_1 is given below
Trang 2Q1.2 The purpose of clf command is – clear the current figure
The purpose of axis command is – control axis scaling and appearance
The purpose of title command is – add a title to a graph or an axis and specify text properties
The purpose of xlabel command is – add a label to the x-axis and
specify text properties
The purpose of ylabel command is – add a label to the y-axis and specify the text properties
Q1.3 The modified Program P1_1 to generate a delayed unit sample sequence ud[n]
with a delay of 11 samples is given below along with the sequence generated byrunning this program
Trang 3Q1.4 The modified Program P1_1 to generate a unit step sequence s[n] is
given below along with the sequence generated by running thisprogram
Q1.5 The modified Program P1_1 to generate a unit step sequence sd[n]
with an advance of 7 samples is given below along with thesequence generated by running this program
Trang 4title('ADVANCED Unit Step
Sequence'); axis([-10 20 0 1.2]);
Project 1.2 Exponential signals
A copy of Programs P1_2 and P1_3 are given below
% Program P1_2
4 4
Trang 5Q1.6 The complex-valued exponential sequence generated by running
Program P1_2 is shown below:
Trang 6Q1.7 The parameter controlling the rate of growth or decay of this sequence is – the real part of c
The parameter controlling the amplitude of this sequence is - K
Q1.8 The result of changing the parameter c to (1/12)+(pi/6)*i is – since exp(-1/12) is
less than one and exp(1/12) is greater than one, this change means that theenvelope of the signal will grow with n instead of decay with n
6 6
Trang 7Q1.9 The purpose of the operator real is – to extract the real part of a Matlab vector
The purpose of the operator imag is – to extract the imaginary part of a Matlab vector
Q1.10 The purpose of the command subplot is – to plot more than one graph in the same
Matlab figure
Q1.11 The real-valued exponential sequence generated by running Program
P1_3 is shown below:
Q1.12 The parameter controlling the rate of growth or decay of this sequence is - a
The parameter controlling the amplitude of this sequence is - K
Q1.13 The difference between the arithmetic operators ^ and ^ is – “^” raises a squarematrix to
a power using matrix multiplication “.^” raises the elements of a
matrix or vector to a power; this is a “pointwise” operation
Q1.14 The sequence generated by running Program P1_3 with the
parameter a changed to 0.9 and the parameter K changed to 20 is
shown below:
Trang 8Q1.15 The length of this sequence is - 36
It is controlled by the following MATLAB command line: n = 0:35;
It can be changed to generate sequences with different lengths as follows (give anexample command line and the corresponding length): n = 0:99; makes the length
100
Q1.16 The energies of the real-valued exponential sequences x[n]generated in Q1.11
and Q1.14 and computed using the command sum are - 4.5673*e+004 and2.1042*e+003
8 8
Trang 9Project 1.3 Sinusoidal sequences
A copy of Program P1_4 is given below
Trang 10Q1.18 The frequency of this sequence is - f = 0.1 cycles/sample
It is controlled by the following MATLAB command line: f = 0.1;
A sequence with new frequency 0.2 can be generated by the following command line:
f = 0.2;
The parameter controlling the phase of this sequence is - phase
10 10
Trang 11The parameter controlling the amplitude of this sequence is - A
The period of this sequence is - 2π/ω = 1/f = 10
Q1.1
9
The length of this sequence is - 41
It is controlled by the following MATLAB command line: n = 0:40;
A sequence with new length 81_ can be generated by the following command line:
2 The modified Program P1_4 to generate a sinusoidal sequence of frequency 0.9 is
given below along with the sequence generated by running it
Trang 12A comparison of this new sequence with the one generated in Question Q1.17 shows - the
two graphs are identical This is because, in the modified program,
we have ω = 0.9*2π This generates the same graph as a cosine
with angular frequency ω - 2π = −0.1*2π Because cosine is an
even function, this is the same as a cosine with angular frequency
+0.1*2π, which was the value used in P1_4.m in Q1.17
12 12
Trang 13In terms of Hertzian frequency, we have for P1_4.m in Q1.17 that f
= 0.1 Hz/sample For the modified program in Q1.22, we have f =0.9 Hz/sample, which generates the same graph as f = 0.9 – 1 =
−0.1 Again because cosine is even, this makes a graph that isidentical to the one we got in Q1.17 with f = +0.1 Hz/sample
A sinusoidal sequence of frequency 1.1 generated by modifying ProgramP1_4 is shown below
A comparison of this new sequence with the one generated in Question
Q1.17 shows - the graph here is again identical to the one inQ1.17 This is because a cosine of frequency f = 1.1 Hz/sample isidentical to one with frequency f = 1.1 – 1 = 0.1 Hz/sample, whichwas the frequency used in Q1.17
Q1.23 The sinusoidal sequence of length 50, frequency 0.08, amplitude 2.5,
and phase shift of 90 degrees generated by modifying ProgramP1_4 is displayed below
NOTE: for this program, it is necessary to convert the phase of 90 deg to
radians and account for the minus sign that appears in thestatement “arg = 2*pi*f*n - phase;” as opposed to the plus signshown in eq (1.12) of the lab manual The correct statement to
Trang 14generate the phase is “phase = -90/(2*pi);” It is also necessary tomodify the axis command to account for the new length andamplitude of the signal The correct axis statement is “axis([0 50-3 3]);”
The period of this sequence is - 2π/ω = 1/f = 1/0.08 = 1/(8/100) = 100/8 =
25/2 Therefore, the fundamental period is 25 and the graph hasthe “appearance” of going through 2 cycles of a cosine waveformduring each period
Q1.24 By replacing the stem command in Program P1_4 with the plot
command, the plot obtained is as shown below:
14 14
Trang 15The difference between the new plot and the one generated in Question
Q1.17 is – instead of drawing stems from the x-axis to the points
on the curve, the “plot” command connects the points with straightline segments, which approximates the graph of a continuous-timecosine signal
Q1.25 By replacing the stem command in Program P1_4 with the stairs
command the plot obtained is as shown below:
Trang 16The difference between the new plot and those generated in Questions
Q1.17 and Q1.24 is – the “stairs” command produces a stairstepplot as opposed to the stem graph that was generated in Q1.17 andthe straight-line interpolation plot that was generated in Q1.24
16 16
Trang 17Laboratory 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:
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;
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
Trang 18Q2.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 shownbelow:
Note: the code is not required; however, it is included here to demonstrate a tricky way
of making the modification to P2_1
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]);
18 18
Trang 19xlabel('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;
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
Trang 21From these plots we make the following observations – with M=4, this filter performs more smoothing than in the case M=2 Both s1 and s2 are high frequency in this case, and they are both substantially attenuated in the output.
Trang 22Q2.4 The required modifications to Program P2_1 by changing the input sequence to a
sweptfrequency sinusoidal signal (length 101, minimum frequency 0, and amaximum frequency 0.5) as the input signal (see Program P1_7) are listedbelow:
xlabel('Time index n'); ylabel('Amplitude');
title('Input Signal'); subplot(2,1,2); plot(n, y);
axis([0, 100, -1.5, 1.5]);
xlabel('Time index n'); ylabel('Amplitude');
title('Output Signal'); axis;
The output signal generated by running this program is plotted below
Project 2.2 (Optional) A Simple Nonlinear Discrete-Time System
A copy of Program P2_2 is given below:
22 22
Trang 230 20 40 60 80 100 120 140 160 180 200 0
0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
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: f=0.05, f=0.1, f=0.25
The output signals generated for each of the above input signals are displayed below:
Trang 24Q2.6 The output signal generated by using sinusoidal signals of the form x[n] = cos(won)
+ k as the input signal is shown below for the following values of wo and k -
wo = 0.2pi (f=0.1); K = 0.5
Project 2.3 Linear and Nonlinear Systems
A copy of Program P2_3 is given below:
Trang 25title('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 thedifference between the two signals:
The two sequences are – the same up to numerical roundoff
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 inputfrequencies:
Trang 27Based 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 -
Based on these plots we can conclude that the system with nonzero initialconditions is – Nonlinear
Trang 28Q2.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 followingthree different sets of input frequencies:
Trang 29Based on these plots we can conclude that the system with nonzero initial conditions and
different weights is – Nonlinear
Q2.11 Program P2_3 was modified to simulate the system:
y2[n]
10
yt[n]
Trang 3050
Trang 31Project 2.4 Time-invariant and Time-varying Systems
A copy of Program P2_4 is given below:
xlabel('Time index n'); ylabel('Amplitude');
title('Difference Signal'); grid;
Trang 32Answers:
Q2.12 The output sequences y[n] and yd[n] generated by
running Program P2_4 are shown below -
These two sequences are related as follows – y[n-10] = yd[n]
The system is – Time Invariant
Q2.13 The output sequences y[n] and yd[n] generated by running Program P2_4 for the
following values of the delay variable D – 2; 6; 8
are shown below -
32 32
Trang 33In each case, these two sequences are related as follows – y[n-D] = yd[n]
Trang 34The system is – Time Invariant
Q2.14 The output sequences y[n] and yd[n] generated by running Program P2_4 for the
following values of the input frequencies –
1 f1=0.05; f2=0.40;
2 f1=0.10; f2=0.25;
3 f1=0.15; f2=0.20; are shown below –
In each case, these two sequences are related as follows – y[n-10] = yd[n].
34 34
Trang 35The system is – Time Invariant
Q2.15 These two sequences are related as follows – yd[n] is NOT equal to the shift of
y[n]
The system is – Time Varying
Q2.16 The output sequences y[n] and yd[n] generated by running Program P2_4 for
non-zero initial conditions and following values of the input frequencies –
The system is – Time Varying
Q2.17 The modified Program 2_4 simulating the system
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;
Trang 36The system is – Time Varying
Q2.18 (optional) The modified Program P2_3 to test the linearity of the system of (2.16)
Trang 37title('Output Due to Weighted Input: a \cdot x_{1}[n] + b \cdot x_{2}
The two sequences are – The same up to numerical roundoff
The system is – Linear
Trang 382.5 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:
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:
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]
38 38
Trang 39= 0.9x[n] – 0.45x[n-1] + 0.35x[n-2] + 0.002x[n-3] are given below:
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:
Trang 40xlabel('Time index n'); ylabel('Amplitude'); title('Impulse
Q2.22 The MATLAB program to generate and plot the step response of a causal LTI
system is indicated below:
Trang 41Project 2.6 Cascade of LTI Systems
A copy of Program P2_6 is given below:
% Program P2_6 %
clf;
Trang 42title('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;
Q2.23 The output sequences y[n], y2[n], and the difference signal d[n] generated by running
Program P2_6 are indicated below:
42 42
Trang 43The relation between y[n]and y2[n] is – They are the SAME up to numerical roundoff
Trang 44Q2.24 The sequences generated by running Program P2_6 with the input changed to a
sinusoidal sequence are as follows:
The relation between y[n] and y2[n] in this case is – The are the same up to numerical
roundoff
Q2.25 The sequences generated by running Program P2_6 with non-zero initial
condition vectors are now as given below:
The relation between y[n]and y2[n] in this case is – They are NOT the same
Q2.26 The modified Program P2_6 with the two 2nd-order systems in reverse order and
with zero initial conditions is displayed below: