Solutions for Laboratory Exercise 1 - Lecture Notes |, Study notes of Digital Signal Processing

SOLUTION Laboratory Exercise Material Type: Notes; Class: Digital Signal Processing; Subject: Electrical and Computer Engineering; University: United Arab Emirates University; Term: Forever 1989;

Typology: Study notes

2010/2011

Uploaded on 12/06/2011

i-mohd
i-mohd 🇦🇪

2 documents

1 / 30

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Name: SOLUTION
Section:
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
% 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,u);
xlabel('Time index n');ylabel('Amplitude');
title('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:
-10 -5 0 5 10 15 20
0
0.2
0.4
0.6
0.8
1
Tim e i nde x n
Amplitude
Unit Sam ple Sequence
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e

Partial preview of the text

Download Solutions for Laboratory Exercise 1 - Lecture Notes | and more Study notes Digital Signal Processing in PDF only on Docsity!

Name: SOLUTION

Section:

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_ % 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,u); xlabel('Time index n');ylabel('Amplitude'); title('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:

-10 -5 0 5 10 15 20

0

1

Time index n

Amplitude

Unit Sample Sequence

Q1.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 by running this program.

% Program P1_1, MODIFIED for Q1. % Generation of a DELAYED Unit Sample Sequence clf; % Generate a vector from -10 to 20 n = -10:20; % Generate the DELAYED unit sample sequence u = [zeros(1,21) 1 zeros(1,9)]; % Plot the DELAYED unit sample sequence stem(n,u); xlabel('Time index n');ylabel('Amplitude'); title('DELAYED Unit Sample Sequence'); axis([-10 20 0 1.2]);

-10 -5 0 5 10 15 20

0

1

Time index n

Amplitude

DELAYED Unit Sample Sequence

-10 -5 0 5 10 15 20

0

1

Time index n

Amplitude

ADVANCED Unit Step Sequence

Project 1.2 Exponential signals

A copy of Programs P1_2 and P1_3 are given below.

% Program P1_ % Generation of a complex exponential sequence clf; c = -(1/12)+(pi/6)i; K = 2; n = 0:40; x = Kexp(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_ % 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:

Q1.6 The complex-valued exponential sequence generated by running Program P1_2 is shown

below:

Time index n

Amplitude

Real part

Time index n

Amplitude

Imaginary part

Q1.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 the envelope of

the signal will grow with n instead of decay with n.

Q1.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.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:

Time index n

Amplitude

Q1.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 an example

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.

and computed using the command sum are - 4.5673e+004 and 2.1042e+003.

Project 1.3 Sinusoidal sequences

A copy of Program P1_4 is given below.

% Program P1_ % Generation of a sinusoidal sequence n = 0:40; f = 0.1; phase = 0; A = 1.5; arg = 2pifn - phase; x = Acos(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.

Sinusoidal Sequence

Time index n

Amplitude

Sinusoidal Sequence

Time index n

Amplitude

A 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.

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.

A sinusoidal sequence of frequency 1.1 generated by modifying Program P1_4 is shown below.

Sinusoidal Sequence

Time index n

Amplitude

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.24 By replacing the stem command in Program P1_4 with the plot command, the plot

obtained is as shown below:

0 5 10 15 20 25 30 35 40

-1.

-0.

0

1

2

Sinusoidal Sequence

Time index n

Amplitude

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:

0 5 10 15 20 25 30 35 40

-1.

-0.

0

1

2

Sinusoidal Sequence

Time index n

Amplitude

The difference between the new plot and those generated in Questions Q1.17 and Q1.24 is –

the “stairs” command produces a stairstep plot as opposed to the stem graph that

was generated in Q1.17 and the straight-line interpolation plot that was generated in

Q1.24.

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:

% Program Q1_ % Generation of a uniform random sequence n = 0:99; A = 2; rand('state',sum(100clock)); % "seed" the 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 = 2A(rand(1,length(n))-0.5); clf; % Clear old graph stem(n,x); % Plot the generated sequence axis([0 length(n) -round(2(A+0.5))/2 round(2(A+0.5))/2]); grid; title('Uniform Random Sequence'); xlabel('Time index n'); ylabel('Amplitude'); axis;

Gaussian Random Sequence

Time index n

Amplitude

Q1.28 The MATLAB program to generate and display five sample sequences of a random sinusoidal signal of length 31

{X[n]} = {A·cos(ωon + φ)}

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 ≤ φ ≤ 2π for the phase is given below. Also shown are five sample sequences generated by

running this program five different times.

% Generates the "deterministic stochastic process" % called for in Q1.28. n = 0:30; f = 0.1; Amax = 4; phimax = 2pi; rand('state',sum(100clock)); % "seed" the generator A = Amaxrand; % 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. phi = phimaxrand; % generate the sequence arg = 2pifn + phi; x = Acos(arg); % plot clf; % Clear old graph

stem(n,x); % Plot the generated sequence Ylim = round(2*(Amax+0.5))/2; axis([0 length(n) -Ylim Ylim]); grid; title('Sinusoidal Sequence with Random Amplitude and Phase'); xlabel('Time index n'); ylabel('Amplitude'); axis;

0 5 10 15 20 25 30

0

1

2

3

4

Sinusoidal Sequence with Random Amplitude and Phase

Time index n

Amplitude

0 5 10 15 20 25 30

0

1

2

3

4

Sinusoidal Sequence with Random Amplitude and Phase

Time index n

Amplitude

0 5 10 15 20 25 30

0

1

2

3

4

Sinusoidal Sequence with Random Amplitude and Phase

Time index n

Amplitude

1.2 SIMPLE OPERATIONS ON SEQUENCES

Project 1.5 Signal Smoothing

A copy of Program P1_5 is given below.

% Program P1_ % Signal Smoothing by Averaging clf; R = 51; d = 0.8(rand(R,1) - 0.5); % Generate random noise m = 0:R-1; s = 2m.*(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:

0 5 10 15 20 25 30 35 40 45 50

0

5

10

Time index n

Amplitude

d[n] s[n] x[n]

0 5 10 15 20 25 30 35 40 45 50

0

2

4

6

8

Time index n

Amplitude

y[n] s[n]

Q1.30 The uncorrupted signal s[n]is - the product of a linear growth with a slowly decaying

real exponential.

The additive noise d[n]is – a random sequence uniformly distributed between -0.4 and

Q1.31 The statement x = s + d CANNOT be used to generate the noise corrupted signal

because – d is a column vector, whereas s is a row vector; it is necessary to transpose

one of these vectors before adding them.

Q1.32 The relations between the signals x1, x2, and x3, and the signal x are – all three signals

x1, x2, and x3 are extended versions of x, with one additional sample appended at the

left and one additional sample appended to the right. 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.