Professional Documents
Culture Documents
Bi 1.1
% exercise1.1
% claulation of the probability density function (PDF) of a
Gaussian
% distributed random variable
clear;
t_a=0.05; %sampling interval
x= -4:t_a:4;
% Clauculation of the PDF of a Gaussian distributed random
variable
p=(1/sqrt(2*pi))*exp(-x.^2/2);
check=trapz(x,p); %integration of p
plot(x,p);
title('\fontsize{12}PDF of a Gaussian distributed random
variable');
xlabel('x','FontSize',12);
ylabel('P(x)', 'FontSize',12);
0.4
0.35
0.3
P(x)
0.25
0.2
0.15
0.1
0.05
0
-4
Bi 1.2
% E1.2
-3
-2
-1
0.4
theoretical
experimental
0.35
0.3
P(X)
0.25
0.2
0.15
0.1
0.05
0
-4
-3
-2
-1
0
X
Bi 2.1
% Bessel funtion-> time autocorrelation funtion of the mobile
channel
clear;
f_c=900e6;
%the carrier frequency in Hz
c_0=3e8;
%the speed of light in m/s
v=109.2e3/3600; %the mobile station's speed in m/s
f_m=v*f_c/c_0; %the maximum Doppler frequency
ohm_p=2;
%total received power
t=0:0.001:0.08; %the time interval in seconds
phi_gIgI=(ohm_p/2)*besselj(0,2*pi*f_m*t); %the autocorrelation
function
plot(t,phi_gIgI);
title('The autocorrelation function ACF');
xlabel('\tau');
ylabel('\phi_{gIgI}(\tau)');
legend('\phi_{gIgI}(\tau)');
phi_gIgI_0=(ohm_p/2)*besselj(0,0);
()
gIgI
0.8
0.4
gIgI
()
0.6
0.2
0
-0.2
-0.4
0.01
0.02
0.03
0.04
0.05
0.06
0.07
0.08
Bi 2.2
% Doppler spectrum
clear;
f_c=900e6;
%the carrier frequency in Hz
c_0=3e8;
%the speed of light in m/s
v=109.2e3/3600; %the mobile station's speed in m/s
f_m=v*f_c/c_0; %the maximum doppler frequency
ohm_p=2;
%the total receiver power
z=-100:1:100;
%the time interval in seconds
for i=1:201;
f=i-101;
if abs(f)<=f_m;
S_gIgI(i)=(ohm_p/2*pi*f_m)/sqrt(1-(f/f_m)^2);
else
S_gIgI(i)=0;
end
end
plot(z,S_gIgI);
title('The power spectral density (PSD)')
xlabel('f')
ylabel('S_{gIgI}(f)')
legend('S_{gIgI}(f)')
2000
SgIgI(f)
1800
1600
1400
SgIgI(f)
1200
1000
800
600
400
200
0
-100
-80
-60
-40
-20
0
f
20
40
60
80
100
Bi 2.3
% The Rice Distribution
clear;
k0=0;
k1=3;
k2=80;
k=k0;
%the rice factor k=s^2/2b_0
x=0:0.01:3;
%the time interval in seconds
ohm_p=1;
%the total received power
p_elfa=(2.*x.*(k+1)/ohm_p).*exp(-k((k+1).*x.^2/ohm_p)).*besseli(0,(2.*x.*sqrt(k*(k+1)/ohm_p)));
plot(x,p_elfa);
hold on
k=k1;
p_elfa1=(2.*x.*(k+1)/ohm_p).*exp(-k((k+1).*x.^2/ohm_p)).*besseli(0,(2.*x.*sqrt(k*(k+1)/ohm_p)));
plot(x,p_elfa1,'r.');
hold on
k=k2;
p_elfa2=(2.*x.*(k+1)/ohm_p).*exp(-k((k+1).*x.^2/ohm_p)).*besseli(0,(2.*x.*sqrt(k*(k+1)/ohm_p)));
plot(x,p_elfa2,'g-.');
title('The Rice Distribution');
xlabel('x');
ylabel('p_{\alpha}(x)')
legend('k=0','k=1','k=800');
hold of
The Rice Distribution
k=0
k=1
k=800
p(x)
0.5
1.5
x
2.5
Bi 2.4
% The non-central chi-square Distribution
k0=0;
k1=3;
k2=80;
k=k0;
%the rice factor k=s^2/2b_0
x=0:0.01:3;
%the time interval in seconds
ohm_p=1;
%the total received power
p_alpha=(k+1)/ohm_p.*exp(-k-((k+1).*x./ohm_p)).*besseli(0,
(2*sqrt(k*(k+1).*x./ohm_p)));
plot(x,p_alpha);
hold on
k=k1;
p_alpha1=(k+1)/ohm_p.*exp(-k-((k+1).*x./ohm_p)).*besseli(0,
(2*sqrt(k*(k+1).*x./ohm_p)));
plot(x,p_alpha1,'r.');
k=k2;
p_alpha2=(k+1)/ohm_p.*exp(-k-((k+1).*x./ohm_p)).*besseli(0,
(2*sqrt(k*(k+1).*x./ohm_p)));
plot(x,p_alpha,'g-');
title('The non-central chi-square Distribution')
xlabel('x')
ylabel('p_{\alpha^2}(x)')
legend('k=0','k=3','k=80')
hold of
k=0
k=3
k=80
0.9
0.8
0.7
p2(x)
0.6
0.5
0.4
0.3
0.2
0.1
0
0.5
1.5
x
2.5
Bi 3.1
% The level crossing rate of the Rice processes
clear;
k0=0;
k1=3;
k2=10;
R=0:0.05:4.5;
%the vector of amplitude levels
ohm_p=1;
%the total received power
rau=R./sqrt(ohm_p);
k=k0;
%the Rice factor k=s^2/2b_0
L_R=sqrt(2*pi*(k+1)).*rau.*exp(-k-(k+1).*rau.^2).*besseli(0,
(2.*rau.*sqrt(k*(k+1))));
plot(R,L_R);
hold on
k=k1;
L_R1=sqrt(2*pi*(k+1)).*rau.*exp(-k-(k+1).*rau.^2).*besseli(0,
(2.*rau.*sqrt(k*(k+1))));
plot(R,L_R1,'r.');
k=k2;
L_R2=sqrt(2*pi*(k+1)).*rau.*exp(-k-(k+1).*rau.^2).*besseli(0,
(2.*rau.*sqrt(k*(k+1))));
plot(R,L_R2,'k-');
title('The Level Crossing Rate (LCR)')
xlabel('R')
ylabel('L_R(R)/f_m')
legend('k=0','k=1','k=10')
hold of
1.4
k=0
k=1
k=10
1.2
LR(R)/fm
1
0.8
0.6
0.4
0.2
0
0.5
1.5
2.5
3.5
4.5
Bi 3.2
%The average duration of fading of the Rice process
clear;
k0=0;
k1=3;
k2=10;
R=0.0001:0.05:4.51;
%the vector of amplitude levels
ohm_p=1;
%the total received power
rau=R./sqrt(ohm_p);
k=k0;
%the rice factor k=s^2/2b_0
L_R=sqrt(2*pi*(k+1)).*rau.*exp(-k-(k+1).*rau.^2).*besseli(0,
(2.*rau.*sqrt(k*(k+1))));
for r=0:0.05:4.5
x=linspace(0,r);
a=0:0.05:r;
i=length(a);
p=(2.*x.*(k+1)/ohm_p).*exp(-k((k+1).*x.^2/ohm_p)).*besseli(0,(2.*x.*sqrt(k*(k+1)/ohm_p)));
CDF(i)=trapz(x,p);
end
ADF=CDF./L_R;
plot(R,ADF)
hold on
k=k1;
%the rice factor k=s^2/2b_0
L_R1=sqrt(2*pi*(k+1)).*rau.*exp(-k-(k+1).*rau.^2).*besseli(0,
(2.*rau.*sqrt(k*(k+1))));
for r=0:0.05:4.5
x=linspace(0,r);
a=0:0.05:r;
i=length(a);
p=(2.*x.*(k+1)/ohm_p).*exp(-k((k+1).*x.^2/ohm_p)).*besseli(0,(2.*x.*sqrt(k*(k+1)/ohm_p)));
CDF1(i)=trapz(x,p); %the integration of the p function
end
ADF1=CDF1./L_R1;
plot(R,ADF1,'r.')
hold on
k=k2;
%the rice factor k=s^2/2b_0
L_R2=sqrt(2*pi*(k+1)).*rau.*exp(-k-(k+1).*rau.^2).*besseli(0,
(2.*rau.*sqrt(k*(k+1))));
for r=0:0.05:4.5
x=linspace(0,r);
a=0:0.05:r;
i=length(a);
p=(2.*x.*(k+1)/ohm_p).*exp(-k((k+1).*x.^2/ohm_p)).*besseli(0,(2.*x.*sqrt(k*(k+1)/ohm_p)));
CDF2(i)=trapz(x,p); %the integration of the p function
end
ADF2=CDF2./L_R2;
plot(R,ADF2,'g-')
axis([0 2 0 3])
title('The average duration of fading (ADF)')
xlabel('R')
ylabel('t(R)*f_m')
legend('k=0','k=1','k=10')
hold of
k=0
k=1
k=10
2.5
t(R)*fm
1.5
0.5
0.2
0.4
0.6
0.8
1
R
1.2
1.4
1.6
1.8
Bi 3.31
% The Nakagami distribution
clear;
m1=0.5;
m2=1;
m3=4;
m4=20;
ohm_p=1;
x=0:0.05:3;
m=m1;
p_alpha1=(2*m^m.*x.^(2*m-1)/gamma(m)*ohm_p^m).*exp(m.*x.^2/ohm_p);
plot(x,p_alpha1)
hold on
m=m2;
p_alpha2=(2*m^m.*x.^(2*m-1)/gamma(m)*ohm_p^m).*exp(m.*x.^2/ohm_p);
plot(x,p_alpha2,'r.')
m=m3;
p_alpha3=(2*m^m.*x.^(2*m-1)/gamma(m)*ohm_p^m).*exp(m.*x.^2/ohm_p);
plot(x,p_alpha3,'g-')
m=m4;
p_alpha4=(2*m^m.*x.^(2*m-1)/gamma(m)*ohm_p^m).*exp(m.*x.^2/ohm_p);
plot(x,p_alpha4,'m--')
hold of
title('The Nakagami distribution p_{\alpha}(x)')
xlabel('x')
ylabel('p_{\alpha}(x)')
legend('m=0.5','m=1','m=4','m=20')
The Nakagami distribution p(x)
m=0.5
m=1
m=4
m=20
3.5
3
p(x)
2.5
2
1.5
1
0.5
0
0.5
1.5
x
2.5
Bi 3.32
% The Rice and Nakagami distribution
clear;
k=2;
x=0:0.01:3;
ohm_p=1;
p_elfa=(2.*x.*(k+1)/ohm_p).*exp(-k((k+1).*x.^2/ohm_p)).*besseli(0,(2.*x.*sqrt(k*(k+1)/ohm_p)));
plot(x,p_elfa)
hold on
m=1.8;
p_elfa1=(2.*m^m.*x.^(2*m-1)/gamma(m)*ohm_p^m).*exp(m.*x.^2/ohm_p);
plot(x,p_elfa1,'r-.')
hold of
title('The Rice & Nakagami distribution p_{\alpha}(x)')
xlabel('x')
ylabel('p_{\alpha}(x)')
legend('Rice p_{\alpha}(x) with k=2','Nakagami p_{\alpha}(x)
with m=1.8')
The Rice & Nakagami distribution p(x)
1.4
1.2
1
p(x)
0.8
0.6
0.4
0.2
0
0.5
1.5
x
Bi 4.1
% Calculation of simulator parameters
2.5
clear;
f_m=90;
b=1;
component
N1=9;
component
N2=10;
component
for n=1:1:N1;
c1(n)=sqrt(2*b/N1);
f1(n)=f_m*sin(pi*(n-0.5)/(2*N1));
th1(n)=2*pi*n/(N1+1);
end
for n=1:1:N2;
c2(n)=sqrt(2*b/N2);
f2(n)=f_m*sin(pi*(n-0.5)/(2*N2));
th2(n)=2*pi*n/(N2+1);
end
save ex4p1_Res f1 f2 c1 c2 th1 th2
% these result will be used in the exercises 4.3 and 4.4
Bi 4.2
% a function which creates the deterministic process g(t)
%Save this funtion to a file name "E4_2.m"
function y=E4_2(c,f,th,t);
y=zeros(size(t));
for n=1:length(f);
y=y+c(n)*cos(2*pi*f(n).*t+th(n));
end;
Bi 4.3
% Create a deterministic process by Rice method
clc;
clear;
load ex4p1_Res f1 f2 c1 c2 th1 th2
f_s=1*0.3125e6;
%the carrier frequency in Hz
T_sim=.4;
%simulation time in seconds
t=0:1/f_s:T_sim;
%discrete time interval
g1=E4_2(c1,f1,th1,t);
%generation of the process g1 by
using the function "E4_2.m" from E4.2
g2=E4_2(c2,f2,th2,t);
g=g1+j*g2;
g3=[];
%for t= 0:1/f_s:T_sim;
% g1=E4_2(c1,f1,th1,t);
%generation of the process g1
by using the function "E4_2.m" from E4.2
% g2=E4_2(c2,f2,th2,t);
% g=g1+j*g2;
% g3=[g3;g];
% h=mean(abs(g3));
% h_dB=20*log10(h);
%end
alpha=abs(g);
alpha_mean=mean(alpha);
alpha_mean_dB=20*log10(alpha_mean);
a=alpha_mean^2;
alpha_dB=20*log10(alpha);
plot(t,alpha_dB);
title('The channel amplitude in dB');
xlabel('t');
ylabel('\alpha(t)');
legend('\alpha(t) in dB',0);
10
0
-10
(t)
-20
-30
-40
(t) in dB
-50
-60
0.05
0.1
0.15
0.2
t
0.25
0.3
0.35
0.4
Bi 4.4
%Comparison of theoretical Gaussian and Rayleigh distribution
with
%simulation results
clear;
load ex4p1_Res f1 f2 c1 c2 th1 th2
f_s=50000;
%the carrier frequency in Hz
T_sim=20;
%simulation time in seconds
t=0:1/f_s:T_sim;
g1=E4_2(c1,f1,th1,t);
g2=E4_2(c2,f2,th2,t);
g=g1+j*g2;
alpha=abs(g);
g_mean=mean(g);
g_variance=var(g);
g1_mean=mean(g1);
g1_variance=var(g1);
alpha_mean=mean(alpha);
alpha_variance=var(alpha);
n=length(alpha);
x=0:0.1:4;
b=hist(alpha,x);
figure(1);
stem(x,b/n/(x(2)-x(1)));
hold on;
k=0;
%the rice factor k=s^2/2b_0
ohm_p=2;
%the total received power
p_alpha=(2.*x.*(k+1)/ohm_p).*exp(-k((k+1).*x.^2/ohm_p)).*besseli(0,(2.*x.*sqrt(k*(k+1)/ohm_p)));
plot(x,p_alpha,'r');
title('The PDF of alpha(x)');
xlabel('X');
ylabel('P_{\alpha}(x)');
legend('p_{\alpha}(x)','Rayleigh distribution (Theory)');
hold of;
figure(2);
n1=length(g1);
x1=-4:0.1:4;
%the time interval in seconds
c=hist(g1,x1);
stem(x1,c/n1/(x1(2)-x1(1)));
hold on;
p=(1/sqrt(2*pi))*exp(-x1.^2/2);
plot(x1,p,'r');
title('The PDF of g1 process')
xlabel('X');
ylabel('P_{g1}(x)');
legend('p_{g1}(x)','Gaussian distribution (Theory)');
hold of;
0.7
p(x)
Rayleigh distribution (Theory)
0.6
0.5
P(x)
0.4
0.3
0.2
0.1
0
0.5
1.5
2
X
2.5
3.5
0.4
pg1(x)
0.35
0.3
Pg1(x)
0.25
0.2
0.15
0.1
0.05
0
-4
Bi 4.5
-3
-2
-1
0
X
t=I1:T_s:I2;
g1=E4_2(c1,f1,th1,t);
phi_gIgI=xcorr(g1,'biased');
i=1:81;
x=(i-1)*T_s;
phi_gIgI_select=phi_gIgI(10001:10081);
plot(x,phi_gIgI_select);
title('The autocorrelation function ACF of g1');
xlabel('\tau in seconds');
ylabel('\phi_{gIgI}(\tau)');
legend('\phi_{gIgI}(\tau)of g1');
save ex4p5_Res phi_gIgI_select f_s;
The autocorrelation function ACF of g1
()of g1
gIgI
0.8
0.4
gIgI
()
0.6
0.2
0
-0.2
-0.4
0.01
0.02
0.03
0.04
in seconds
0.05
0.06
0.07
0.08
Bi 4.6
%Simulation result of ACF of g1 in comparison with theoretical
result
clear;
f_m=91;
%Maximum Doppler frequency
b=1;
N1=9;
%Number of sinusoids
tau_max=0.08;
t_a=0.001;
%Sampling interval
for n=1:N1;
c1(n)=sqrt(2*b/N1);
f1(n)=f_m*sin(pi*(n-0.5)/(2*N1));
th1(n)=2*pi*n/(N1+1);
end
tau=0:t_a:tau_max;
k=1:length(tau);
for n=1:N1
x(n,k)=(c1(n)^2/2)*cos(2*pi*f1(n).*tau);
end
fay=sum(x);
tau_s=-tau_max:t_a:tau_max;
k=1:length(tau_s);
for n=1:N1
xs(n,k)=(c1(n)^2/2)*cos(2*pi*f1(n).*tau_s);
end
phi_g1g1_theory=sum(xs);
plot(tau,fay);
hold on;
f_c=900e6;
%The carrier frequency in Hz
c_0=3e8;
%The speed of light in m/s
v=109.2e3/3600;
%The mobile station's speed in m/s
f_m=v*f_c/c_0;
%The maximum doppler frequency
ohm_p=2;
%The total received power
t=0:0.001:tau_max;
%The time interval in seconds
z=2*pi*f_m*t;
phi_gIgI=(ohm_p/2)*besselj(0,z); %The autocorrelation
function
plot(tau,phi_gIgI,'r');
load ex4p5_Res;
N=length(phi_g1g1_theory);
phi_g1g1_s=phi_g1g1_theory(N/2:N/2+tau_max/t_a);
plot(tau,phi_g1g1_s,'k.')
title('The autocorrelation function (ACF) of the process gI')
xlabel('\tau in seconds')
ylabel('\phi_{gIgI}(\tau)')
legend('\phi_{gIgI}(\tau) Simulation model
(Theory)','\phi_{gIgI}(\tau) Reference model','\phi_{gIgI}
(\tau)Simulation')
hold of
gIgI
() Reference model
gIgI
()Simulation
gIgI
gIgI
()
0.5
-0.5
0.01
0.02
0.03
0.04
in seconds
0.05
0.06
0.07
0.08
Bi 4.7
% Power spectral density (PSF)of the signal g(t)
clear;
f_m=91;
%Maximum Doppler frequency
b=1;
N1=9;
%Number of sinusoids
f_1_n=f_m*sin(pi*((1:N1)-1/2)/(2*N1));
c_1_n=sqrt(2*b/N1)*ones(size(f_1_n));
theta_1_n=2*pi*(1:N1)/(N1+1);
fs=1000;
%sampling frequency
t_sim=(10E3:20E3)/fs;
%time interval
g1_t_tilde=zeros(size(t_sim));
for k=1:length(f_1_n)
g1_t_tilde=g1_t_tilde+c_1_n(k)*cos(2*pi*f_1_n(k)*t_sim+theta_
1_n(k));
end
r_g1_g1=xcorr(g1_t_tilde,'biased');
PSD_S=ft(r_g1_g1);
len_S=length(PSD_S);
f_PSD=(-(len_S-1)/2:(len_S-1)/2)/len_S*fs;
plot(f_PSD,ftshift(abs(PSD_S)/len_S));
ax=axis; ax(1)=-100; ax(2)=100; ax(3)=0; ax(4)=0.03; axis(ax)
xlabel('Doppler frequency, f in Hz')
ylabel('PSD, S_{g_1 g_1}(f)')
0.03
0.025
PSD, Sg g (f)
1 1
0.02
0.015
0.01
0.005
0
-100
-80
-60
-40
-20
0
20
40
Doppler frequency, f in Hz
60
80
100
Bi 4.8
% Power spectral density (PSF)of the signal g(t)
clear;
f_m=91;
%Maximum Doppler frequency
b=1;
N1=9;
%Number of sinusoids
f_1_n=f_m*sin(pi*((1:N1)-1/2)/(2*N1));
c_1_n=sqrt(2*b/N1)*ones(size(f_1_n));
theta_1_n=2*pi*(1:N1)/(N1+1);
fs=1000;
%sampling frequency
t_sim=(10E3:20E3)/fs;
%time interval
g1_t_tilde=zeros(size(t_sim));
for k=1:length(f_1_n)
g1_t_tilde=g1_t_tilde+c_1_n(k)*cos(2*pi*f_1_n(k)*t_sim+theta_
1_n(k));
end
r_g1_g1=xcorr(g1_t_tilde,'biased');
PSD_S=ft(r_g1_g1);
len_S=length(PSD_S);
f_PSD=(-(len_S-1)/2:(len_S-1)/2)/len_S*fs;
plot(f_PSD,ftshift(abs(PSD_S)/len_S),'b--');
hold on
%Reference model
Omega_p=2;
f=(-f_m):1:(f_m);
S_f=Omega_p/2/pi/f_m./sqrt(1-(f/f_m).^2);
plot(f,S_f,'r-')
%Theorectical result of simulation model
f_tilde=[-f_1_n(N1:-1:1),f_1_n];
S_mm_tilde=[c_1_n(N1:-1:1).^2,c_1_n.^2]/4;
Stem(f_tilde,S_mm_tilde,'m:x')
hold of
ax=axis; ax(1)=-100; ax(2)=100; ax(3)=0; ax(4)=0.08; axis(ax)
legend('Simulation','Reference Model','Simulation Model')
0.08
Simulation
Reference Model
Simulation Model
0.07
PSD, Sg g (f)
1 1
0.06
0.05
0.04
0.03
0.02
0.01
0
-100
-80
-60
-40
-20
0
20
40
Doppler frequency, f in Hz
60
80
100
Bi 4.9
% Create a deterministic process by Rice method
clear;
load ex4p1_Res f1 f2 c1 c2 th1 th2
f_s=10000;
%the carrier frequency in Hz
T_sim=10;
%simulation time in seconds
t=0:1/f_s:T_sim;
%discrete time interval
g1=E4_2(c1,f1,th1,t);
%generation of the process g1 by
using the function "E4_2.m" from E4.2
g2=E4_2(c2,f2,th2,t);
g=g1+j*g2;
alpha=abs(g);
plot(t,alpha);
title('The channel amplitude in dB');
xlabel('t');
ylabel('\alpha(t)');
legend('\alpha(t)',0);
The channel amplitude in dB
4.5
(t)
4
3.5
(t)
3
2.5
2
1.5
1
0.5
0
5
t
10
Bi 4.10
clear;
f_m=91;
% Maximal Doppler frequency
b=1;
% Variance of in-phase or quadrature
component
N1=9;
% Number of sinusoids for the quadrature
component
R=0:0.05:4.5;
beta=0;
for n=1:1:N1;
c1(n)=sqrt(2*b/N1);
f1(n)=f_m*sin(pi*(n-0.5)/(2*N1));
beta=beta+2*pi^2*c1(n)^2*f1(n)^2;
end
LCR=sqrt(beta/(2*pi)).*(R/b).*exp(-R.^2/(2*b));
plot (R,LCR,'b');
hold on;
ohm_p=2;
%the total received power
rau=R./sqrt(ohm_p);
k=0;
%the Rice factor k=s^2/2b_0
L_R=sqrt(2*pi*(k+1)).*f_m*rau.*exp(-k(k+1).*rau.^2).*besseli(0,(2.*rau.*sqrt(k*(k+1))));
plot(R,L_R,'r.');
hold of
title('The Level Crossing Rate (LCR)')
xlabel('R')
ylabel('L_R(R)')
legend('LCR Simulation', 'LCR Rice Process')
The Level Crossing Rate (LCR)
100
LCR Simulation
LCR Rice Process
90
80
70
LR(R)
60
50
40
30
20
10
0
0.5
1.5
Bi 5.1
%QPSK modulation
clear;
x=round(rand(1,5000));
for i=1:2:length(x)
if x(i)==0 & x(i+1)==0
S((i+1)/2)=exp(j*pi/4);
else if x(i)==0 & x(i+1)==1
S((i+1)/2)=exp(j*3*pi/4);
else if x(i)==1 & x(i+1)==1
2.5
3.5
4.5
S((i+1)/2)=exp(j*5*pi/4);
else if x(i)==1 & x(i+1)==0
S((i+1)/2)=exp(j*7*pi/4);
end
end
end
end
end
save ex5p1_Res S x;
plot(S,'*');
hold on
t=0:0.01:2*pi;
plot(exp(j*t),'r--');
xlabel('\phi(t)');
ylabel('S_m');
title('The complex signal-space diagam for 4-QPSK');
1
0.8
0.6
0.4
Sm
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.8
-0.6
-0.4
-0.2
(t)
0.2
0.4
Bi 5.2
%QPSK modulation in presence of noise
0.6
0.8
clear;
load ex5p1_Res;
Es=var(S);
%symbol energy
Eb=Es/2;
%bit energy
SNR_db=6;
%signal to noise ratio in dB
N_0=Eb/10^(SNR_db/10);
N=sqrt(N_0/2)*(randn(size(S))+j*randn(size(S)));
R=S+N;
%add noise to the signal
plot(R,'.');
hold on
plot(S,'r*');
hold on
t=0:0.01:2*pi;
plot(exp(j*t),'r--');
legend('S_m','S');
xlabel('I');
ylabel('Q');
title('The complex signal-space diagam for 4-QPSK');
hold of
1.5
Sm
S
1
0.5
0
-0.5
-1
-1.5
-2
-2
-1.5
-1
-0.5
0.5
1.5
Bi 6.1
% Main function of the ex 6_1
clear all;
load ex5p1_Res S x;
% S: Tranmitted QPSK symbols
% x:transmitted bit sequence
SNR_db=0:2:8;
%signal to noise ration
for i=1:length(SNR_db)
c(i)=cha(SNR_db(i),S,x);
end
BEP=c/length(x);
semilogy(SNR_db,BEP,'.--')
title('The bit error probability')
xlabel('SNR in dB')
ylabel('P_b')
legend('p_b')
save ex6p1_Res c BEP
Bi 6.2
%Comparison of simulation result of bit error probability
(BEP)with
%theoretical results
clear;
SNR_db=0:8;
%Signal to noise ratio vector
SNR_db_simulation=0:2:8;
for i=1:length(SNR_db)
SNR(i)=10^(SNR_db(i)/10);
gamma_b(i)=SNR(i);
p_b(i)=erfc(sqrt(2*gamma_b(i))/sqrt(2))/2;
%BEP of QPSK
end
semilogy(SNR_db,p_b,'ro--')
hold on
load ex6p1_Res c BEP;
%simulation result from e6_1
semilogy(SNR_db_simulation,BEP,'x--')
title('The bit error probability')
xlabel('SNR in dB')
ylabel('P_b')
legend('Theory','Simulation')
hold of
-1
10
Theory
Simulation
-2
Pb
10
-3
10
-4
10
4
SNR in dB
Bi 6.3
clear;
load ex5p1_Res;
S=S(1:20000);
x=x(1:40000);
c1=sqrt(2*b/N1)*ones(size(f1));
th1=rand(size(f1))*2*pi;
f2=f_m*sin(pi/2/N2*((1:N2)-1/2));
c2=sqrt(2*b/N2)*ones(size(f2));
th2=rand(size(f2))*2*pi;
f_s=270800;
T_symb=1/f_s;
t=(0:length(S)-1)*T_symb;
g1=g(c1,f1,th1,t);
g2=g(c2,f2,th2,t);
g=g1+j*g2;
FS=g.*S;
gamma_average=2*b*10.^(SNR_db/10);
p_b=(1-sqrt(gamma_average./(1+gamma_average)))/2;
semilogy(SNR_db,p_b,'r.--')
hold on
load ex6p3_Res BEP
semilogy(SNR_db,BEP,'bo')
hold of
title('BEP of slow flat Rayleigh fading channel')
xlabel('\gamma_b')
ylabel('P_b')
legend('BEP of QPSK over a fading channel(Theory)','-(Simulator)')
10
Pb
10
-2
10
-3
10
-4
10
10
Bi 7
%Main program of Ex7
clear;
k=3;
R_c=1/2;
%bit source
15
20
25
30
meg=round(rand(1,5000));
%Convolution coder
conlen=3;
%constrainlength=k=1+v,v=number of shift registers
codegen=[7 5];
%codegenerator g(1)=(1,1,1)>7, g(2)=(1,0,1)->5
trellis=poly2trellis(conlen,codegen);
x=convenc(meg,trellis);
%the coded bit stream
%QPSK modulation
for i=1:2:length(x)
if x(i)==0&x(i+1)==0
S((i+1)/2)=exp(j*pi/4);
elseif x(i)==0&x(i+1)==1
S((i+1)/2)=exp(j*3*pi/4);
elseif x(i)==1&x(i+1)==1
S((i+1)/2)=exp(j*5*pi/4);
elseif x(i)==1&x(i+1)==0
S((i+1)/2)=exp(j*7*pi/4);
end
end
%S is the modulated complex signal
SNR_db=0:5;
for i=1:length(SNR_db)
c(i)=cha2(SNR_db(i),S,meg,trellis);
end
BEP=c/length(meg);
semilogy(SNR_db,BEP,'.--');
hold on
SNR_db=0:2:8;
load ex6p1_Res
BEP2=c/length(x);
semilogy(SNR_db,BEP2,'r.--');
title('The bit error probability')
xlabel('SNR in db')
ylabel('P_b')
legend('P_b with coder','P_b without coder')
hold of
-1
10
Pb with coder
Pb without coder
-2
Pb
10
-3
10
-4
10
4
SNR in db
Bi 8.1
%Main function of ex8_1
clear all;
NFFT=64;
%FFT length
G=9;
%Guard interval length
M_ary=16;
%Multilevel of M-ary symbol
t_a=50*10^(-9);
%Sampling duration of
HiperLan/2
%load rho.am-ascii;
%load discrete multi-path
channel profile
rho=[1, 0.6095, 0.4945, 0.3940, 0.2371, 0.19, 0.1159, 0.0699,
0.0462];
h=sqrt(rho);
N_P=length(rho);
H=ft([h,zeros(1,NFFT-N_P)]);
NofOFDMSymbol=100;
%Number of OFDM symbols
length_data=(NofOFDMSymbol)*NFFT; %The total data length
%Source bites
source_data=randint(length_data,sqrt(M_ary));
%Receiver
Receiver_Data=[];
received data symbols
d=[];
%Demodulated symbols
data_symbol=[];
for i=1:NofOFDMSymbol;
if(N_P>G+1)&(i>1)
previous_symbol=rs_frame(i-1,:); %previous OFDM
symbol
ISI_term=previous_symbol(NFFT+2*G+1:NFFT+G+N_P1);
ISI=[ISI_term,zeros(1,length(previous_symbol)length(ISI_term))];
rs_i=rs_frame(i,:)+ISI;
%the ISI term is added to
the current OFDM symbol
else
rs_i=rs_frame(i,:);
end;
%OFDM demodulator
Demodulated_signal_i=OFDM_Demodulator(rs_i,NFFT,NFFT,G);
%OFDM Equalization
d=Demodulated_signal_i./H;
demodulated_symbol_i= ddemodce(d,1,1,'QAM',M_ary);
data_symbol=[data_symbol, demodulated_symbol_i];
end;
data_symbol= data_symbol';
%calculation of error symbols
[number, ratio]=symerr(symbols, data_symbol);
ser=[ser, ratio];
end;
snr=snr_min:step:snr_max;
semilogy(snr,ser,'bo');
ylabel('SER');
xlabel('SNR in dB');
save e8p1_Res snr ser;
10
-1
SER
10
-2
10
-3
10
10
SNR in dB
15
20
25
Bi 8.2
load e8p1_Res snr ser;
semilogy(snr,ser,'bo');
hold on
%Main function of ex8_1
clear all;
NFFT=64;
%FFT length
G=0;
%Guard interval length
M_ary=16;
%Multilevel of M-ary symbol
t_a=50*10^(-9);
%Sampling duration of
HiperLan/2
%load rho.am-ascii;
%load discrete multi-path
channel profile
rho=[1, 0.6095, 0.4945, 0.3940, 0.2371, 0.19, 0.1159, 0.0699,
0.0462];
h=sqrt(rho);
N_P=length(rho);
H=ft([h,zeros(1,NFFT-N_P)]);
NofOFDMSymbol=100;
%Number of OFDM symbols
length_data=(NofOFDMSymbol)*NFFT; %The total data length
%Source bites
source_data=randint(length_data,sqrt(M_ary));
%bit to symbol coder
symbols=bi2de(source_data);
%QAM modulator in base band
QAM_Symbol=dmodce(symbols,1,1,'qam',M_ary);
%Preparing data pattern
Data_Pattern=[];
%Transmitted signal before IFFT
for i=0:NofOFDMSymbol-1;
QAM_tem=[];
for n=1:NFFT;
QAM_tem=[QAM_tem,QAM_Symbol(i*NFFT+n)];
end;
Data_Pattern=[Data_Pattern;QAM_tem];
clear QAM_tem;
end
ser=[];
%set the counter of symbol error ratio
to be a empty vector
snr_min=0;
snr_max=25;
step=1;
for snr=snr_min:step:snr_max;
snr=snr-10*log10((NFFT+G)/NFFT); %Miss matching efect
rs_frame=[];
%A matrix of received signal
for i=0:NofOFDMSymbol-1;
%OFDM modulator
OFDM_signal_tem=OFDM_Modulator(Data_Pattern(i+1,:),NFFT,
G);
%The received signal over multi-path channel is created
by a
%convolutional operation
rs=conv(OFDM_signal_tem,h);
%Additive noise is added
rs=awgn(rs,snr,'measured','dB');
rs_frame=[rs_frame;rs];
clear OFDM_signal_tem;
end;
%Receiver
Receiver_Data=[];
received data symbols
d=[];
%Demodulated symbols
data_symbol=[];
for i=1:NofOFDMSymbol;
if(N_P>G+1)&(i>1)
previous_symbol=rs_frame(i-1,:); %previous OFDM
symbol
ISI_term=previous_symbol(NFFT+2*G+1:NFFT+G+N_P1);
ISI=[ISI_term,zeros(1,length(previous_symbol)length(ISI_term))];
rs_i=rs_frame(i,:)+ISI;
%the ISI term is added to
the current OFDM symbol
else
rs_i=rs_frame(i,:);
end;
%OFDM demodulator
Demodulated_signal_i=OFDM_Demodulator(rs_i,NFFT,NFFT,G);
%OFDM Equalization
d=Demodulated_signal_i./H;
demodulated_symbol_i= ddemodce(d,1,1,'QAM',M_ary);
data_symbol=[data_symbol, demodulated_symbol_i];
end;
data_symbol= data_symbol';
%calculation of error symbols
[number, ratio]=symerr(symbols, data_symbol);
ser=[ser, ratio];
end;
snr=snr_min:step:snr_max;
semilogy(snr,ser,'*--');
hold of;
ylabel('SER');
xlabel('SNR in dB');
10
-1
SER
10
-2
10
-3
10
10
SNR in dB
15
20
25
Bi 8.3
%Main function: OFDM system over a time-variant channel
clear all;
NFFT=64;
G=9;
M_ary=16;
t_a=50*10^(-9);
%load rho.am-ascii;
rho=[1, 0.6095, 0.4945, 0.3940, 0.2371, 0.19, 0.1159, 0.0699];
N_P=length(rho);
%Parameters for Monte Carlo channel
symbol_duration=NFFT*t_a;
number_of_summations=40;
%Number of summations for Monte-Carlo method
f_dmax=50;
NofOFDMSymbol=100;
length_data=(NofOFDMSymbol)*NFFT;
%Source bites
source_data=randint(length_data,sqrt(M_ary));
%bit to symbol coder
symbols=bi2de(source_data);
%QAM modulation in base band
QAM_Symbol=dmodce(symbols,1,1,'qam',M_ary);
%Preparing data pattern
Data_Pattern=[];
for i=0:NofOFDMSymbol-1;
QAM_tem=[];
for n=1:NFFT;
QAM_tem=[QAM_tem,QAM_Symbol(i*NFFT+n)];
end;
Data_Pattern=[Data_Pattern;QAM_tem];
clear QAM_tem;
end;
Number_Relz=50;
ser_relz=[];
for number_of_relialization=1:Number_Relz;
u=rand(N_P,number_of_summations);
%A random variable for Monte-Carlo method
ser=[];
snr_min=0;
snr_max=25;
step=1;
for snr=snr_min:step:snr_max;
snr=snr-10*log10((NFFT+G)/NFFT);
%Miss matching efect caused by using guard interval
rs_frame=[];
h_frame=[];
initial_time=0;
for i=0:NofOFDMSymbol-1;
%OFDM modulation
OFDM_signal_tem=OFDM_Modulator(Data_Pattern(i+1,:),NFFT,
G);
[h, t]=MCM_channel_model(u, initial_time,
number_of_summations, symbol_duration, f_dmax, rho);
h_frame=[h_frame; h];
%The received signal over multipath channel is created
by a
%convolutional operation
rs=conv(OFDM_signal_tem,h);
%Additive noise is added
rs=awgn(rs,snr,'measured','dB');
rs_frame=[rs_frame;rs];
initial_time=t;
clear OFDM_signal_tem;
end;
%Receiver
Receiver_Data=[];
d=[];
data_symbol=[];
for i=1:NofOFDMSymbol;
if (N_P>G+1)&(i>1)
previous_symbol=rs_frame(i-1,:);
ISI_term=previous_symbol(NFFT+2*G+1:NFFT+G+N_P-1);
ISI=[ISI_term,zeros(1,length(previous_symbol)length(ISI_term))];
rs_i=rs_frame(i,:)+ISI;
else
rs_i=rs_frame(i,:);
end;
%OFDM demodulator
Demodulated_signal_i=OFDM_Demodulator(rs_i,NFFT,NFFT,G);
%OFDM Equalization
h=h_frame(i,:);
H=ft([h,zeros(1,NFFT-N_P)]);
d=Demodulated_signal_i./H;
demodulated_symbol_i=ddemodce(d,1,1,'QAM',M_ary);
data_symbol=[data_symbol, demodulated_symbol_i];
end;
data_symbol=data_symbol';
%Calculation of error symbols
[number, ratio]=symerr(symbols, data_symbol);
ser=[ser, ratio];
end;
ser_relz=[ser_relz;ser];
end;
ser=sum(ser_relz)/Number_Relz;
snr=snr_min:step:snr_max;
semilogy(snr,ser,'bo');
hold on
%Parameters for Monte Carlo channel
symbol_duration=NFFT*t_a;
number_of_summations=40;
%Number of summations for Monte-Carlo method
f_dmax=0;
NofOFDMSymbol=100;
length_data=(NofOFDMSymbol)*NFFT;
%Source bites
source_data=randint(length_data,sqrt(M_ary));
%bit to symbol coder
symbols=bi2de(source_data);
%QAM modulation in base band
QAM_Symbol=dmodce(symbols,1,1,'qam',M_ary);
%Preparing data pattern
Data_Pattern=[];
for i=0:NofOFDMSymbol-1;
QAM_tem=[];
for n=1:NFFT;
QAM_tem=[QAM_tem,QAM_Symbol(i*NFFT+n)];
end;
Data_Pattern=[Data_Pattern;QAM_tem];
clear QAM_tem;
end;
Number_Relz=50;
ser_relz=[];
for number_of_relialization=1:Number_Relz;
u=rand(N_P,number_of_summations);
%A random variable for Monte-Carlo method
ser=[];
snr_min=0;
snr_max=25;
step=1;
for snr=snr_min:step:snr_max;
snr=snr-10*log10((NFFT+G)/NFFT);
%Miss matching efect caused by using guard interval
rs_frame=[];
h_frame=[];
initial_time=0;
for i=0:NofOFDMSymbol-1;
%OFDM modulation
OFDM_signal_tem=OFDM_Modulator(Data_Pattern(i+1,:),NFFT,
G);
[h, t]=MCM_channel_model(u, initial_time,
number_of_summations, symbol_duration, f_dmax, rho);
h_frame=[h_frame; h];
%The received signal over multipath channel is created
by a
%convolutional operation
rs=conv(OFDM_signal_tem,h);
%Additive noise is added
rs=awgn(rs,snr,'measured','dB');
rs_frame=[rs_frame;rs];
initial_time=t;
clear OFDM_signal_tem;
end;
%Receiver
Receiver_Data=[];
d=[];
data_symbol=[];
for i=1:NofOFDMSymbol;
if (N_P>G+1)&(i>1)
previous_symbol=rs_frame(i-1,:);
ISI_term=previous_symbol(NFFT+2*G+1:NFFT+G+N_P-1);
ISI=[ISI_term,zeros(1,length(previous_symbol)length(ISI_term))];
rs_i=rs_frame(i,:)+ISI;
else
rs_i=rs_frame(i,:);
end;
%OFDM demodulator
Demodulated_signal_i=OFDM_Demodulator(rs_i,NFFT,NFFT,G);
%OFDM Equalization
h=h_frame(i,:);
H=ft([h,zeros(1,NFFT-N_P)]);
d=Demodulated_signal_i./H;
demodulated_symbol_i=ddemodce(d,1,1,'QAM',M_ary);
data_symbol=[data_symbol, demodulated_symbol_i];
end;
data_symbol=data_symbol';
%Calculation of error symbols
[number, ratio]=symerr(symbols, data_symbol);
ser=[ser, ratio];
end;
ser_relz=[ser_relz;ser];
end;
ser=sum(ser_relz)/Number_Relz;
snr=snr_min:step:snr_max;
semilogy(snr, ser, '*--');
hold of
ylabel('SER');
xlabel('SNR in dB');
legend('time-variant', 'time-invariant');
10
SER
time-variant
time-invariant
-1
10
-2
10
10
SNR in dB
15
20
25