Lab Ex 1
Lab Ex 1
Section:
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:
U
nitS
amp
leS
equ
ence
0
.8
Amplitude
0
.6
0
.4
0
.2
0
-1
0 -5 0 5 1
0 1
5 2
0
T
imein
dexn
1
Q1.2 The purpose of clf command is used to clear current figure.
The purpose of axis command is used to control axis scaling and appearance.
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,20) 1 zeros(1,10)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 20 0 1.2]);
2
Unit Sample Sequence
0.8
Amplitude
0.6
0.4
0.2
0
-10 -5 0 5 10 15 20
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 Unit
20 Step Sequence
n = -10:20;
% Generate the unit sample sequence
u = [zeros(1,10) ones(1,21)];
% Plot the unit sample sequence
stem(n,u);
1
xlabel('Time index n');ylabel('Amplitude');
title('Unit Step Sequence');
axis([-10 20 0 1.2]);
0.8
Amplitude
0.6
0.4
0.2
0
3
-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 advance 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,3) ones(1,28)];
% Plot the unit sample sequence
stem(n,u);
xlabel('Time index n');ylabel('Amplitude');
title('Unit Step Sequence');
axis([-10 20 0 1.2]);
4
Unit StepSequence
0.8
Amplitude
0.6
0.4
0.2
0
-10 -5 0 5 10 15 20
Timeindex n
Q1.6 The complex-valued exponential sequence generated by running Program P1_2 is shown
below:
Q1.7 The parameter controlling the rate of growth or decay of this sequence is n.pi/6.
5
The parameter controlling the amplitude of this sequence is K.e-n/12
Q1.8 The result of changing the parameter c to (1/12)+(pi/6)*i is the amplitude of real(x)
and img(x) will increase with time by the parameter controlling the amplitude, K.en/12
50
40
40
30
30
20
20
Amplitude
Amplitude
10 10
0
0
-10
-10
-20
-20
-30
-30 -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
Q1.9 The purpose of the operator real is used to get the real-value of a complex number.
The purpose of the operator imag is used to get the imaginary-value of a complex
number.
Q1.10 The purpose of the command subplot is used to create axes in tiled positions.
Q1.11 The real-valued exponential sequence generated by running Program P1_3 is shown
below:
120
100
80
Amplitude
60
40
20
0
0 5 10 15 20 25 30 35
Time index n
6
Q1.12 The parameter controlling the rate of growth or decay of this sequence is n
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
20
18
16
14
12
Amplitude 10
0
0 5 10 15 20 25 30 35 40
Time index n
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.5673e+004 and 2.1042e+003.
Answers:
Q1.17 The sinusoidal sequence generated by running Program P1_4 is displayed below.
8
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.05 Hz can be generated by the following command
line:f=0.05.
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
9
Q1.19 The length of this sequence is 41 mẫu hay 2 chu kì.
A sequence with new length 51 can be generated by the following command line:
n=0:50.
Sinusoidal Sequence
2
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30 35 40 45 50
Time index n
Q1.21 The purpose of axis command is used to sets scaling for the x- and y-axes
on the current plot.
The purpose of grid command is used to set the XGrid, YGrid, and ZGrid properties of
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');
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
that they are alike.
A sinusoidal sequence of frequency 1.1 generated by modifying Program P1_4 is 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
A comparison of this new sequence with the one generated in Question Q1.17 shows that
they are alike.
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.
11
Sinusoidal Sequence
4
1
Amplitude
-1
-2
-3
-4
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:
Sinusoidal Sequence
4
1
Amplitude
-1
-2
-3
-4
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 the signal
of new plot is a continuous signal while the signal of question q1.17 is a
discrete-time signal in the time domain.
Q1.25 By replacing the stem command in Program P1_4 with the stairs command the plot
obtained is as shown below:
12
Sinusoidal Sequence
4
1
Amplitude
-1
-2
-3
-4
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 the figure in Q1.24 is a stairstep graph of the elements in vector Y at the
locations specified in X.
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:
% Program P1_4
% Generation of a random signal of length 100 with elements uniformly distributed in the
interval [–2, 2]
x = rand(1,100);
n=-2:0.04:1.96;
clf;
stem(n,x);
13
axis([-2 2 -1 1]);
grid;
ylabel('Amplitude');
axis
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
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:
14
axis([0 75 -8 8]);
grid;
title(' Gaussian random signal of length 75 ');
xlabel('Time index n');
ylabel('Amplitude');
axis;
2
Amplitude
-2
-4
-6
-8
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 si-
nusoidal signal of length 31
{X[n]} = {Acos(ωon + φ)}
where the amplitude A and the phase φ are statistically independent on random variables
with uniform probability distribution in the range 0 ≤ A ≤ 4 for the amplitude and
in the range 0 ≤ φ ≤ 2π for the phase is given below. Also shown are five sample
sequences generated by running this program five different times.
% Program P1_4
% Generation of a sinusoidal sequence
n = 0:30;
f = 0.1;
phase = 2*pi*rand(1,1);
15
A = 4*rand(1,1);
arg = 2*pi*f*n - phase;
x = A*cos(arg);
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 30 -4 4]);
grid;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;
Sinusoidal Sequence
4
1
Amplitude
-1
-2
-3
-4
0 5 10 15 20 25 30
Time index n
16
plot(m,d','r-',m,s,'g--',m,x,'b-.');
xlabel('Time index n');ylabel('Amplitude');
legend('d[n] ','s[n] ','x[n] ');
x1 = [0 0 x];x2 = [0 x 0];x3 = [x 0 0];
y = (x1 + x2 + x3)/3;
subplot(2,1,2);
plot(m,y(2:R+1),'r-',m,s,'g--');
legend( 'y[n] ','s[n] ');
xlabel('Time index n');ylabel('Amplitude');
Answers:
Q1.29 The signals generated by running Program P1_5 are displayed below:
10
d[n]
s[n]
5
Amplitude
x[n]
-5
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
The additive noise d[n]is sequences of a random where the amplitude are statistically
independent on random variables with uniform probability distribution in the range
-0.4 0.4 for the amplitude.
17
Q1.31 The statement x = s + d CAN / CANNOT be used to generate the noise corrupted
signal because matrix dimensions must be agreed.
Q1.32 The relations between the signals x1, x2, and x3, and the signal x are -
Q1.33 The purpose of the legend command used to display a table on a map, chart,
listing to explaining the symbols used.
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:
18
1.5
0.5
Amplitude
-0.5
-1
-1.5
0 10 20 30 40 50 60 70 80 90 100
Time index n
Q1.35 The difference between the arithmetic operators * and .* is with operator .* every
Answers:
19
Q1.36 The swept-frequency sinusoidal sequence x[n] generated by running Program P1_7 is
displayed below.
0.5
Amplitude
-0.5
-1
-1.5
0 10 20 30 40 50 60 70 80 90 100
Time index n
Q1.37 The minimum and maximum frequencies of this signal are 0 Hz and 25 Hz.
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/200;
b = 0;
arg = a*n.*n + b*n+0.2*pi;
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;
20
1.3 WORKSPACE INFORMATION
Q1.39 The information displayed in the command window as a result of the who command is
used to list the variables in the current workspace.
Q1.40 The information displayed in the command window as a result of the whos command
is used to list all the variables in the current workspace, together with
information about their size, bytes, class, etc.
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:
n=0:99;
y =3*square(2*pi*0.1*n,60);
stem(n,y);
xlabel('Time index n');ylabel('Amplitude');
title('Square wave sequences');
axis([0 100 -4 4]);
1
Amplitude
-1
-2
-3
-4
0 10 20 30 40 50 60 70 80 90 100
Time index n
21
title('Square wave sequences');
axis([0 100 -4 4]);
1
Amplitude
-1
-2
-3
-4
0 10 20 30 40 50 60 70 80 90 100
Time index n
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30
Time index n
22
Sawtooth wave sequences
2
1.5
0.5
Amplitude
-0.5
-1
-1.5
-2
0 5 10 15 20 25 30
Time index n
Date: Signature:
Date: Signature:
23