LABEX1
LABEX1
Section:
Laboratory Exercise 1
DISCRETE-TIME SIGNALS: TIME-DOMAIN REPRESENTATION
< Insert program code here. Copy from m-file(s) and paste. >
n=-10:20;
u = [zeros(1,10) 1 zeros(1,20)];
stem(n,u);
xlabel('Time index n');
ylabel('Amplitude');
tittle('Unit Sample sequence');
axis([-10 20 0 1.2]);
Answers:
Q1.1 The unit sample sequence u[n] generated by running Program P1_1 is shown
below:
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
1
Q1.2 The purpose of clf command is – delete image graph recently
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.
< Insert program code here. Copy from m-file(s) and paste. >
n=-10:20;
u = [zeros(1,21) 1 zeros(1,9)];
stem(n,u);
axis([-10 20 0 1.5]);
xlabel('Time index n');
ylabel('Amplitude');
title('Unit Sample sequence');
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
2
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 .
< Insert program code here. Copy from m-file(s) and paste. >
n=-10:20;
u = [zeros(1,10) ones(1,21)];
stem(n,u);
axis([-10 20 0 1.5]);
xlabel('Time index n');
ylabel('Amplitude');
title('Unit Sample sequence');
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
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.
< Insert program code here. Copy from m-file(s) and paste. >
n=-10:20;
u = [zeros(1,3) ones(1,28)];
stem(n,u);
axis([-10 20 0 1.5]);
xlabel('Time index n');
ylabel('Amplitude');
title('Unit Sample sequence');
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
4
Project 1.2 Exponential signals
P1_2: < Insert program code here. Copy from m-file(s) and paste. >
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');
P1_3:
clf;
n = 0:35; a = 1.2; K = 0.2;
x = K*a.^n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
5
Answers:
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
Q1.7 The parameter controlling the rate of growth or decay of this sequence is - n
= 0:40;
6
Q1.9 The purpose of the operator real is - calculate the real part of the calculation
The purpose of the operator imag is – calculate the imag part of the calculation
Q1.10 The purpose of the command subplot is - split display area to row and column ,
select display area
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
7
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 - ^square 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:
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
< Insert program code here. Copy from m-file(s) and paste. >
n = 0:40;
8
f = 0.1;
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');
axis;
Answers:
Q1.17 The sinusoidal sequence generated by running Program P1_4 is displayed below .
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
9
A sequence with new frequency _____ can be generated by the following command
line: f=0.2;
A sequence with new length _____ can be generated by the following command
line:
n = 0:80;
The purpose of grid command is – turn on/ turn off a net of 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 .
< Insert program code here. Copy from m-file(s) and paste. >
% 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);
%x = A*square(arg,30); %square(T,duty) duty de chi so phan tu phia tren
trong 1 chu ky
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;
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
10
A comparison of this new sequence with the one generated in Question
Q1.17 shows - In 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 is
identical to the one we got in Q1.17 with f = +0.1 Hz/sample .
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
11
A comparison of this new sequence with the one generated in Question Q1.17
shows - the graph here is again identical to the one in Q1.17. This is because a
cosine of frequency f = 1.1 Hz/sample is identical to one with frequency f = 1.1 – 1
= 0.1 Hz/sample, which was 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 Program P1_4 is displayed below .
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
12
The period of this sequence is – 12.5
Q1.24 By replacing the stem command in Program P1_4 with the plot command, the
plot obtained is as shown below:
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
13
The difference between the new plot and the one generated in Question
Q1.17 is - the new image has a continuous signal, while the old image has a discrete
signal
Q1.25 By replacing the stem command in Program P1_4 with the stairs command the
plot obtained is as shown below:
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
14
The difference between the new plot and those generated in Questions
Q1.17 and Q1.24 is - The points are extended until the next time
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 :
< Insert program code here. Copy from m-file(s) and paste. >
% Program Q1_26
n = 0:99;
A = 2;
% 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,100)-0.5);
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
15
axis([0 100 -2.5 2.5 ]);
grid;
title('uniform Random Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
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:
< Insert program code here. Copy from m-file(s) and paste. >
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% Plot the generated
stem(n,x); sequence
16
xmax = max(abs(x));
Ylim = round(2*(xmax+0.5))/2;
grid;
ylabel('Amplitude');
axis;
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
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 .
< Insert program code here. Copy from m-file(s) and paste. >
n = 0:30;
f = 0.1;
17
Amax = 4;
phimax = 2*pi;
rng('shuffle'); % seed generator
A = Amax*rand;
for trial=1:5
phi = phimax*rand;
x = A*cos(arg);
% plot figure(trial);
clf; % Clear any old graph% Plot the generated
stem(n,x); sequence
Ylim = round(2*(Amax+0.5))/2;
< Insert MATLAB figure(s) here. Copy from figure window(s) and paste. >
18
1.2 SIMPLE OPERATIONS ON SEQUENCES
< Insert program code here. Copy from m-file(s) and paste. >
% Program P1_5
% Signal Smoothing by Averaging
clf;
R = 51;
d = 0.8*(rand(R,1) - 0.5); % Generate random noise
m = 0:R-1;
s = 2*m.*(0.9.^m); % Generate uncorrupted signal
x = s + d'; % Generate noise corrupted signal
subplot(2,1,1);
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 :
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
19
Q1.30 The uncorrupted signal s[n]is - s = 2*m.*(0.9.^m);
The additive noise d[n]is - d = 0.8*(rand(R,1) - 0.5);
Q1.32 The relations between the signals x1, x2, and x3, and the signal x are – The
signals x1, x2, and x3 are related to the signal x in the context of signal smoothing, and
their purpose is to create a moving average of the signal x. The idea behind these shifts
is to smooth out the signal by averaging the current value of x with its neighboring
values
< Insert program code here. Copy from m-file(s) and paste. >
% Program P1_6
% Generation of amplitude modulated sequence
20
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');
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:
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
21
Q1.35 The difference between the arithmetic operators * and .* is - *: Multiply matrices
or scalars
< Insert program code here. Copy from m-file(s) and paste. >
% 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;
subplot(2,1,1);
stem(n, x);
axis([0,100,-1.5,1.5]);
title('Swept-Frequency Sinusoidal Signal');
xlabel('Time index n');
ylabel('Amplitude');
grid; axis;
subplot(2,1,2);
plot(n, x);
axis([0,100,-1.5,1.5]);
title('Swept-Frequency Sinusoidal Signal');
22
xlabel('Time index n');
ylabel('Amplitude');
grid; axis;
%arg=an^2+bn
%w=(arg)'=2an+b
%(2pi/200)*0+0<=2pif=2an+b<=(2pi/200)*100+0
%0<=w<=pi
%0<=2pif<=pi
%0<=f<=0.5
Answers:
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
Q1.37 The minimum and maximum frequencies of this signal are - min= 0.005 and
max=1/2
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 : a= pi/500; b=0.2
pi
< Insert program code here. Copy from m-file(s) and paste. >
n = 0:100;
a = pi/500;
b = 0.2*pi;
arg = a*n.*n + b*n;
23
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 - List all variable names that exist in memory
Q1.40 The information displayed in the command window as a result of the whos
command is - list variables name, size, number of elements and check for non-zero
imaginary parts.
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 :
< Insert program codes here. Copy from m-file(s) and paste. >
square
24
n = 0:40;
f = 0.1;
phase = 0;
A = 3;
arg = 2*pi*f*n - phase;
x = A*square(arg,30); %square(T,duty) duty de chi so phan tu phia tren
trong 1 chu ky
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 40 -4 4]);
grid;
title('testsquare');
xlabel('Time index n');
ylabel('Amplitude');
axis;
sawtooth
n = 0:50;
f = 0.05;
phase = 0;
A = 2;
arg = 2*pi*f*n - phase;
x = A*sawtooth(arg);
%x = A*sawtooth(arg,.5); %sawtooth de
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 50 -2.5 2.5]);
grid;
title('testsawtooth');
xlabel('Time index n');
ylabel('Amplitude');
n = 0:50;
f = 0.05;
phase = 0;
A = 2;
arg = 2*pi*f*n - phase;
x = A*sawtooth(arg,.5); %sawtooth de
clf; % Clear old graph
stem(n,x); % Plot the generated sequence
axis([0 50 -2.5 2.5]);
grid;
title('testsawtooth');
xlabel('Time index n');
ylabel('Amplitude');
< Insert MATLAB figure(s) here. Copy from figure window(s) and
paste. >
square
25
Sawtooth
26
27
Date: Signature:
28