Mat Lab Book
Mat Lab Book
1. Introdution
Matlab is very powerful program which has been applied in many areas such as mobile
communications. In over the world, Matlab has been used not only in academic educations
but also in industrial applications.
This script helps students understand fundamental principles of mobile communication
and deverlope their Matlab programming skill.
2. Descriptions of excercises
• Exercise 1: Theoretical calculation and simulation of a Gaussian distributed random
variable.
• Exercise 2: Calculation of autocorrelation, power spectral density dunction, Rice
distribution function.
• Exercise 3: Calculation of the level crossing rate (LCR) and average duration of
fading (ADF) of Rice processes. Calculation of Nakagami distribution.
• Exercise 4: Channel modelling by using Rice method.
• Exercise 5: Modulation and demodulation of the QPSK signal.
• Exercise 6: Bit error probability of QPSK on a AWGN and a fading channel.
• Exercise 7: Bit error probability of QPSK with convolutional code on a fading
channel.
• Exercise 8: Symbol error ratio of an OFDM system.
4. References
1) Kermit Sigmon, MATLAB Primer, Second Edition, Department of Mathematics,
University of Florida, 1992.
2) MATHWORKS Inc, MATLAB High-Performance Numeric Computation and Visu-
alization Software, User’s Guide, South Natick, MA, USA, 1994.
3) www.mathwork.com.
4) Proakis, J.G. Digital Communications, 3. edition, New York: McGraw-Hill, 1995.
5) Paetzold, M. Mobilfunkkanaele, Germany: Vieweg & Sohn Verlag GmbH, 1999.
2
Exercise 1
1.1 The probability density function (PDF) of a Gaussian distributed ran-
dom variable µ is given by
1 (x − mµ )2
pµ (x) = √ exp [− ], (1.1)
2πσµ 2σµ2
where mµ and σµ denote the mean value and the variance of µ, respec-
tively. For mµ = 0 and σµ = 1, sketch the PDF pµ (x) in the interval
−4 ≤ x ≤ 4. Check whether or not the PDF result is correct by using
R∞
−∞ pµ (x)dx = 1.
Hint: Use the MATLAB function trapz to compute the integral and
use for the discretization of x the MATLAB command x = −4 : 0.05 :
4.
1.2 A digital transmission system always includes some white noise which
is usually Gaussian distributed. Use the MATLAB function randn to
generate a real-valued white noise vector having a length of 1000000.
Determine the mean value, the variance (power), and the PDF of the
noise from this noise vector. Plot the PDF and compare it with the
theoretical curve in (1.1) under the condition that they have the same
mean value and variance.
Exercise 2
2.1 For the 2–D isotropic scattering flat fading channel model (Clarke’s
model), the autocorrelation function (ACF) of the real and imaginary
components of the received complex signal g(t) = gI (t) + jgQ (t) can
be expressed by
Ωp
φgI gI (τ ) = φgQ gQ (τ ) = J0(2πfm τ ) , (2.1)
2
where Ωp represents the total received power, fm is the maximum
Doppler frequency, and J0(·) denotes the zeroth-order Bessel function
of the first kind.
Hint: Use the MATLAB function besselj for the calculation of the
Bessel function J0 (·).
2.2 For Clarke’s model, the power spectral density (PSD) of gI (t) and
gQ (t) can be expressed by
Ωp
√ 1
2πfm , |f | ≤ fm ,
SgI gI (f ) = SgQ gQ (f ) = 1−(f /fm)2 (2.3)
0 , |f | > fm .
4
Calculate SgI gI (f ) and sketch it. Use the same values for Ωp and fm
as in Exercise 2.1.
2.3 If the 2–D isotropic scattering environment consists of a scattered com-
ponent plus a strong line-of-sight (LOS) component, the probability
density function (PDF) of the received signal amplitude α(t) = |g(t)|
is given by the following Rice distribution
v
2
2x(K + 1) (K + 1)x u K(K + 1)
u
pα (x)= exp [−K − ]I0 2xt ,x ≥ 0. (2.4)
u
Ωp Ωp Ωp
Hint: Use the MATLAB function besseli for the calculation of the
modified Bessel function I0(·).
2.4 For Rice fading, the PDF of the squared envelope, i.e., α2(t) = |g(t)2 |,
is given by the following non-central chi-square distribution
v
K +1 (K + 1)x u u K(K + 1)x
u
pα2 (x) = exp [−K − ]I0 2t , x ≥ 0 . (2.5)
Ωp Ωp Ωp
1) For Ωp = 1, compute pα2 (x) and sketch it for the following cases:
K = 0, K = 3, and K = 80.
2) When K = 0, pα2 (x) will tend to which distribution?
3) When K → ∞, pα2 (x) tends to which distribution?
5
Exercise 3
3.1 The envelope level-crossing rate (LCR) of Rice processes can be ex-
pressed as
2
q q
LR (R) = 2π(K + 1)fm ρe−K−(K+1)ρ I0 (2ρ K(K + 1)) , (3.1)
where pα (x) and LR (R) are given as in (2.4) and (3.1), respectively.
For Ωp = 1, compute the normalized ADF t(R) ∗ fm and plot it for
the following cases: K = 0, K = 3, and K = 10.
3.3 The Nakagami distribution is given by
2mmx2m−1 mx2 1
pα (x)= exp (− ) , m ≥ , (3.3)
Γ(m)Ωm
p Ω p 2
(K + 1)2
m= . (3.4)
2K + 1
Plot these two distributions in the same figure for K = 2, i.e.,
m = 1.8, and compare the results.
Hint: Use the MATLAB function gamma for the calculation of the
Gamma function Γ(·).
7
Exercise 4
where
Ni
X
g̃i (t) = ci,n cos(2πfi,nt + θi,n) , i = 1, 2 . (4.2)
n=1
v
u 2b
u
ci,n = t (4.3a)
Ni
π 1
fi,n = fm sin [ (n − )] (4.3b)
2Ni 2
n
θi,n = 2π (4.3c)
Ni + 1
c 1 ,1
co s( 2 p f 1 ,1 t + q 1 ,1 ) Ä
c
c o s( 2 p f t + q )
1 , 2
g~ 1 ( t )
1 ,2 1 ,2 Ä +
M M
c 1 ,N
c o s ( 2 p f t + q ) Ä
1
1 ,N 1 ,N
a~ ( t )
1 1
g~ ( t )
c 2 ,1
c o s ( 2 p f 2 ,1 t + q 2 ,1 ) Ä
c 2 , 2
c o s ( 2 p f t + q ) Ä +
g~
2 ,2 2 ,2
M M 2 (t)
c 2 ,N
c o s (2 p f t + q ) Ä
2
2 ,N 2 2 ,N 2
4.1 For the given number of sinusoids N1 = 9 and N2 = 10, compute the
simulation model parameters ci,n , fi,n , and θi,n according to (4.3a)–
(4.3c) by using b = 1 and fm = 91 Hz. Write your results in Table 4.1
given on the next page.
4.2 Develop a MATLAB function m-file to simulate the deterministic
processes g̃i (t) for i = 1, 2. Use the quantities ci,n , fi,n, θi,n, and t
as input arguments.
4.3 Write a MATLAB script m-file to carry out the simulation of the
channel amplitude α̃(t) = |g̃(t)| = |g̃1 (t) + jg̃2 (t)| and plot α̃dB (t) =
20logα̃(t). Solve this problem by making use of your function m-file
developed in Exercise 4.2. The simulation model parameters ci,n , fi,n,
θi,n, and Ni are given as listed in Table 4.1. Use the simulation time
Tsim = 0.4 s and the sampling frequency fs = 270.8 kHz, which cor-
responds to the symbol rate used in GSM. If a vehicle drives with a
speed of v = 109.2 km/h, what is the distance it covers in the simu-
lation time?
4.4 Simulate the deterministic functions g̃1 (t), g̃(t), and α̃(t) by using the
sampling frequency fs = 50 kHz and the simulation time Tsim = 20 s.
Determine the mean value and variance of g̃1 (t), g̃(t), and α̃(t). De-
termine the probability density function (PDF) of g̃1 (t) and α̃(t) by
using histograms. Which distributions do they approximate? Com-
pare the PDF of g̃1 (t) with the theoretical result given in (1.1), where
mµ = 0 and σµ = 1. Compare the PDF of α̃(t) with the theoretical
result pα (x) given in (2.4), where Ωp = 2, and K = 0.
Hint: Use the MATLAB function xcorr with the option biased.
10
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
2 1
2 2
2 3
2 4
2 5
2 6
2 7
2 8
2 9
2 10
N1
X c21,n
φ̃g1 g1 (τ ) = cos (2π f1,n τ ) . (4.4)
n=1 2
4.7 Determine and sketch the power spectral density (PSD) S̃g1 g1 (f ) of
the signal g̃1 (t)|t∈I .
Hint: Use the MATLAB functions fft and fftshift. Normalize the
measured PSD to its number of spectral components.
N1
X c21,n
S̃g1 g1 (f ) = [δ(f − f1,n ) + δ(f + f1,n)] . (4.5)
n=1 4
N1
β̃ = 2 π 2 (c1,n f1,n )2 .
X
(4.7)
n=1
Exercise 5
5.1 The QPSK signal constellation by using Gray encoding is shown in
Fig. 5.1. The constellation points are located symmetrically at a unit
circle in the complex domain. Then, the QPSK complex signal vectors
can be expressed by
where θm ∈ { π4 , 3π 5π 7π
4 , 4 , 4 }. In MATLAB, we model a binary bit se-
quence as a finite length vector. Generate a bit vector of length 50000
and then map the bits onto the complex data symbols by using QPSK
modulation with Gray encoding. Plot the constellation diagram.
0 1 0 0
1 1 1 0
Fig. 5.1: Complex signal-space diagram for QPSK with Gray encoding.
5.2 Suppose that the above modulated QPSK signals are transmitted
through an additive white Gaussian noise (AWGN) channel. Then,
the received signal is the addition of the QPSK signal and the white
Gaussian noise. First, generate a complex-valued white Gaussian noise
vector, whose length is identical with that of the QPSK signal vec-
tor. Use the value 6 dB for the signal-to-noise ratio (SNR) in decibel.
14
The SNR is defined as the ratio of the bit energy to noise power, i.e.,
SNR = Eb /N0. Plot the constellation diagram of the received signals.
You are expected to see the so-called Gaussian clouds around the orig-
inal QPSK signal points. Change the SNR (e.g., 3 dB) and plot again
the constellation diagram of the received signals.
Exercise 6
6.1 Let us consider a QPSK baseband transmission system as shown in
Fig. 6.1. The transmitted bits of length 100000 are mapped onto
the QPSK complex data symbols by using Gray encoding as shown
in Fig. 5.1. The modulated QPSK signals are transmitted through
an additive white Gaussian noise (AWGN) channel. We will use the
maximum likelihood (ML) receiver to detect the received signals. In
other words, we compare the distance of a received symbol to all
possible symbol values and choose the one that minimizes the distance.
After QPSK demodulation, the received bits will be compared with
the transmitted bits. Count the errors occurred during transmission
and plot the bit error probability (BEP) for the signal-to-noise ratio
(SNR) of 0, 2, 4, and 6 dB. Note that due to the long simulation
time, it is important to save the obtained simulation results by using
the MATLAB function save. The data can be retrieved by using the
function load.
A W G N
B it S o u rc e Q P S K Q P S K B it S in k
M o d u la tio n D e m o d u la tio n
B E R
C a lc u la tio n
6.2 For QPSK with Gray encoding over an AWGN channel, the theoretical
BEP pb can be obtained from
q
pb = Q( 2γb) , (6.1)
16
where Q(·) denotes the Q function and γb = Eb/N0 is the SNR. Note
that there is no Q function available in MATLAB. Fortunately, it can
be determined by using the complementary error function erfc(·) as
follows
1 x
Q(x) = erfc( √ ) . (6.2)
2 2
Compute pb and plot it for the SNR of 0, 2, 4, and 6 dB. Compare
this theoretical result with the simulated BEP in Exercise 6.1.
B it S o u rc e Q P S K R a y le ig h Q P S K B it S in k
M o d u la tio n F a d in g C h a n n e l D e m o d u la tio n
B E R
C a lc u la tio n
6.4 For QPSK over a slow Rayleigh fading channel, the theoretical BEP
is expressed by
v
1 u γb
u
pb = 1−t , (6.3)
2 1 + γb
where γ b = 2bEb/N0 denotes the average received SNR. For b = 1/2,
compute pb and plot it for SNR = 0, 5, 10, 15, 20 dB. Compare the
theoretical result with the simulated BEP in Exercise 6.3.
18
Exercise 7
Fig. 7.1 shows a coded QPSK baseband transmission system. The structure
of the convolutional coder with the rate Rc = 1/2 and the constraint
length K = 3 is shown in Fig. 7.2. What is the impulse response of
this convolutional coder? We assume that the encoder starts at the all-
zeros state and the decoder uses the Viterbi algorithm with hard decision.
Simulate this coding system by using 2 × 106 transmission bits and plot
the BEP for SNR = 0, 2, 4 dB. Calculate the coding gain for BEP = 10−3
with respect to the uncoded BPSK system. Note that the BEP of uncoded
BPSK is essentially the same as that of uncoded QPSK.
B it S o u rc e C o n v o lu tio n a l Q P S K
C o d e r M o d u la tio n
B E R
A W G N
C a lc u la tio n
V ite rb i Q P S K
B it S in k
D e c o d e r D e m o d u la tio n
firs t o u tp u t
in p u t o u tp u t
s e c o n d o u tp u t
Hint: Use the MATLAB functions convenc, poly2trellis for the convolu-
tional coding and vitdec for the Viterbi decoding.
20
Exercise 8
8.1 Implement an Orthogonal Frequency Division Multiplexing (OFDM)
system using the following parameters taken from HIPERLAN/2 stan-
dard:
8.2 The parameters of the OFDM system are selected as in the exercise
6.1, except the guard interval length is set to be zero. The channel is
still time-invariant. Plot the SER of the system then compare with
the result obtained from exercise 8.1.
8.3 The channel is in this exercise a time-variant channel with the dis-
crete multi-path channel profile similar to that in exercise 8.1. The
maximum Doppler frequency fd,max on each path is 50 Hz.
The channel is modeled by the Monte Carlo method
1 X L M
h(τk , t) = √ ρ[k] ej(2πfk,l t+θk,l )
X
M k=1 l=1
·δ(τ − τk ), (8.1)
where fk,l = fd,max sin(2πuk,l ), θk,l = 2πuk,l , and M are called the
discrete Doppler frequencies, the Doppler phases, and the number of
harmonic functions, respectively. L denotes the channel length. In
the above given multi-path channel profile, L = 8. The qualities uk,l
are independent random variables, each with a uniform distribution
in the range (0, 1] for all k = 1, 2, . . . , L, and l = 1, 2, . . . , M. The
number of harmonic functions M is chosen to be 40. Plot the SER of
the system then compare with the result obtained from exercise 8.1.