You are on page 1of 17

SECTE Laboratory Report 1-3

1

(i) Answer:

(ii) Matlab Code:
Ts = 0.01;
t = 0:Ts:0.25;
xn = 5*cos(120*pi*t + (pi/6));
stem(t, xn, 'filled'),
title('Signal XN')

From the plot is can be seen that the
period N is 5.



(ii) Matlab Plot:

(iii) Answer:
Aliasing has occurred. Nyquist theory states we need at least 120 Hz to avoid aliasing (twice the value of
fmax). The sampling frequency used to plot x(n) was only 100 Hz.

0 0.05 0.1 0.15 0.2 0.25
-5
-4
-3
-2
-1
0
1
2
3
4
5
Signal XN
ECTE301 - Digital Signal Processing: Lab Report 1
Student Name Ben Armstrong
Student ID 3110035 E-mail ba180@uow.edu.au
Lab Report Mark Date
Instructions:
Answer the problems for the lab report 1-3.
Problem 1.1:

Consider the signal
0
( ) s5cos(120 30 ), 0 t 0.25 sec
a
x t t t = + s s . Sample this signal uniformly using a
sampling T = 10 ms period to obtain a discrete time signal x(n).

(i) What is the corresponding sampling rate?
(ii) Plot the signal x(n) using Matlab command stem and deduce its period N from the plot.
(iii) Is there aliasing, and why?


SECTE Laboratory Report 1-3
2

Problem 1.2:

Generate and plot the samples (use the stem(..., filled) function) of the following signals.
(i)
1
( ) 2 ( 2) 0.5 ( 1) ( ) 1.5 ( 1) ( 2), -5 5 x n n n n n n n o o o o o = + + + + + s s
(ii)
2
( ) 2 ( 2) 2 ( 3), -5 5 x n u n u n n = + s s
(iii)
4
3
( ) (0.75) ( 4), 0 15
n
x n u n n

= s s
(iv)
2
4
( ) (0.8) sin(0.3 ) ( 2), 0 15
n
x n n u n n t

= s s
To save space, please plot all figures on the same page, using plot(41x) or plot (22x), where x =
1,...,4.


(i)-(iv) Matlab Code:
n = -5:5
xn1 = 2*(n==-2) + 0.5*(n==-1) - (n==0) + 1.5*(n==1) + (n==2)
subplot(411), stem(n, xn1, 'filled'), title('Signal XN1')
n = -5:5
xn2 = 2*(n >= -2) - 2*(n > 3)
subplot(412), stem(n, xn2, 'filled'), title('Signal XN2')
n = 0:15
xn3 = (0.75).^(n-4).*(n >= 4)
subplot(413), stem(n, xn3, 'filled'), title('Signal XN3')
n = 0:15
xn4 = (0.8).^(n-2).*sin(0.3*pi*n).*(n >= 2)
subplot(414), stem(n, xn4, 'filled'), title('Signal XN4')
(i)-(iv) Matlab Plot:

-5 -4 -3 -2 -1 0 1 2 3 4 5
-2
0
2
Signal XN1
-5 -4 -3 -2 -1 0 1 2 3 4 5
0
1
2
Signal XN2
0 5 10 15
0
0.5
1
Signal XN3
0 5 10 15
-1
0
1
Signal XN4
SECTE Laboratory Report 1-3
3

Problem 1.3:

Consider the following single tone signal
( ) sin(200 ) ( ), 0 0.2sec. x t t u t t t = s s
(i) Sample this signal at the following rates: 2000 Hz, 125 Hz, and 105 Hz. Name the signals x1,
x2, and x3, respectively.
(ii) Using subplot(311), plot and compare the three signals. The first graph should contain all
three signals, the second graph contains the signal x2 and its samples, and the third graph
contains the signal x3 and its samples.
(iii) Find the normalized frequency, f (samples/cycle), and the period, N (in samples), of these
discrete-time signals.
(iv) If three analog signals are to be reconstructed from the three sampled signals, using the
respective sampling rate used to obtain the sampled signal, find the frequencies of the
resulting analog signals.


