You are on page 1of 15

KEEE494: 2nd Semester 2009 Lab 9

Lab 9: Timing Error and Frequency Error


1 Review: Multi-Rate Simulation
In this lab, we learn to simulate the digital communication systems with multi-rate. Consider the BPSK mod-
ulated digital transmission system given in Fig. 1. So far, for the simulation, we have considered the sampled
X
d=+1,-1,-1,+1
g(t)
T
0
T 0
s(t)
2T 3T 4T
Zero-padding for over-sampling rate 4
Generation of d
0 T
0 T
2T
3T
1
T
1
osT
1
T

1
osT


1
osT
s(t)
1
T
Figure 1: BPSK modulated digital transmission.
signal at the output of the matched lter such as
y
n
= s(nT) h(nT) + n(nT)
where h(nT) is the matched lter. This procedure was programmed in Matlab (Reference:Lab note 5)
for i=1:N,
[n(1) n(2)]=gngauss(sgma);
r(i,:)=qam_sig(i,:)+n;
end;
We now want to consider the transmitted pulse, (root raised cosine pulse, rectangular pulse, etc) and employ the
matched lter at the output. In Fig. 1, the rectangular pulse is employed. For example for BPSK modulation,
we generate the bits with equal probabilities and assign the bit zero to a symbol d and the bit one to a
symbol +d. This can be programmed in Matlab very easily such as
d=1;
N=10000;
for n=1:N,
1
u=rand;
if (u<0.5)
bit(n)=0;
symbol(n)=-d;
else
bit(n)=1;
symbol(n)=d;
end;
end;
Note that this simulation only contain the signal at the time of nT and does not have any information between
(n1)T and nT. To represent the information between (n1)T and nT and to have more practical simulation,
we now try to make a simulation by over-sampling. As shown in Fig. 1, this procedure can be realized for the
rectangular pulse with over-sampling rate 4 in Matlab :
N=10000;
d=1;
os=4; % over sampling rate
for n=1:N
u=rand;
if (u < 0.5)
bit(n)=0;
s(os
*
(n-1)+1:os
*
n) = [-d zeros(1,os-1)]; % zero padding
else
bit(n)=1;
s(os
*
(n-1)+1:os
*
n) = [d zeros(1,os-1)]; % zero padding
end
end
t=[-2:1/os:2]; % T is normalized to 1.
tap=length(t);
% pulse
g=[zeros(1,length([-2:1/os:-0.5])),ones(1,length(-0.5+1/os:1/os:0.5)),...
zeros(1,length([0.5+1/os:1/os:2]))]; % rectangular pulse
g=g/sqrt(sum(g.2)); % pulse is normalized to a unit energy
tx=conv(s,g); % Transmitted signal
Note that the rectangular pulse is realized with length of t taps and each tap is spaced at T/(number of over-
sampling=4) [sec]. Also note that the symbol at each symbol instant nT is zero padded as many as (over-
sampling rate-1=3).
The received signal corrupted by the AWGN with variance of 1/SNR can be written in Matlab as:
noise =randn(1,os
*
N+(os-1))/sqrt(snr
*
os);
rt = tx + noise;
The matched lter output at the receiver is
for k=1:tap,
h(k)=g(tap-k+1);
2
end
r = conv(rt,h);
Then, it is sampled at every symbol interval T and it can be written in Matlab as
decis = r(tap:os:length(r));
This procedure is depicted in Fig. 2.
os
Matched Filter
1
osT
0 T
T
2T 3T
4T
T 2T 3T
4T
Down-sampling
Figure 2: Matched lter output for noiseless case.
Now, the simulation of the BPSK modulation can be programmed as below.
function [pe]=bpsk_rect(snrdB,os);
N=10000;
snr=10.(snrdB/10);
d=1;
for n=1:1:N
u=rand;
if (u < 0.5)
bit(n)=0;
s(os
*
(n-1)+1:os
*
n) = [-d zeros(1,os-1)];
else
bit(n)=1;
s(os
*
(n-1)+1:os
*
n) = [d zeros(1,os-1)];
end
end
t=[-2:1/os:2]; % T is normalized to 1.
tap=length(t);
% pulse
g=[zeros(1,length([-2:1/os:-0.5])),ones(1,length(-0.5+1/os:1/os:0.5)),...
zeros(1,length([0.5+1/os:1/os:2]))];
g=g/sqrt(sum(g.2));
tx=conv(s,g); % Transmitted signal
3
noise = randn(1,length(tx))/sqrt(2
*
snr);
rt = tx + noise;
for k=1:tap,
h(k)=g(tap-k+1);
end
% correlator output
r = conv(rt,h); decis = r(tap:os:length(r));
pe=0; for n=1:1:N,
if (decis(n) > 0)
b_hat(n) = 1;
else
b_hat(n) = 0;
end
if (b_hat(n) = bit(n));
pe=pe+1;
end
end pe=pe/N;
Performing the Monte Carlo simulation for the over-sampling rate 4 such as
snrdB=[0:2:10];
snrdB1=[0:0.1:10];
snr=10.(snrdB./10);
snr1=10.(snrdB1./10);
os=4;
for k=1:1:length(snr),
smpe(k)=bpsk_rect(snrdB(k),os);
end
thpe=Qfunct(sqrt(2
*
snr1));
semilogy(snrdB,smpe,o,snrdB1,thpe,-)
grid on
xlabel(E_b/N_o [dB])
ylabel(BER)
Then, if we simulate the BPSK, we have the BER curve given in Fig. 3.
2 Effect of Timing Error
In practical communication system, the accurate sampling timing should be estimated while in class we have assumed
the perfect sampling time. In this lab, we want to see the effect of timing error on the performance.
We need to modify two lines from the above.
1. At the rst line: function [pe]=bpsk_m1(snrdB,os) function[pe]=bpsk_rect(snrdB,os,epsilon),
where epsilon is ranged from 0 to (os-1).
2. After the matched lter: decis = r(os:os:length(r)); decis=r(tap+epsilon:os:length(r)).
4
0 1 2 3 4 5 6 7 8 9 10
10
6
10
5
10
4
10
3
10
2
10
1
SNR [dB]
B
E
R
Simulation
Theory
Figure 3: BER performance.
Note that corresponds to the timing error of /T. Let us run the following m-le;
snrdB=[0:2:10];
os=4;
for k=1:length(snrdB)
pe1(k)=bpsk_rect(snrdB(k),os,0);
pe2(k)=bpsk_rect(snrdB(k),os,1);
pe3(k)=bpsk_rect(snrdB(k),os,2);
end
semilogy(snrdB,pe1,-o,snrdB,pe2,-x,snrdB,pe3,-d)
grid on
xlabel(SNR [dB])
ylabel(BER)
legend(No timing error,\epsilon=1/T,\epsilon=2/T)
Then, the simulation results are illustrated in Fig. 4. It is clear to see from Fig. 4 that the performance loss due to the
timing error is huge.
5
0 1 2 3 4 5 6 7 8 9 10
10
3
10
2
10
1
10
0
SNR [dB]
B
E
R
No timing error
=1/T
=2/T
Figure 4: Effect of timing error on BER.
6
3 Effect of Frequency Error on BPSK Signals
No frequency error case:
For the binary PSK (or equivalently Binary PAM), the signal can be represented as
s
m
(t) = s
m
f(t) m = 1, 2
where f(t) =
_
2
E
g
g(t) cos 2f
c
t, g(t) is the pulse with the energy of E
g
and f
c
is the carrier frequency. The
received signal over AWGN can be written as
r(t) = s
m
(t) + n(t)
where n(t) is the AWGN with spectral density of N
o
/2.
The optimum receiver over AWGN employs the correlation based demodulator so that the output of the demod-
ulator can be obtained as
y(t) =
_
T
0
r(t)f(t) dt
=
_
T
0
s
m
(t)f(t) dt +
_
T
0
n(t)f(t) dt
= s
m
_
T
0
f(t)f(t) dt + z(t)
= s
m
+ z(t) (1)
where it can be easily shown that z(t)is zero mean Gaussian random process with variance of N
o
/2. Note that
the output SNR of the demodulator is now given by

