Ee4015 Matlab3

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

1

EE 4015 Digital Signal Processing in Communications



MATLAB Exercise 3

Spectral Analysis

Intended Learning Outcomes:

On completion of this MATLAB exercise, you should be able to

Analyze discrete-time signals in the frequency domain
Implement and analyze several spectral estimation methods using synthetic and
real-world signals

Deliverable:

Each student is required to submit a hardcopy answer sheet which contains
answers to the questions in this manual on or before 2 November 2012.

Background:

Spectral analysis [1]-[3] involves determining the distribution of amplitude or power
over frequency, associated with a given signal. Periodogram [4] is a conventional
method for it and the periodogram of a sequence ] [n x of length N is defined as

2
2
1
0
,
| ) ( |
1
] [
1
) (

=
e
= = e |
j
N
n
n j
p xx
e X
N
e n x
N


where ) (
e j
e X is the discrete-time Fourier transform (DTFT) of ] [n x

with a length of N .
The periodogram is a nonparametric spectral analysis approach because no
assumptions are made on the observed data sequence. Since ) (
e j
e X

is continuous in
frequency, it is desirable to have its discrete version for digital signal processing. The
discrete version is known as the discrete Fourier transform (DFT) and the DFT of ] [n x

is defined as
1 , , 1 , 0 , ] [ ] [
1
0
/ 2
= =

=
t
N k e n x k X
N
n
N kn j


at frequencies N k
k
/ 2t = e . Using the DFT, the sampled version of the periodogram
is computed as
1 , , 1 , 0 , ] [
1
] [

2
1
0
/ 2
,
= = |

=
t
N k e n x
N
k
N
n
N kn j
p xx


An important topic in spectral analysis is to estimate the frequencies of signals and
this problem has many applications such as wireless communications, audio and
speech processing, biomedical engineering, power electronics, astronomy and
instrumentation and measurement [5]. From the periodogram, the signal frequencies
can be estimated from its peaks:
2

)} (

{ max arg
, 0
e | = e
e
p xx


On the other hand, parametric methods, which assume that the signal satisfies a
generating model with known functional form, such as modified covariance (MC) [2]
and Pisarenko harmonic decomposition (PHD) [3] can be used when the discrete-
time signal is a pure tone:

1 , , 1 , 0 ), cos( ] [
0
= | + e o = N n n n x

where 0 > o , ) , 0 (
0
t e e and ) 2 , 0 [ t e | denote the unknown tone amplitude,
normalized radian frequency and phase, respectively. The MC method [2] makes
use of the simple recurrence of ] [n x :

] 2 [ ] 1 [ ) cos( 2 ] [
0
e = n x n x n x

and the frequency estimate is given as:

| |
|
|
|
|
.
|

\
|

+
= e

=

=
] 1 [ 2
] 2 [ ] [ ] 1 [
cos
2
1
2
1
2 1
0
n x
n x n x n x
N
n
N
n


On the other hand, the PHD method utilizes the autocorrelation estimates of ] [n x :

2 , 1 , 0 ], [ ] [
1
1
0
= +

=

=
k k n x n x
k N
r
k N
n
k


and the frequency estimate is computed as:

|
|
.
|

\
|
+ +
= e

1
2
1
2
2 2 1
0
4
8
cos
r
r r r


Procedure:

1. Let ) 2 . 1 200 cos( 10 ) ( + t = t t x which is a continuous-time sinusoid. The ) (t x is
sampled every
s
T sec. to obtain a sequence ] [n x where ) ( ] [
s
nT x n x = . Answer
the following questions:

(a) Produce ] [n x for 100 0 s s n with 001 . 0 =
s
T sec. Use stem to plot ] [n x .
What is the relationship between the frequencies of ) (t x and ] [n x ?
(b) Create and save a file called mc.m which contains

function w = mc(x);
% w = mc(x) is used to estimate frequency
% the MC method from the vector x
% x is supposed to be a noisy single-tone sequence
3
% w is the estimated frequency in radian
N=max(size(x));
t1=0;
t2=0;
for n=3:N
t1=t1+x(n-1)*(x(n)+x(n-2));
t2=t2+2*(x(n-1))^2;
end
r = t1/t2;
if (r>1)
r=1;
end
if (r<-1)
r=-1;
end
w=acos(r);

That is, mc is the MATLAB function for the MC estimator. What is purpose
of setting r to 1 and -1 when its value is larger than 1 and smaller than -1,
respectively? Determine the frequency estimate for ] [n x using mc.
(c) Develop the MATLAB function for the PHD estimator, denoted by phd.
Note that xcorr with unbiased can be utilized in implementing phd.m.
Determine the frequency estimate for ] [n x using phd.
(d) With the use of the fft command, develop the MATLAB function to
compute the sampled periodogram ] [

,
k
p xx
| , 1 , , 1 , 0 = N k , denoted by
per. Based on the periodogram peak, determine the frequency estimate
for ] [n x using per. You may use the command max in the peak search.
(e) Determine the frequency estimates using MC, PHD and sampled
periodogram when ) (t x is changed to ) 2 . 1 267 cos( 10 ) ( + t = t t x .
(f) Based on (b)-(e), discuss the frequency estimation accuracy of MC, PHD
and sampled periodogram according to the absolute difference between
the true and estimated values.
(g) With the use of zeros command, construct a new sequence ] [n y

by
padding M zeros at the end of ] [n x with ) 2 . 1 267 cos( 10 ) ( + t = t t x .
Compute the frequency estimates using the sampled periodogram of ] [n y
for 100 = M , 1000 = M and 1000000 = M . Discuss the effect of zero
padding in frequency estimation based on the sampled periodogram.
(h) The frequency components of a continuous-time signal can be
investigated using its sampled version x with the following MATLAB code:

[freq_response,freq_index] = freqz(x,1,N,Fs);
plot(freq_index,abs(freq_response))

In doing so, you will see the magnitude plot of the Fourier transform for x
versus frequency in Hz. The N and Fs represent the number of samples
used in the plot and sampling frequency in Hz, respectively. Note that N
should be chosen sufficiently large to ensure a smooth plot. Try the above
MATLAB code with N equals 500 to analyze ] [n x for 100 0 s s n with
4
001 . 0 =
s
T sec. which corresponds to ) 2 . 1 267 cos( 10 ) ( + t = t t x , in the
frequency domain. From the plot or freq_index and
abs(freq_response), determine the peak frequency. For more
information regarding the usage of freqz, try help freqz. Try different
values of N to study its effects.

2. An application for spectral analysis in the field of astronomy is to find the sunspot
cycle [6]. Download spot_num.txt at [6]. Remove the first row and rows after
July 2012 and then overwrite the file. Try the following code:

load spot_num.txt
ssn = spot_num(:,3);
ssn = ssn-mean(ssn);

(a) Describe the usage of each of the three commands.
(b) Compute the frequency estimates for ssn using the MC, PHD and
sampled periodogram.
(c) Based on each estimate in (b), determine the sunspot cycle in terms of
number of months. Note that the sunspot number sampling interval in
spot_num.txt is one month.
(d) According to [6], which sunspot cycle estimate(s) is/are close to the
expected value?

References:

[1] S.L.Marple, Jr. Digital Spectral Analysis With Applications, Prentice-Hall, 1987
[2] S.M.Kay, Modern Spectral Estimation: Theory and Application, Prentice-Hall,
1988
[3] P.Stoica and R.L.Moses, Introduction to Spectral Analysis, Prentice-Hall, 1997
[4] A.V.Oppenheim and R.W.Schafer, Discrete-Time Signal Processing, Prentice
Hall, 1998
[5] IEEE Standard for Digitizing Waveform Recorders, IEEE Std. 1057, 1994
[6] http://solarscience.msfc.nasa.gov/SunspotCycle.shtml

You might also like