(i) Matlab Code:
Fs1 = 2000;
Fs2 = 125;
Fs3 = 105;

t1 = 0:(1/Fs1):0.2
t2 = 0:(1/Fs2):0.2
t3 = 0:(1/Fs3):0.2

xn1 = sin(200*pi*t1).*(t1 >= 0)
xn2 = sin(200*pi*t2).*(t2 >= 0)
xn3 = sin(200*pi*t3).*(t3 >= 0)

subplot(311), title('Plot of Xn1(Blue), Xn2(red) and Xn3(Magenta)')
hold on
plot(t1, xn1, 'b')
plot(t2, xn2, 'r')
plot(t3, xn3, 'm')

subplot(312), title('Stem Plot of Xn2')
hold on
stem(t2, xn2, 'filled'), plot(t2, xn2)

subplot(313), title('Stem Plot of Xn3')
hold on
stem(t3, xn3, 'filled'), plot(t3, xn3)

hold off


SECTE Laboratory Report 1-3
4


(ii) Matlab Plot:

(iii) Matlab Code:
F1 = (1/(2*pi))*((200*pi)/Fs1)
F2 = (1/(2*pi))*((200*pi)/Fs2)
F3 = (1/(2*pi))*((200*pi)/Fs3)

N can be obtained from the Matlab
plot.
(iii) Answer:
X1 X2 X3
F
(samples/cycles)
0.05 0.8 0.9524
N (samples) 20 5 22

(iv) Matlab Code:
[Y, I1] = max(xn1);
[Y, I2] = min(xn1);
half_period = abs(t1(I1) - t1(I2));
f1 = 1 / (2 * half_period)

[Y, I1] = max(xn2);
[Y, I2] = min(xn2);
half_period = abs(t2(I1) - t2(I2));
f2 = 1 / ((2 * half_period)+t2(2))

[Y, I1] = max(xn3);
[Y, I2] = min(xn3);
half_period = abs(t3(I1) - t3(I2));
f3 = 1 / (2 * half_period)
(iv) Answer:
f1 =
100.0000

f2 =
25.0000

f3 =
4.7727
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
-1
0
1
Plot of Xn1(Blue), Xn2(red) and Xn3(Magenta)
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
-1
0
1
Stem Plot of Xn2
0 0.02 0.04 0.06 0.08 0.1 0.12 0.14 0.16 0.18 0.2
-1
0
1
Stem Plot of Xn3
SECTE Laboratory Report 1-3
5

(i) ) Matlab Code:
n1 = 0:10
x = (0.7).^n1
n2 = 0:10
h = (n2 >= 3) - (n2 >= 8)
y = conv(x,h)
n = length(x) + length(h) -1; n3 = 0:n-1;
(ii) Matlab Code:
subplot(311)
stem(n1, x,'filled')
title('Plot of x(n)')
ylabel('x(n)')

subplot(312)
stem(n2, h,'filled')
title('Plot of h(n)')
ylabel('h(n)')

subplot(313)
stem(n3, y, 'filled')
title('y(n) = x(n) * h(n)')
xlabel('n'), ylabel('y(n)')

(ii) Matlab Plot:

(iii) Answer:







0 1 2 3 4 5 6 7 8 9 10
0
0.5
1
Plot of x(n)
x
(
n
)
0 1 2 3 4 5 6 7 8 9 10
0
0.5
1
Plot of h(n)
h
(
n
)
0 2 4 6 8 10 12 14 16 18 20
0
2
4
y(n) = x(n) * h(n)
n
y
(
n
)
Problem 2.1:

Perform the convolution of the following signals:
1; 3 8 (0.7) ; 0 10
( ) and ( )
0; otherwise 0; otherwise
n
n n
h n x n
s s s s
= =



