LABEX1 (1)
LABEX1 (1)
Student id : 23161307
Section:
Laboratory Exercise 1
DISCRETE-TIME SIGNALS: TIME-DOMAIN REPRESENTATION
Answers:
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 25
Time index n
The purpose of axis command is - axis Control axis scaling and appearance.
axis([XMIN XMAX YMIN YMAX]) sets scaling for the x- and y-axes
the gca command. Reissuing the title command causes the new title to
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:27;
% Generate the unit sample sequence
u = [zeros(1,21) ones(1,17)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 27 0 1.2]);
grid;
2
Unit Sample Sequence
1.2
0.8
Amplitude
0.6
0.4
0.2
0
-10 -5 0 5 10 15 20 25
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:27;
% Generate the unit sample sequence
u = [zeros(1,10) ones(1,28)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 27 0 1.2]);
grid;
0.8
Amplitude
0.6
0.4
0.2
0
-10 -5 0 5 10 15 20 25
Time index n
3
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:27;
% Generate the unit sample sequence
u = [zeros(1,17) ones(1,21)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 27 0 1.2]);
grid;
0.8
Amplitude
0.6
0.4
0.2
0
-10 -5 0 5 10 15 20 25
Time index n
4
stem(n,imag(x));
xlabel('Time index n');ylabel('Amplitude');
title('Imaginary part');
% Program P1_3
% 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');
Answers:
1
Amplitude
-1
-2
0 5 10 15 20 25 30 35 40
Time index n
Imaginary part
2
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 -
The parameter controlling the rate of growth or decay of this sequence is the real part
of the constant c, which is -1/12. It causes the amplitude of the sequence to decay
exponentially at a rate determined by this value."
5
Real part
40
20
Amplitude 0
-20
0 5 10 15 20 25 30 35 40
Time index n
Imaginary part
50
Amplitude
-50
0 5 10 15 20 25 30 35 40
Time index n
Q1.9 The purpose of the operator real is - "The purpose of the operator real is to
extract the real part of a complex number or a complex sequence, discarding the
imaginary part, for use in computation or plotting."
The purpose of the operator imag is - "The purpose of the operator imag is to
extract the imaginary part of a complex number or a complex sequence, discarding the
real part, for use in computation or plotting."
Q1.10 The purpose of the command subplot is - Create axes in tiled positions
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 -n =
0:35;
The parameter controlling the amplitude of this sequence is - K = 0.2;
6
Q1.13 The difference between the arithmetic operators ^ and .^ is -
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:
20
18
16
14
12
Amplitude
10
0
0 5 10 15 20 25 30 35
Time index n
7
106
18
16
14
12
Amplitude
10
0
0 10 20 30 40 50 60 70 80 90 100
Time index n
Answers:
8
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
Q1.18 The frequency of this sequence is - f = 0.1
A sequence with new frequency _____ can be generated by the following command
line: f=[new frequency];
The parameter controlling the phase of this sequence is - phase = 0;
The parameter controlling the amplitude of this sequence is - A = 1.5;
>> P1_4
Q1.21 The purpose of axis command is - Control axis scaling and appearance.
axis([XMIN XMAX YMIN YMAX]) sets scaling for the x- and y-axes
on the current plot.
The purpose of grid command is -
Grid lines.
9
grid OFF removes major and minor grid lines from the current axes.
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;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
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 - same
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 - same
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
Q1.24 By replacing the stem command in Program P1_4 with the plot command, the
plot obtained is as shown below:
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
The difference between the new plot and the one generated in Question Q1.17 is -
it is continuous
Q1.25 By replacing the stem command in Program P1_4 with the stairs 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 those generated in Questions Q1.17 and
Q1.24 is -
"By replacing the stem command in Program P1_4 with the stairs command,
12
Project 1.4 Random signals
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 :
clf;
n=0:99;
x = -2 + 4*rand (1,length(n));
stem(n, x);
xlabel("truc x");
ylabel("truc y");
title("Random signals")
grid on;
axis([0 99 -3 3]);
Random signals
3
1
truc y
-1
-2
-3
0 10 20 30 40 50 60 70 80 90
truc x
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;
gttb=0;
phuong_sai=3;
x= gttb+sqrt(phuong_sai)*randn(1,length(n));
plot(n,x);
grid on;
title("Gaussian Random Signal (Mean = 0, Variance = 3)")
13
Gaussian Random Signal (Mean = 0, Variance = 3)
4
-1
-2
-3
-4
-5
-6
0 10 20 30 40 50 60 70 80
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 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 .
clf;
n=0:30;
omega=0.2;
for i=1:5
phi=0+2*pi*rand;
a=4*rand;
x=a*cos(omega*n+phi);
subplot(5,1,i);
stem(n, x);
grid on;
title(['bieu do:',num2str(i),',a=',num2str(a),',\phi',num2str(phi)]);
end
14
bieu do:1,a=3.8906, 3.2964
5
0
-5
0 5 10 15 20 25 30
bieu do:2,a=1.2474, 4.4636
1
0
-1
0 5 10 15 20 25 30
bieu do:3,a=3.4014, 1.8313
5
0
-5
0 5 10 15 20 25 30
bieu do:4,a=2.5571, 5.728
2
0
-2
0 5 10 15 20 25 30
bieu do:5,a=0.35466, 1.6045
0.5
0
-0.5
0 5 10 15 20 25 30
Answers:
15
Q1.29 The signals generated by running Program P1_5 are displayed below :
8
d[n]
s[n]
6
x[n]
Amplitude
4
-2
0 5 10 15 20 25 30 35 40 45 50
Time index n
8
y[n]
s[n]
6
Amplitude
0
0 5 10 15 20 25 30 35 40 45 50
Time index n
Q1.32 The relations between the signals x1, x2, and x3, and the signal x are -
The relationships between the signals x1, x2, x3, and the signal x are:
x1 = [0 0 x]: The signal x with two zeros added at the beginning. This is
equivalent to shifting x to the right by two steps (a delay).
x2 = [0 x 0]: The signal x with one zero added at the beginning and one zero at
the end. This is equivalent to shifting x to the right by one step.
x3 = [x 0 0]: The signal x with two zeros added at the end, keeping the beginning
of x unchanged.
These are time-shifted versions of x, used to compute a moving average in the
next step of the code.
16
Project 1.6 Generation of Complex Signals
Answers:
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
0 10 20 30 40 50 60 70 80 90 100
Time index n
17
· The * operator performs matrix multiplication, following the rules of linear algebra
where the number of columns in the first matrix must equal the number of rows in the
second matrix.
· The .* operator performs element-wise multiplication, multiplying corresponding
elements of two arrays, which must have the same size or one must be a scalar."
Answers:
0.5
Amplitude
-0.5
-1
-1.5
0 10 20 30 40 50 60 70 80 90 100
Time index n
18
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
% Generation of a swept frequency sinusoidal sequence
n = 0:100;
a = pi/500;
b = 0.2*pi;
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;
Q1.39 The information displayed in the command window as a result of the who
command is -
a ans arg b n x
Q1.40 The information displayed in the command window as a result of the whos
command is -
>> whos
a 1x1 8 double
b 1x1 8 double
19
Project 1.8 Squarewave and Sawtooth Signals
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_1
% Generation of a Unit Sample Sequence
clf;
% Generate a vector from -10 to 20
n = -10:27;
% Generate the unit sample sequence
u = [zeros(1,10) ones(1,28)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 27 0 1.2]);
grid;
Unit Sample Sequence
1.2
0.8
Amplitude
0.6
0.4
0.2
0
-10 -5 0 5 10 15 20 25
Time index n
% Program P1_2
% Generation of a complex exponential sequence
clf;
c = -(1/12)+(pi/6)*i;
K = 2;
n = 0:40;
20
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');
Real part
2
1
Amplitude
-1
-2
0 5 10 15 20 25 30 35 40
Time index n
Imaginary part
2
Amplitude
-1
0 5 10 15 20 25 30 35 40
Time index n
21