o
=
s
2
m
N
o
/2
=
2E
b
N
o
= 2
where s
2
m
= E
b
and = E
b
/N
o
. Then, the bit error probability can be shown as
P
b
= Q
_
_
2
_
Frequency Error Case:
Now consider the receiver with frequency error, f
e
, which may be caused by the heat or imperfection of the
oscillator. Then even though the receiver set the oscillator to generate the frequency f
c
, it will generate the
frequency f
c
+ f
e
so (3) can be written as
y(t) =
_
T
0
r(t)

2
E
g
g(t) cos 2(f
c
+ f
e
)t dt
= s
m
_
T
0
2
E
g
_
T
0
g
2
(t) cos(2f
c
t) cos(2(f
c
+ f
e
)t) dt + z(t), (2)
where we can easily show that z(t) is Gaussian random process with zero mean and N
o
/2 variance (Why?).
Assuming the rectangular pulse for g(t), we can write (2) as
y(t) = s
m
_
T
0
2 cos(2f
c
t) cos(2(f
c
+ f
e
)t) dt + z(t)
= s
m
_
T
0
[cos(2f
e
t) + cos(2(f
c
+ f
e
)t)] dt + z(t)
= s
m
sin(2f
e
T)
2f
e
+ z(t) (3)
7
Now the output SNR for the carrier frequency error is given as