(i) Compute the sequence ( ) ( ) ( ) y n x n h n = - .
(ii) Plot the three sequences, x(n) , h(n), y(n) and in three separate graph windows using subplot
and stem.
(iii) What is the length of the sequence y(n)? What is the range of over which ( ) 0 y n = ?
SECTE Laboratory Report 1-3
6

Problem 2.2:

The image below is blurred with a 1-D FIR filter in the horizontal direction. The blurring filter is
h(n) = [0.0392 0.0529 0.0634 0.0714 0.0771 0.0809 0.0832 0.0843 0.0843 0.0834
0.0683 0.0553 0.0442 0.0348 0.0269 0.0202 0.0145 0.0098 0.0059];
Blurred Image.


Restore the original image using deconvolution. What is the message hidden in the image?

First, you need to load the file prac2_prb2_file.mat using the command load prac2_prb2_file. This
file contains the blurred image, y, and the impulse response of the FIR filter, h.


Matlab Code:
clear all % clears all the variables from the workspace.
clf % clears the figure.
load prac2_prb_file % loads an image stored in a file called prac2_prb_file.
who % lists the current variable (i.e., image).
subplot(211), imagesc(y), colormap gray
title('Blurred Image, Y')

[N, M] = size(y);
Xr = [ ]; % create an empty matrix in for the restored image.
for i = 1:N
Xr = [Xr; deconv(y(i,:), h)]; % Restore the image one row at a time.
end

subplot(212), imagesc(Xr), colormap gray
title('Restored Image, Xr')





SECTE Laboratory Report 1-3
7














Answer:




Blurred Image, Y
20 40 60 80 100 120 140 160 180
5
10
15
20
Restored Image, Xr
20 40 60 80 100 120 140 160 180
5
10
15
20
SECTE Laboratory Report 1-3
8

Problem 2.3:

Consider the discrete-time causal system
( ) 0.5 ( 1) 0.5 ( 2) 0.25 ( 3) ( ) y n y n y n y n x n = + + +
(i) Compute and plot the impulse and step responses, for 0 50 n s s .
(ii) What is the steady-state value of the step response? Solve for this by hand, then check
your answer using the graph and the last value of y(n), i.e., y(length(y)). Do all your answers
agree, why?
(iii) Compute the response of this system to the sinusoidal input ( ) 20sin(0.4 ) x n n t = . What is
the frequency and amplitude of the steady-state response, i.e., the frequency and amplitude
of as n .
(iv) Find the poles and zero of the system, plot the pole-zero diagram, and determine the
stability of the system.



(i) Matlab Code:

n = 0:50
A = [1 0.5 -0.5 -0.25]
B = [1]

d = n==0
h = filter(B, A, d) % Impulse response
subplot(211), stem(n, h, 'filled'), title('Impulse Response')
xlabel('n'),ylabel('h(n)')

u = n>=0
y = filter(B, A, u) % Step response
subplot(212), stem(n, y, 'filled'), title('Stem Response')
xlabel('n'),ylabel('y(n)')









SECTE Laboratory Report 1-3
9
(i) Matlab Plot:





(ii) Answer:
These results agree because by y(51) the system has already reached stability.
(iii) Matlab Code:
clf
x = 20*sin(0.4*pi*n)
y = filter(B, A, x) % Step response
stem(n, y, 'filled')
title('Response to x(n) = 20sin(0.4*pi*n)')
xlabel('n'),ylabel('y(n)')










(iii) Answer:
0 5 10 15 20 25 30 35 40 45 50
-0.5
0
0.5
1
Impulse Response
n
h
(
n
)
0 5 10 15 20 25 30 35 40 45 50
0
0.5
1
1.5
Stem Response
n
y
(
n
)
SECTE Laboratory Report 1-3
10











(iv) Matlab Code:
p = roots(A);
r = abs(p); max(r)
zplane(B,A)



(iv) Answer:
(v) Answer:

All the poles lie within the unit circle, therefore the system is stable.

-1 -0.5 0 0.5 1
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
3
Real Part
I
m
a
g
i
n
a
r
y

