Bài 1
Bài 1
Section:T3-123
Laboratory Exercise 1
DISCRETE-TIME SIGNALS: TIME-DOMAIN REPRESENTATION
Q1.1 The unit sample sequence u[n] generated by running Program P1_1 is shown
below:
1
Unit Sample Sequence
1.2
0.8
Amplitude
0.6
0.4
0.2
0
-10 -5 0 5 10 15 20
Time index n
The purpose of title command is - Adds the specified title to the axes or chart
The purpose of xlabel command is - Adds text beside the X-axis on the current
axis.
The purpose of ylabel command is - Adds text beside the Y-axis on the current
axis.
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 by
running this program.
% Program P1_1
% Generation of a Unit Sample Sequence
clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
% Plot the unit sample sequence
stem(n-11,u);
xlabel('Time index n');ylabel('Amplitude');
2
title('Unit Sample Sequence');
axis([-10 20 0 1.2]);
0.8
Amplitude
0.6
0.4
0.2
0
-20 -15 -10 -5 0 5
Time index n
Q1.4 The modified Program P1_1 to generate a unit step sequence s[n] is given below
along with the sequence generated by running this program .
% Program P1_1
% Generation of a Unit Sample Sequence
clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
u2 = [zeros(1,10) ones(1,21)];
% Plot the unit sample sequence
subplot(211);
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 20 0 1.2]);
subplot(212);
stem(n,u2);
xlabel('Time index n');ylabel('Amplitude');
title('ham buoc');
3
Unit Sample Sequence
1
Amplitude
0.5
0
-10 -5 0 5 10 15 20
Time index n
ham buoc
1
Amplitude
0.5
0
-10 -5 0 5 10 15 20
Time index n
Q1.5 The modified Program P1_1 to generate a unit step sequence sd[n] with an ad-
vance of 7 samples is given below along with the sequence generated by running
this program.
% Program P1_1
% Generation of a Unit Sample Sequence
clf;
% Generate a vector from -10 to 20
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) 1 zeros(1,20)];
u2 = [zeros(1,10) ones(1,21)];
% Plot the unit sample sequence
subplot(211);
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 20 0 1.2]);
subplot(212);
stem(n+7,u2);
xlabel('Time index n');ylabel('Amplitude');
title('ham buoc');
4
Unit Sample Sequence
1
Amplitude
0.5
0
-10 -5 0 5 10 15 20
Time index n
ham buoc
0.8
Amplitude
0.6
0.4
0.2
-5 0 5 10 15
Time index n
% Program P1_2
% Generation of a complex exponential sequence
clf;
c = -(1/12)+(pi/6)*i;
K = 2;
n = 0:40;
x = K*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
xlabel('Time index n');ylabel('Amplitude');
title('Real part');
subplot(2,1,2);
stem(n,imag(x));
xlabel('Time index n');ylabel('Amplitude');
title('Imaginary part');
% Program P1_3
5
% Generation of a real exponential sequence
clf;
n = 0:35; a = 1.2; K = 0.2;
x = K*a.^n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
Real part
2
1
Amplitude
-1
-2
0 5 10 15 20 25 30 35 40
Time index n
Imaginary part
2
1
Amplitude
-1
0 5 10 15 20 25 30 35 40
Time index n
Q1.7 The parameter controlling the rate of growth or decay of this sequence is
c = -(1/12)+(pi/6)*i;
Q1.10 The purpose of the command subplot is - Create axes in tiled positions
6
120
100
80
Amplitude
60
40
20
0
0 5 10 15 20 25 30 35
Time index n
Q1.12 The parameter controlling the rate of growth or decay of this
sequence is a = 1.2
The matrix multiplies each other and .^ multiplies each element in the matrix
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:
7
20
18
16
14
12
Amplitude
10
0
0 5 10 15 20 25 30 35
Time index n
8
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 40 -2 2]);
grid;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;
Q1.17 The sinusoidal sequence generated by running Program P1_4 is displayed below .
Sinusoidal Sequence
2
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30 35 40
Time index n
A sequence with new frequency _0.3_ can be generated by the following command
line: f=0.3
9
The parameter controlling the amplitude of this sequence is -A=15
A sequence with new length _56____ can be generated by the following command
line:n=0
Q1.21 The purpose of axis command is - Control axis scaling and appearance.
The purpose of grid command is - to turn on the drawing of grid lines on the graph.
Q1.22 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 .
% Program P1_4
% Generation of a sinusoidal sequence
n = 0:40;
f = 0.9;
phase = 0;
A = 1.5;
arg = 2*pi*f*n - phase;
x = A*cos(arg);
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 40 -2 2]);
grid;
sum(x(1:10).*x(1:10))/10 ;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;
10
Sinusoidal Sequence
2
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30 35 40
Time index n
A comparison of this new sequence with the one generated in Question Q1.17
shows -
11
Sinusoidal Sequence
2
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30 35 40
Time index n
A comparison of this new sequence with the one generated in Question Q1.17
shows - 2 graphs are identical because f=1,1-1=01Hz
Q1.23 The sinusoidal sequence of length 50, frequency 0.08, amplitude 2.5, and phase
shift of 90 degrees generated by modifying Program P1_4 is displayed below .
Sinusoidal Sequence
2
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30 35 40
Time index n
12
The period of this sequence is – T=1/0,08=12.5s
Q1.24 By replacing the stem command in Program P1_4 with the plot command, the
plot obtained is as shown below:
Sinusoidal Sequence
2
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30 35 40
Time index n
The 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 straight line segments, which approximates the
graph of a continuous-time cosine signal.
Q1.25 By replacing the stem command in Program P1_4 with the stairs command the
plot obtained is as shown below:
13
Sinusoidal Sequence
2
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30 35 40
Time index n
The difference between the new plot and those generated in Questions Q1.17 and
Q1.24 is –
stairs command draws a stairstep graph and was generated in Q1.17 and the
“plot” command connects the points with straight line segments in Q1.24
Answers:
Q1.26 The MATLAB program to generate and display a random signal of length 100 with
elements uniformly distributed in the interval [–2, 2] is given below along with the
plot of the random sequence generated by running the program :
n = 0:99;
A = 2;
%rand('state',sum(100*clock)); % Obsolete syntax to "seed" the generator
rng('shuffle'); % new syntax to seed generator
%
% rand(1,100) is uniform in [0,1]
% rand(1,100)-0.5 is uniform in [-0.5,0.5]
% 4*(rand(1,100)-0.5) is uniform in [-2,2]
x = 2*A*(rand(1,length(n))-0.5);
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 100 -2 2]);
14
grid;
title('uniform Random Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 10 20 30 40 50 60 70 80 90 100
Time index n
Q1.27 The MATLAB program to generate and display a Gaussian random signal of length
75 with elements normally distributed with zero mean and a variance of 3 is given
below along with the plot of the random sequence generated by running the
program:
n = 0:74;
xmean = 0; % mean of x
xstd = sqrt(3); % standard deviation of x
rng('shuffle'); % new syntax to seed generator
% generate the sequence
x = xstd*randn(1,length(n)) + xmean;
% setup the graph and plot
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
xmax = max(abs(x));
Ylim = round(2*(xmax+0.5))/2;
axis([0 length(n) -Ylim Ylim]);
grid;
title('Gaussian Random Sequence');
xlabel('Time index n');
ylabel('Amplitude');
15
axis;
1
Amplitude
-1
-2
-3
-4
0 10 20 30 40 50 60 70
Time index n
Q1.28 The MATLAB program to generate and display five sample sequences of a random
sinusoidal signal of length 31
where the amplitude A and the phase are statistically independent random
variables with uniform probability distribution in the range 0 A 4 for the
amplitude and in the range 0 for the phase is given below. Also shown
are five sample sequences generated by running this program five different times .
% Program Q1_28
% Generates the "deterministic stochastic process"
n = 0:30;
f = 0.1;
phimax = 2*pi;
rng('shuffle'); % seed generator
A = -4+8*rand;
% NOTE: successive calls to rand without arguments
% return a random sequence of scalars. Since this
% random sequence is "white" (uncorrelated), it is
% not necessary to re-seed the generator for phi.
for trial=1:5
phi = phimax*rand;
16
% generate the sequence
arg = 2*pi*f*n + phi;
x = A*cos(arg);
% plot
figure(trial);
clf; % Clear any old graph
stem(n,x); % Plot the generated sequence
2
Amplitude
-2
-4
-6
0 5 10 15 20 25 30
Time index n
17
Sinusoidal Sequence with Random Amplitude and Phase
6
2
Amplitude
-2
-4
-6
0 5 10 15 20 25 30
Time index n
18
Sinusoidal Sequence with Random Amplitude and Phase
6
2
Amplitude
-2
-4
-6
0 5 10 15 20 25 30
Time index n
19
Sinusoidal Sequence with Random Amplitude and Phase
6
2
Amplitude
-2
-4
-6
0 5 10 15 20 25 30
Time index n
20
Sinusoidal Sequence with Random Amplitude and Phase
6
2
Amplitude
-2
-4
-6
0 5 10 15 20 25 30
Time index n
21
Q1.29 The signals generated by running Program P1_5 are displayed below :
d[n]
6
s[n]
x[n]
Amplitude
0
0 5 10 15 20 25 30 35 40 45 50
Time index n
8
y[n]
6 s[n]
Amplitude
0
0 5 10 15 20 25 30 35 40 45 50
Time index n
Q1.30 The uncorrupted signal s[n]is - product with linear decreasing time
The additive noise d[n]is - a random sequence uniformly distributed between -0.4
and +0.4
Q1.32 The relations between the signals x1, x2, and x3, and the signal x are . The
signal x1 is a delayed version of x, shifted one sample to the right with zero padding on
the left. The signal x2 is equal to x, with equal zero padding on both the left and right
to account for the extended length. Finally, x3 is a time advanced version of x, shifted
one sample to the left with zero padding on the right.
Q1.33 The purpose of the legend command is - creates a legend with descriptive labels
for each plotted data series.
22
A copy of Program P1_6 is given below.
% Program P1_6
% Generation of amplitude modulated sequence
clf;
n = 0:100;
m = 0.4;fH = 0.1; fL = 0.01;
xH = sin(2*pi*fH*n);
xL = sin(2*pi*fL*n);
y = (1+m*xL).*xH;
stem(n,y);grid;
xlabel('Time index n');ylabel('Amplitude');
Q1.34 The amplitude modulated signals y[n] generated by running Program P1_6 for
various values of the frequencies of the carrier signal xH[n] and the modulating
signal xL[n], and various values of the modulation index m are shown below:
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 10 20 30 40 50 60 70 80 90 100
Time index n
23
Q1.35 The difference between the arithmetic operators * and .* is - * is product
.% Program P1_7
% Generation of a swept frequency sinusoidal sequence
n = 0:100;
a = pi/2/100;
b = 0;
arg = a*n.*n + b*n;
x = cos(arg);
clf;
stem(n, x);
axis([0,100,-1.5,1.5]);
title('Swept-Frequency Sinusoidal Signal');
xlabel('Time index n');
ylabel('Amplitude');
grid; axis;
0.5
Amplitude
-0.5
-1
-1.5
0 10 20 30 40 50 60 70 80 90 100
Time index n
24
Q1.37 The minimum and maximum frequencies of this signal are - 0 and 0.5
Q1.38 The Program 1_7 modified to generate a swept sinusoidal signal with a minimum
frequency of 0.1 and a maximum frequency of 0.3 is given below :
% Program P1_7_2
% Generation of a swept frequency sinusoidal sequence
n = 0:100;
a = pi/500;
b = pi/5;
arg = a*n.*n + b*n;
x = cos(arg);
clf;
stem(n, x);
axis([0,100,-1.5,1.5]);
title('Swept-Frequency Sinusoidal Signal');
xlabel('Time index n');
ylabel('Amplitude');
grid; axis;
0.5
Amplitude
-0.5
-1
-1.5
0 10 20 30 40 50 60 70 80 90 100
Time index n
25
Q1.39 The information displayed in the command window as a result of the who
command is - who lists the variables in the current workspace.
Q1.40 The information displayed in the command window as a result of the whos
command is – whos List current variables, long form.
Answer:
Q1.41 MATLAB programs to generate the square-wave and the sawtooth wave sequences
of the type shown in Figures 1.1 and 1.2 are given below along with the sequences
generated by running these programs :
% Program P1_41
% Generation of a sinusoidal sequence
n = 0:40;
f = 0.1;
phase = 0;
A = 1.5;
arg = 2*pi*f*n - phase;
x = A*square(arg);
x2=A*sawtooth(arg);
clf; % Clear old graph
subplot(211);
stem(n,x); % Plot the generated sequence
axis([0 40 -2 2]);
grid;
title('Square Sequence 1.1');
xlabel('Time index n');
ylabel('Amplitude');
subplot(212);
stem(n,x2); % Plot the generated sequence
axis([0 40 -2 2]);
grid;
title('Sawtooth Sequence 1.2');
xlabel('Time index n');
ylabel('Amplitude');
axis;
26
Square Sequence 1.1
2
Amplitude 1
-1
-2
0 5 10 15 20 25 30 35 40
Time index n
Sawtooth Sequence 1.2
2
1
Amplitude
-1
-2
0 5 10 15 20 25 30 35 40
Time index n
Date: Signature:
27