f
e
=
2E
b
_
sin(2f
e
T)
2f
e
_
2
N
o
= 2
_
sin(2f
e
T)
2f
e
_
2
and thus its BER can be written as
P
b
= Q
_

sin(2f
e
T)
2f
e

_
2
_
In Matlab, we can check the effect of frequency error on the BER performance by running the following m-le and its
result is given in Fig. 5.
snrdB=[0:0.1:15];
snr=10.(snrdB./10);
T=1;
a=[0.1 0.2 0.3];
a=sin(2
*
pi
*
a
*
T)./(2
*
pi
*
a);
pb0=Qfunct(sqrt(2
*
snr));
pb1=Qfunct(sqrt(2
*
snr)
*
abs(a(1)));
pb2=Qfunct(sqrt(2
*
snr)
*
abs(a(2)));
pb3=Qfunct(sqrt(2
*
snr)
*
abs(a(3)));
semilogy(snrdB,pb0,-,snrdB,pb1,--,snrdB,pb2,:,snrdB,pb3,.)
grid on xlabel(\gamma [dB]) ylabel(BER)
legend(f_eT=0,f_eT=0.1,f_eT=0.2,f_eT=0.3)
axis([0 15 10(-8) 1])
1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1
0.25
0.2
0.15
0.1
0.05
0
0.05
0.1
0.15
0.2
0.25
f
e
T (True Value) [Hz]
E
s
t
i
m
a
t
e
d

V
a
l
u
e

[
H
z
]
Figure 5: Effect of frequency error for T = 1 sec and f
e
T = 0, 0.1, 0.2, and 0.3.
As seen in this gure, there are signicant performance loss due to the frequency error. For example, if T = 1 ms
and the frequency error is f
e
= 100, 200, and 300 Hz, which correspond to f
e
T = 0.1, 0.2, and 0.3, the performance
loss to reach 10
3
BER, comparing to no frequency error, is approximately 0.5 dB, 2.5 dB, and 7 dB, respectively
8
4 Estimation of Frequency Error
For the estimation of frequency error, there are mainly two different schemes: one is non-data aided scheme and the
other is data-aided scheme. In our lab, we only consider the non-data aided scheme where the pilot signal is used for
the frequency error.
Pilot Signals: The pilot signal is known signal at the receiver. For example, the transmitter transmits the signal
for the symbol duration T as
s(t) = [Ag(t)e
j2f
c
t
],
where A is a complex constant value and g(t) is the pulse dened for 0 t T. In practical communication
systems, the pilot signal is transmitted for the channel estimation, frequency error estimation, timing error
estimation, etc.
Estimation over noiseless channels:
Let us consider noiseless case only to see the effect of frequency error. Then, at the receiver, employing the
correlation based demodulator, we have its sampled output signal with the sampling period of T as
y(nT) = [ y(nT)]
= [Ae
j2f
e
nT
]
= A
I
cos(2f
e
nT) A
Q
sin(2f
e
nT) (4)
where y(nT) is the complex representation of y(nT), that is, y(nT) = Ae
j2f
e
nT
, A = A
I
+ jA
Q
. Note
that A
I
and A
Q
are known to the receiver and thus
A
is also known. Without loss of generality and for the
simplicity, let us assume that A
I
=