P
a
r
t
SECTE Laboratory Report 1-3
11

(i) Matlab Code:
s = [0 1 1 0 1 0 1 1]
w = sqrt(0.36)*randn(1,
length(s))
xn = s + w
stem(xn, 'filled')
title('Received Signal')








(i) Matlab Plot:

1 2 3 4 5 6 7 8
-1
-0.5
0
0.5
1
1.5
2
Received Signal
Problem 3.1:
Consider the two template signals
1
sin(0.45 ) s n t = and
2
cos(0.1 ) s n t = for 0 19 n s s . In a digital
communication link using frequency shift keying (FSK) the signals
1
( ) s n and
2
( ) s n represent the
two binary numbers 1 and 0, respectively. Suppose the binary sequence s = {1, 1, 0, 1, 0, 1, 1, 0} is
transmitted down a channel that is corrupted by zero-mean white Gaussian noise of variance 0.36.

(i) Construct and plot the received signal ( ) ( ) ( ) x n s n w n = + , where ( ) s n is the signal
representing the binary sequence s and ( ) w n is the white noise sequence.
(ii) Compute and plot the correlation sequences
1 2 0 0 1 0 0 1
( ), ( ), ( ) and ( )
s s s s s s s s
r r r r .
(iii) Compute and plot
1 0
( ) and ( )
xs xs
r r the crosscorrelation sequences of the received signal
x(n) with the template signals
1 0
s ( ) and s ( ) n n .
(iv) Determine a procedure for detecting and identifying the symbols.
(v) Determine and plot the impulse responses
1 0
h ( ) and h ( ) n n of the matched filters
corresponding to the signals
1 0
s ( ) and s ( ) n n , respectively.
(vi) Compute and illustrate
1 0
y ( ) and y ( ) n n , the responses of the
1 0
h ( ) and h ( ) n n to the
received signal x(n) . Compare these responses with the crosscorrelation sequences found
in (ii). What can you conclude?
(vii) A binary sequence was transmitted and the received signal is stored in the file fsk.mat.
Identify the transmitted sequence of 0s and 1s.

SECTE Laboratory Report 1-3
12

(ii) Matlab Code:
n = 0:19
s1 = sin(0.45*pi*n)
s0 = -cos(0.1*pi*n)

[rs1, ls1] = xcorr(s1)
[rs0, ls0] = xcorr(s0)
[rs1s0, ls1s0] = xcorr(s1, s0)
[rs0s1, ls0s1] = xcorr(s0, s1)

subplot(411)
stem(ls1, rs1, 'filled')
title('Correlated sequence
rs1s1')
subplot(412)
stem(ls0, rs0, 'filled')
title('Correlated sequence
rs0s0')
subplot(413)
stem(ls1s0, rs1s0, 'filled')
title('Correlated sequence
rs1s0')
subplot(414)
stem(ls0s1, rs0s1, 'filled')
title('Correlated sequence
rs0s1')

(ii) Matlab Plot:


(iii) Answer:

-20 -15 -10 -5 0 5 10 15 20
-10
0
10
Correlated sequence rs1s1
-20 -15 -10 -5 0 5 10 15 20
-10
0
10
Correlated sequence rs0s0
-20 -15 -10 -5 0 5 10 15 20
-2
0
2
Correlated sequence rs1s0
-20 -15 -10 -5 0 5 10 15 20
-2
0
2
Correlated sequence rs0s1
-20 -15 -10 -5 0 5 10 15 20
-2
-1
0
1
2
-20 -15 -10 -5 0 5 10 15 20
-4
-2
0
2
4
SECTE Laboratory Report 1-3
13
(iv) Matlab Code:
for i = 1:length(s)
if xn(i) < 0.5
symbols(i)= 0;
else
symbols(i) = 1;
end
end




(iv) Matlab Plot:

(v) Matlab Code:
h1 = fliplr(s1)
h0 = fliplr(s0)

subplot(211)
stem(n, h1, 'filled')
subplot(212)
stem(n, h0, 'filled')

















(v) Matlab Plot:

1 2 3 4 5 6 7 8
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Received symbols from xn
0 2 4 6 8 10 12 14 16 18 20
-1
-0.5
0
0.5
1
0 2 4 6 8 10 12 14 16 18 20
-1
-0.5
0
0.5
1
SECTE Laboratory Report 1-3
14
(vi) Matlab Code:
y1 = conv(xn, h1);
y0 = conv(xn, h0);
temp = length(xn) + length(h1) -
1;
nn = -20:temp-21;


subplot(211)
stem(nn, y1, 'filled')
subplot(212)
stem(nn, y0, 'filled')


These responses are the same of that in
part iii. Thus we can conclude that to
perform correlation with convolution. The
same computations will occur if h(n) is
equal to the flipped version of s(n).

(vi) Matlab Plot:

(vii) Answer:
Symbols =
0 1 0 0 1 0 1 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 1 1 1 0 1 1 0 0 0 0 0 0 1 1 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0
0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 0
0 0 0 1 0 0 0 0 0 0 0 1 1 1 1 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 1 1














-20 -15 -10 -5 0 5 10
-2
-1
0
1
2
-20 -15 -10 -5 0 5 10
-4
-2
0
2
4
SECTE Laboratory Report 1-3
15



(i) Matlab Code:
n = 0:20;
s = [1 -1 1 -1 -1 1];
w = sqrt(0.25)*randn(1,
length(n));
x = [0 0 0 0 0 0 0 0 0 0 s 0
0 0 0 0];
x = 0.8*x + w;
stem(n, x, 'filled')
title('Signal x(n)')



The delay D cannot be identified from
the plot.








(i) Matlab Plot:


0 2 4 6 8 10 12 14 16 18 20
-1.5
-1
-0.5
0
0.5
1
1.5
Signal x(n)
Problem 3.2:
Consider the template signal s(n) ={ 1 ,-1 , 1 ,-1 ,-1 , 1}. Let the signal x(n) be a delayed and noise
corrupted version
( ) ( ) ( ), x n s n D w n o = +
where w(n) is a zero-mean white noise sequence and D is the delay in number of samples.

(i) Generate and plot the signal x(n) for 0 20 n s s . (Assume that D = 10, = 0.8 and the white
noise has variance equal to 0.25). Can you identify the delay D from the plot of x(n)?
(ii) Compute and illustrate the crosscorrelation ( )
xs
r and determine the time delay of x(n).
(iii) Identify and plot the matched filter impulse response h(n).
(iv) Compute and plot y(n) the response of the matched filter to x(n), compare y(n) to ( )
xs
r .
(v) Can you determine the time delay of x(n) from the output of the matched filter y(n)?

SECTE Laboratory Report 1-3
16


(ii) Matlab Code:
[rxs, lxs] = xcorr(x,s)
stem(lxs, rxs,'filled')
title('Crosscorrelation of
rxs')


(ii) Matlab Plot:

(iii) Answer:


h = fliplr(s)
t = 0:5
stem(t, h,'filled')
-20 -15 -10 -5 0 5 10 15 20
-5
-4
-3
-2
-1
0
1
2
3
4
5
Crosscorrelation of rxs
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Plot of h(n)
SECTE Laboratory Report 1-3
17
title('Plot of h(n)')



(iv) Matlab Code:
y = conv(x, h);
temp = length(x) + length(h)
-1; nn = -5:temp-6;
stem(nn, y, 'filled')
title('y(n) = x(n)*h(n)')
xlabel('n'), ylabel('y(n)')





(iv) Matlab Plot:

(v) Answer:
The time delay of x(n) can be determined from the above plot by looking at the peak value of the sequence.
The peak value is located at t =10, thus the time delay is equal to 10. This is as expected.


-5 0 5 10 15 20
-5
-4
-3
-2
-1
0
1
2
3
4
5
y(n) = x(n)*h(n)
n
y
(
n
)

You might also like