P and A
Q
= 0. Consider the following discriminator as
d(n) = y

(nT) y((n 1)T) =

Pe
j2f
e
T
,
where is the conjugate operation.
Then, we can estimate f
e
by

f
e
=
tan
1
__
Quadrature term of d(n)
In-phase term of d(nT)
__
2T
Simulation: In Matlab, we can simulate the estimation of f
e
using the complex signal. We rst want to see the
various values of f
e
such as f
e
= [1/T : 0.1/T : 1/T] with T = 1 sec. Then, its result is illustrated in Fig. 6.
Note that Fig. 6 is called the S-curve. Why is it periodic? What is the bound of the frequency error in Hz that
your atan based estimator can estimate? You have to answer these questions!
N=1;
P=1;
j=sqrt(-1);
A=sqrt(P)
*
ones(1,N); % unit energy.
T=1; % symbol duration
fe=[-1/T:0.1/T:1/T]; % [Hz]
dnT= A.
*
exp(j
*
2
*
pi
*
fe
*
T);
hatfe=atan(imag(dnT)./real(dnT))./(2
*
pi
*
T);
close all
9
plot(fe,hatfe)
grid on
xlabel(f_e (True Value) [Hz])
ylabel(Estimated Value [Hz])
1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 1
0.2
0.15
0.1
0.05
0
0.05
0.1
0.15
0.2
0.25
f
e
(True Value) [Hz]
E
s
t
i
m
a
t
e
d

V
a
l
u
e

[
H
z
]
Figure 6: S-curve.
Estimation over noisy channels
We now want to estimate the frequency error over noisy channels. In this example, we want to take an average
of the estimated frequency error to reduce the effect of noise.
Let us generate N pilot symbols such as
A=ones(1,N);
Then, the received sampled sample can be written as
ynT=A.
*
exp(j
*
2
*
pi
*
fe
*
[0:1:N-1]
*
T) + (randn(1,N) + ...
j
*
randn(1,N))/sqrt(snr);
Then, the output of the discriminator is
dnT=conj(ynT(1:N-1)).
*
ynT(2:N);
Note that in the above, taking arctangent for dnT and dividing it by 2T may be different from the true value,
f
e
, due to the noise. To reduce the noise effect, we make an average with the samples M, such as
10
L=floor(N/M);
for k=1:L,
meandnT(k)=mean(dnT((k-1)
*
M+1:M));
fehat(k)=atan(meandnT)/(2
*
pi
*
T);
end
Then, we run the simulation to see the performance of the estimation in terms of the root mean square error
(RMSE), dened as,
RMSE =
_
E[(

f
e
f
e
)
2
]
In summary, we can build the following function for the symbol rate 1/T = 15 KHz.:
function mse=lab72(snrdB,M,fe)
T=1/15000; %15 KHz
N=10000;
j=sqrt(-1);
snr=10.(snrdB/10);
A=ones(1,N);
ynT=A.
*
exp(j
*
2
*
pi
*
fe
*
[0:1:N-1]
*
T) + (randn(1,N) + j
*
randn(1,N))/sqrt(snr);
% M=100;
dnT=conj(ynT(1:N-1)).
*
ynT(2:N);
L=floor(length(dnT)/M);
for k=1:L,
meandnT(k)=mean(dnT((k-1)
*
M+1:k
*
M));
fehat(k)=atan(imag(meandnT(k))/real(meandnT(k)))/(2
*
pi
*
T);
end
mse=sqrt(mean((fehat-fe).2));
Then, for the SNR=10dB, f
e
= 100 Hz and the average length M=100, we have RMSE of 34.9815 Hz by
running m=lab72(10,100,10). You might have different value.
The MSE will be getting lower as the signal power P increases, equivalently the SNR increases. Let us run the
simulation to see the effect of the SNR for a xed value of f
e
= 100 Hz by running the following m-le. Its
result is depicted in Fig. 7.
snrdB=[0:2:20];
snr=10.(snrdB./10);
M=100;
fe=100;
for k=1:1:length(snr),
rmse(k)=lab72(snrdB(k),M,fe);
end
plot(snrdB,rmse);
grid on
xlabel(SNR [dB])
ylabel(RMSE [Hz])
11
0 2 4 6 8 10 12 14 16 18 20
0
50
100
150
200
250
300
350
SNR [dB]
R
M
S
E

[
H
z
]
Figure 7: Effect of SNR on the performance of frequency estimator.
The average length M will denitely affect the performance of SNR. Now let us see the effect of the aver-
age length for the xed SNR=10dB and f
e
= 100 Hz. Note that for this simulation, increase the number of
simulation N as 100000.
snrdB=10;
snr=10.(snrdB./10);
M=[10:10:500];
fe=100;
for k=1:1:length(M),
rmse(k)=lab72(snrdB,M(k),fe);
end
plot(M,rmse);
grid on
xlabel(SNR [dB])
ylabel(RMSE [Hz])
12
0 50 100 150 200 250 300 350 400 450 500
0
20
40
60
80
100
120
140
160
SNR [dB]
R
M
S
E

[
H
z
]
Figure 8: Effect of average length on the performance of frequency estimator.
13
Lab Homework
Problem 1. In class, we learned that the raised cosine pulse does not incur any intersymbol interference (ISI) because it
satises the Nyquist condition for no ISI and has lower effect of timing error comparing to the rectangular pulse
since the tail of the power spectral density decays as 1/t
3
wile for the rectangular case it decays as 1/t.
The raised cosine pulse, denoted by X
rc
(f), is the pulse after the matched lter is convolved with the transmitted
pulse over the channel.
Assuming the ideal band-limited channel, the transmit pulse and its matched lter at the receiver is given by
G(f) =
_
X
rc
(f) and the pulse in the time domain can be obtained by taking the inverse Fourier transform
yielding the root-raised cosine (RRC) pulse given by
g(t) =
sin
_

t
T
(1 )

+ 4
t
T
cos
_

t
T
(1 + )

t
T
_
1
_
4
t
T
_
2
_
Simulate the BPSK modulated digital transmission systems with RRC for the roll-off factor = 0.22 over
AWGN channels. Use the 8 over-sampling rate and see the effect of timing error of (1)0, (2) T/8, (3) 2T/8.
First, you may need to generate root raised cosine (RRC) FIR lter. The following function can help you
generate the RRC FIR lter.
function coef=rootrc(beta,t,T)
coef=ones(size(t));
i=find(t);
coef(i)=(sin(pi.
*
t(i).
*
(1-beta)./T)+4
*
beta
*
(t(i)./T)...
.
*
cos(pi
*
(t(i)./T).
*
(1+beta)))./(pi.
*
(t(i)./T)...
.
*
(1-(4.
*
beta.
*
t(i)./T).2));
In addition, you may need to replace
t=[-2:1/os:2];
tap=length(t);
% pulse
g=[zeros(1,length([-2:1/os:-0.5])),ones(1,length(-0.5+1/os:1/os:0.5)),...
zeros(1,length([0.5+1/os:1/os:2]))];
g=g/sqrt(sum(g.2));
in rectangular pulse case with
t=[-2:1/os:2];
g=rootrc(beta,t,1);
g=g/sqrt(sum(g.2));
tap=length(g);
Problem 2. Instead of averaging the output of the discriminator output, we might want to average the output of the arctan-
gent. To do this, after you obtain dnT, you calculate the frequency error estimation by
fehat = atan(imag(dnT)./dnT)/(2
*
pi
*
T);
14
Then, average fehat such as
L=floor(length(fehat)/M);
for k=1:length(L),
avgfehat(k)=mean(fehat((k-1)
*
M:k
*
M));
end
Let us call the above algorithm as phase averager (PA) while the previous one is called linear predictor (LP).
Now run the simulation for f
e
= 100Hz and 1/T = 15 KHz to answer the following questions.
1. For the PA, show the effect of SNR in terms of RMSE.
2. For the PA, show the effect of the average length M for SNR=10dB in terms of the RMSE.
3. Compare the PA and LP in terms of the RMSE for the SNR range of [-20:1:20] dB. Which one gives better
performance?
15

You might also like