You are on page 1of 246

Page 1 of 246

Solutions Manual
to
Introduction to Wireless Systems
P. M. Shankar
Drexel University
Page 2 of 246
The solutions manual contains the m-files, charts, graphs, and numerical values for the problems
in the book. The m-files have comment statements making it easy for the reader to understand
the programs. Some of the programs are a little bit too long and can be shortened if necessary.
Since the book grew out of my course offered from 1997, a few of the m-files are based on
MATLAB 5. Most of the m-files, however, use MATLAB 6 and therefore may be a bit shorter
and more efficient. Statistics and Signal Processing Toolboxes have been used extensively.
Imaging Processing Toolboxes and Communication toolbox have been used sparingly.
Every effort has been made to ensure that errors are minimized. If you do find an error, I would
greatly appreciate if you could notify me.
Sincerely
P. M. Shankar
September 4, 2001
Page 3 of 246
Chapter 2......................................................................................................................................... 4
Chapter 3....................................................................................................................................... 68
Chapter 4..................................................................................................................................... 164
Chapter 5..................................................................................................................................... 181
Chapter 6..................................................................................................................................... 221
Page 4 of 246
Chapter 2
Problem 1 Powerlawprofiles.m
clear
%powerlawprofiles.m; calculates the powerloss as per inverse square law and 1/d^n.
close all
nu=[2 3 3.5 4];%four values of the loss parameter
for k=1:4;
n=nu(k);
d=1:50;% distance in Km
d1=d.^n;
dn=1./d1;
pn=-10.*log10(dn);%inverse law
plot(d,pn,'k');
xlabel('distance in Km');
ylabel('powerloss in dB');
hold on
end;
Page 5 of 246
Problem 2 From the book, eqn. (2.2) is
2 2
2 2 2
1000 2 1
16 16 3 5000
r r t
d
P GG
P
L d

_ _



, ,
.
The wavelength
1
3
m
_


,
.
8
5.6 10 72.5
d
P dBm

.
Problem 3& 4 hataloss.m
clear
% hataloss.m Power loss calculations
carf=input('enter carrier freq. in MHZ...>>');
lcrf=log10(carf);
ht=input('enter the height of BS antenna in meters..>>');%height in meters of the BS
lht=log10(ht);
hr=input('enter the height of the MU antenna in meters..>>');%MU ant. height in meters
lhr=log10(11.75*hr);
N=60;%number of increments for distance
distmax=30;%coverage distance in Kms
for kk=1:1:59;
d(kk)=1+0.5*(kk-1);
fact1=69.55+26.16*lcrf-13.83*lht;
fact2=(44.9-6.55*lht)*log10(d(kk));
fftq=fact1+fact2;
%antenna correction factor MU...
ahr=3.2*(lhr)^2-4.97;% large cities; freq. above 400 MHz
amr=(1.1*lcrf-0.7)*hr-(1.56*lcrf-0.8);
alar(kk)=fftq-ahr;
amed(kk)=fftq-amr;
asub(kk)=amed(kk)-2*(log10(carf/28)).^2-5.4;
arur(kk)=amed(kk)-4.78*(lcrf.^2)+18.33*lcrf-40.94;
end;
subplot(2,2,1);
plot(d,alar);
xlabel('distance Km');
ylabel('power loss dB');
title('large city');
subplot(2,2,2);
plot(d,amed);
%axis([1 30 -140 -60]);
xlabel('distance Km');
ylabel('power loss dB');
title('medium city');
subplot(2,2,3);
Page 6 of 246
plot(d,asub);
%axis([1 30 -140 -60]);
xlabel('distance Km');
ylabel('power loss dB');
title('suburban');
subplot(2,2,4);
plot(d,arur);
%axis([1 30 -140 -60]);
xlabel('distance Km');
ylabel('power loss dB');
title('rural');
%loss at a reference distance of 100 m
Wave=3e8/900e6;%wavelength in meters
PL=10*log10((4*pi*100)^2/Wave^2);%relative loss at 100 meters
d3=d(3)*1000;%distance in meters
%use eqn. (2.19)
denom=10*log10(d3/100);%denominator of eqn. (2.19)
nuLarge=(alar(3)-PL)/denom%nu for large city
nuMed=(amed(3)-PL)/denom%nu for med city
nuSub=(asub(3)-PL)/denom%nu for suburbs city
nuRur=(arur(3)-PL)/denom%nu for rural city
Page 7 of 246
Large = 4.1865
Med = 4.1801
Sub =3.4159
Rur =1.9890
Problem 5.fadcom.m
clear
%fadcom.m simulates Doppler fading including a carrier frequency and then demodulate
%uses random phase model for both Rayleigh and Rician fading
% also computes the outage probability
fc=900e3;%carrier frequency
ppf=2*pi*fc;
N=11;% Number of mutiple paths
fd=input('enter the Doppler shift...')
ppw=2*pi*fd;
%scattering strengths are considered to be Gamma distributed
Page 8 of 246
fs=4*fc;%sampling rate
Ts=1/fs;
t = [0:Ts:1999*Ts]; %time array
nn=length(t);
ci=zeros(1,nn); %received signal (Rayleigh
for m=1:N;
a = gamrnd(1.4,1,1,nn);
ppwt=ppw*unifrnd(0,2*pi,1,nn);
ci = ci + a.*cos((ppf+ppwt).*t+ppwt+unifrnd(0,2*pi,1,nn));
end;
cr=ci;
crr=ci+2*cos(ppf*t);%generates Rician
[x,y]=demod(cr,fc,fs,'qam');
[xr,yr]=demod(crr,fc,fs,'qam');
ae=(1/N)*sqrt(x.^2+y.^2);
aer=(1/N)*sqrt(xr.^2+yr.^2);
pha=pi+angle(x+i*y);%phase to be centered around 2*pi
figure
subplot(2,1,1)
plot(t*1e3,cr),title('Rayleigh fading')
xlabel('time ms')
ylabel('rf signal volt')
xlim([0 .1])
aes=20*log10(ae);
subplot(2,1,2)
plot(t*1e3,aes),title('Rayleigh fading')
xlabel('time ms')
ylabel('relative power dB')
xlim([0 .1])
figure
subplot(2,1,1)
plot(t*1e3,crr),title('Rician fading')
xlabel('time ms')
ylabel('rf signal volt')
xlim([0 .1])
aerr=20*log10(aer);
subplot(2,1,2)
plot(t*1e3,aerr),title('Rician fading')
xlabel('time ms')
ylabel('relative power dB')
xlim([0 .1])
fractra=0.0;
for mf=1:nn;
Page 9 of 246
if aes(mf)<=-10
fractra=fractra+1;
else
end;
end;
outageRayl=fractra/nn
fractrc=0.0;
for mf=1:nn;
if aerr(mf)<=-10
fractrc=fractrc+1;
else
end;
end;
outageRice=fractrc/nn
Problem 6.fadingsim.m
Page 10 of 246
clear
%fadingsim.m simulates fading including a carrier frequency and then demodulate
%uses random phase model as well as random delay
fc=900e3;%carrier frequency
ppf=2*pi*fc;
N=11;% Number of mutiple paths
%a are considered to be Gamma distributed
fs=4*fc;%sampling rate
Ts=1/fs;
t = [0:Ts:1999*Ts]; %time array
nn=length(t);
ci=zeros(1,nn); %received signal (Rayleigh
nn=length(t);
dist=1000;%distance between transmit and receive in meters
avdel=dist/3e8%average delay in seconds
ci=zeros(1,nn);
cir=zeros(1,nn);
cit=0.0;%this uses a delay instead of Uniform phase
for m=1:N;
phterm=unifrnd(0,2*pi,1,nn);
delay=avdel+(-0.5+unifrnd(0,2*pi,1,nn))*avdel;%uniform delay with a mean of avdel
a = gamrnd(1.4,1,1,nn);
ci=ci+a.*cos(ppf*t+phterm);%Rayleigh
%following term generates the received signal with delay format
cit=cit+a.*cos(ppf*t+delay);
end;
crr=cit+2*cos(ppf*t);%rician
[x,y]=demod(ci,fc,fs,'qam');
[xt,yt]=demod(cit,fc,fs,'qam');
[xr,yr]=demod(crr,fc,fs,'qam');
ae=(1/N)*sqrt(x.^2+y.^2);
aet=(1/N)*sqrt(xt.^2+yt.^2);
aer=(1/N)*sqrt(xr.^2+yr.^2);
pha=pi+angle(x+i*y);%phase to be centered around 2*pi
phat=pi+angle(xt+i*yt);%phase of the delay version
figure
subplot(2,2,1)
plot(t*1e3,ci),title('random phase: Rayleigh');
xlabel('time ms')
ylabel('rf signal volt')
xlim([0 0.1])
subplot(2,2,2)
Page 11 of 246
plot(t*1e3,ae),title('random phase:Rayleigh');
xlabel('time ms')
ylabel('envelope volt')
xlim([0 0.1])
subplot(2,2,3)
plot(t*1e3,cit),title('random delay:Rayleigh');
xlabel('time ms')
ylabel('rf signal volt')
xlim([0 0.1])
subplot(2,2,4)
plot(t*1e3,aet),title('random delay:Rayleigh');
xlabel('time ms')
ylabel('envelope volt')
xlim([0 0.1])
figure
subplot(2,2,1)
plot(t*1e3,crr),title('Rician')
xlabel('time ms')
ylabel('rf signal volt')
xlim([0 0.1])
subplot(2,2,2)
plot(t*1e3,aer),title('Rician')
xlabel('time ms')
ylabel('envelope volt')
xlim([0 0.1])
subplot(2,2,4)
hist(aer),title('envelope histogram-Rician fading')
subplot(2,2,3);
hist(aet),title('envelope histogram-Rayleigh(delay)')
Page 12 of 246
Problem 7.rayexp.m
clear
%rayexp.m
%compares the Rayleigh and exponential
%verifies that if the envelope is Rayleigh, power is exponentially distributed
x=raylrnd(1,1,1000);%1000 Rayleigh random numbers
%%%It is also possible to generate Rayleigh random numbers directly from uniform random
numbers
%%%%%%%%%%%
%xu=rand(1,1000);%1000 Uniform rand numbers
%x=1.0*sqrt(-log(xu));
%%%%%%%%%%%%
xmean=mean(x);%mean
xstd=std(x);%stdev
y=x.^2;%generates exponentially distributed set
subplot(2,1,1)
hist(x),title('histogram of Rayleigh')
subplot(2,1,2)
Page 13 of 246
hist(y),title('histogram of exponential');
ymean=mean(y)
ystd=std(y)
ratio_Rayl=xmean/xstd
ratio_exp=ymean/ystdratio_Rayl=xmean/xstd
ratio_exp=ymean/ystd
ratio_Rayl = 1.8818
ratio_exp = 0.9684
Problem 8.fadcom
outageRayl =
0.2945
Problem 9.fadcom
Page 14 of 246
Problem 10.fadcom.m
outageRayl =
0.2945
outageRice =
0.2500
Problem 11. If the signal is Rayleigh faded, the power is exponentially distributed.
Therefore, the outage probability P
out
is given by
0
1 exp
T
out
Z
P
Z
_


,
where Z
0
is the average power and Z
T
is the threshold power.
Z
0
=10 dBm 10 mW
Page 15 of 246
Z
T
=0 dBm 1 mW
Outage Probability =
1
1 exp 0.271
10
_


,
.
Problem 12
{ }
1
Prob SNR<0dB 1 exp
2
1 _

1
,
]
= 03935.
Problem 13. Threshold = 25-10=15 dB or 10
1.5
.
Mean SNR = 25 dB or 10
2.5
.
1.5
2.5
10
1 exp 0.0952
10
out
P
_


,
.
Problem 14. Threshold = 5 dB or 10
.5
.
.5
0
10
0.02 1 exp
out
P
Z
_


,
where Z
0
is the average SNR.
( )
.5
0
10
156.5 22
log .98
e
Z dB

Problem 15. fadingsim.m


Page 16 of 246
Problem 16.
.001 0 1 .1 3 1 4 .1
2.8926
.01 .1 1 .1
s
+ + +

+ + +
.
2 2
2 2
.001 0 1 .1 3 1 4 .1
8.84
.01 .1 1 .1
s
+ + +

+ + +
2
2
. . 0.6898 rmsdel ay s
Coherence BW =290 KHz.
Problem 17.
a.
60 1 85 .1 110 .01
62.7
.01 .1 1
ns
+ +

+ +
Page 17 of 246
2 2 2
2 2
60 1 85 .1 110 .01
4000
.01 .1 1
ns
+ +

+ +
2
2
. . 8.48 rmsdel ay ns
b.
0 .01 4 .1 8 1
7.57
.01 .1 1
s
+ +

+ +
2 2 2
2 2
0 .01 4 .1 8 1
59.1
.01 .1 1
s
+ +

+ +
2
2
. . 1.36 rmsdel ay s
The response represented by (a) is an indoor channel response while the response represented by
(b) is an outdoor channel one.
Problem 18. hatalog.m
clear
% hatalog.m Power loss calculations
%incluse a plot of the lognormal fading suprimposed
close all
Pt=30;%power in dBm transmitted 1W
carf=input('enter carrier freq. in MHZ...>>');
lcrf=log10(carf);
ht=input('enter the height of BS antenna in meters..>>');%height in meters of the BS
lht=log10(ht);
hr=input('enter the height of the MU antenna in meters..>>');%MU ant. height in meters
lhr=log10(11.75*hr);
N=60;%number of increments for distance
distmax=30;%coverage distance in Kms
for kk=1:1:39;
d(kk)=1+0.5*(kk-1);
fact1=69.55+26.16*lcrf-13.83*lht;
fact2=(44.9-6.55*lht)*log10(d(kk));
fftq=fact1+fact2;
%antenna correction factor MU...
ahr=3.2*(lhr)^2-4.97;% large cities; freq. above 400 MHz
amr=(1.1*lcrf-0.7)*hr-(1.56*lcrf-0.8);
alar(kk)=Pt-(fftq-ahr);
Page 18 of 246
amed(kk)=Pt-(fftq-amr);
asub(kk)=Pt-(fftq-ahr-2*(log10(carf/28)).^2-5.4);
arur(kk)=Pt-(fftq-ahr-4.78*(lcrf.^2)+18.33*lcrf-40.94);
xlar(kk)=alar(kk)+normrnd(0,10);%10 dB std deviation for big city with mean equal to the
received power
xmed(kk)=amed(kk)+normrnd(0,8);%8 dB std deviation for med city
xsub(kk)=asub(kk)+normrnd(0,4);%4 dB std deviation
xrur(kk)=arur(kk)+normrnd(0,3);%3 dB std deviation
end;
subplot(2,2,1)
plot(d,alar,d,xlar);
xlabel('distance Km');
xlim([2 20])
ylabel('Received Power dBm');
title('large city');
subplot(2,2,2)
plot(d,amed,d,xmed);
%axis([1 30 -140 -60]);
xlabel('distance Km');
xlim([2 20])
ylabel('Received Power dBm');
title('medium city');
subplot(2,2,3)
plot(d,asub,d,xsub);
%axis([1 30 -140 -60]);
xlabel('distance Km');
xlim([2 20])
ylabel('Received Power dBm');
title('suburban');
subplot(2,2,4)
plot(d,arur,d,xrur);
%axis([1 30 -140 -60]);
xlabel('distance Km');
xlim([2 20])
Page 19 of 246
ylabel('Received Power dBm');
title('rural');
Problem 19. rice.m
clear;
close all
%rice.m
%generates a Rician distribution
for kr=1:10
rpara=input('mean of the Gaussian to create Rician...>');
rp2=rpara^2;
n=1000;%number of samples
x=normrnd(0,1,1,1000);
xx=normrnd(rpara,1,1,1000);
ac=x.^2+xx.^2;
r=sqrt(ac);%rician variable
ax=0.:0.2:20;% range of values for the histogram
figure
Page 20 of 246
yy=hist(r,ax);
%hist(r,ax),title('histogram of Rician Distribution');
ax1=rp2+ax.^2;
bes1=besseli(0,ax*rpara);
y=ax.*bes1.*exp(-ax1/2);
plot(ax,yy/max(yy),'+',ax,y/max(y))
legend('histogram','pdf')
xf=input('enter 1 for another mean and 0 to stop..>>');
if xf==0
break
else
end;
end;
Page 21 of 246
You can verify that the numbers are Rician distributed by conducting a chi-square test using the
following MATALB program.
function [q]=chirice(x,mm);
%data, and bins
%does the chi-square testing of the data to see Ricain is a fit.
xx=sort(x);
%using the moments of the data estimate the two parameters
a4=mean(xx.^4);
my=mean(xx.^2);
a = (2*my*my-a4)^0.25; %Rician parameter
b=sqrt(0.5*(my-a^2));
inter = max(xx) - min(xx); %interval for chi-square test
intstep = inter/mm; %size of sub-interval
intval = [min(xx):intstep:max(xx)]; %samples at the sub-intervals
k = [zeros(1,mm)]; %number of samples in each sub-interval
%counting the samples in each sub-interval
for i = 1:length(xx)
for j = 1:mm
Page 22 of 246
if xx(i) <= intval(j+1)
k(j) = k(j) + 1;
break;
end;
end;
end;
Fy=1-marcumq(a/b,intval/b);%CDF uses marcumq function from Communications Toolbox
p = zeros(1,mm);
for i = 1:mm
p(i) = Fy(i+1) - Fy(i); %probabilities at the sub-interval samples
end;
np = p.*length(xx);
q = 0;
for i = 1:mm
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
Problem 20 . ricetoNakagami.m
The Nakagami pdf is given by ( )
( )
( ) ( )
2 1
2 2
exp
m m
m
m x m
m
f x x U x


. When m=1, this equation
becomes ( ) ( ) ( )
2 2
2
exp
x x
f x U x

, the Rayleigh density function. Rician becomes Rayleigh
when the Rician parameter K(dB) .
clear
%ricetoNakagami.m
%generates a Rician distribution, estimates the Nakagami parameter to show that
%m>1 for Rician
for kk=1:21
rr(kk)=(kk-1)*0.2;%A0 value of the Rician
r0=rr(kk);
x=randn(1,1000);%1000 Gaussian random numbers
xx=randn(1,1000);%1000 Gaussian random numbers
x1=xx+r0;%Gaussian with different means
a=sqrt(x1.^2+x.^2);%calculate the envelope
hist(a),title('histogram of Rician Distribution');
r2=mean(a.^2);
Page 23 of 246
r4=mean(a.^4);
m(kk)=r2^2/(r4-r2^2);
end;
figure
RRdB=10*log10(rr.^2/2);
plot(RRdB,m,'+')
xlabel('Ricean parameter dB')
ylabel('Nakagami parameter m')
Problem 21. ricetoNakagami.m
Eqn. (2.59) is
( )
( )
( )
2 2
0 0
2 2 2 0
2
exp
a A
aA
A
A
f a I

+
.
2 2 2
0
2 E A A 1 +
]
.Rician
2
E A 1
]
..Nakagami
Thus,
2 2
0
2 A + . Also, using the expression for m (eqn. 2.72), we can write
Page 24 of 246
( )
2
2
0
2 4 4
0 0
2 2 2
2 2 2
0 0
2
2 1
1 1 1
2
1
2
A
A A
m
A A

1
1
]

_ +
+

,
.
Note that ( )
( )
2
0
2
10
2
10log
A
K dB

. It is now possible to relate K(dB) to the Nakagami parameter


m. (Shown above).
Problem 22. Doppler shift
6
8
900 10 80000
66.6
3 10 60 60
d
v
f f Hz
c



2
.36
1
2
1
2 .6 66.67
d
e
av
f
e

=.0043 s
2
.36
2 2 66.67 .6 e 70
A d
N f e



.
Problem 23. Coherence BW = 10 KHz
Data rate = 5 kbps
Data rate < coherence bandwidth Channel is flat.
Coherence Time = 100 s
Pulse duration =
1
200
5000
s
Pulse duration > coherence time fast fading.
Problem 24. freqselresponse.m
The relative attenuation of the frequency components varies with the strength of the two waves.
This will change the coherence bandwidth of the channel.
Page 25 of 246
Figure Ex. 2-24
Problem 25.Gaussexp and chiexp
clear
close all
%Gaussexp.m
%generates exponential from two Gaussian random numbers
%histogram is compared to the exponential pdf
x1=normrnd(0,.5,1,10000);%10000 Gaussian random numbers
x2=normrnd(0,.5,1,10000);%10000 Gaussian random numbers
y=x1.^2+x2.^2;
x=min(y):max(y)/80:max(y);
hist(y,x);
xh=hist(y,x);
hold on
%plot(x,xh/max(xh))
ymean=mean(y);
Page 26 of 246
ystd=std(y);
ratio=ymean/ystd
exf=exppdf(x,ymean);%generates exponential pdf having the same mean
hold on
exf=exf*max(xh)/max(exf);
plot(x,exf,'r')
legend('expoential pdf')
xlabel('x')
ylabel('pdf or histogram')
Problem 26.pulsedisp.m
%pulsedisp.m
%shows the effect of frequency selective effects by adding ten different pulses
%shifted and weighted
%Gaussian pulses used
close all
clear
for kp=1:3;
%plots three separate generation to show the effect of random paths and random weights
%w=rand(10,1);%weights for 10 pulses
Page 27 of 246
%tt=100*rand(10,1);%delay is also considered to be random
NN=1024;
sigma2=200;%sigmasquare
p0=500;
%for p=1:NN;
xx=zeros(1,NN);
p=1:NN;
t(p)=p;
p1=p-p0;
for kn=1:10;
xx=xx+(1/sqrt(2*pi*sigma2))*rand(1)*exp(-(p1-100*rand(1)).^2/(2*sigma2));%10 pulses
added
end;
x1=(1/sqrt(2*pi*sigma2))*rand(1)*exp(-(p1-100*rand(1)).^2/(2*sigma2));%a single pulse
xxx=xx/max(xx);
x1=x1/max(x1);
subplot(2,2,kp+1)
plot(t,xxx);
xlim([400 800])
%finds the mean and standard deviation of the Gaussian pulse
xpp=sum(xxx);%denominator
xp=sum(t.*xxx)/xpp;%mean......sum(pi.xi)/sum(pi)
t2=t.^2;
xp2=sum(t2.*xxx)/xpp;%second moment
stdval=sqrt((xp2-xp^2))%standard deviation
end;
subplot(2,2,1)
plot(t,x1),title('Transmitted Pulse')
xlim([400 800])
sum2=sum(x1);
xy1=sum(t.*x1)/sum2;
xy2=sum(t2.*x1)/sum2;
stval=sqrt(xy2-xy1^2)%standard deviation ...single pulse
Page 28 of 246
r.m.s width (transmitted) = 14.1421
r.m.s width (received) = 25.2188, 24.2574, 24.1377
Problem 27 (a) ricetoGaussian.m
clear;
close all
%ricetoGaussian.m ;generates a Rician distribution
%compares the histogram to Rician pdf and to a Gaussian pdf having identical
%mean and variance
st=2;%standared deviation of Gaussian needed
st2=st^2;
for kr=1:10
rpara=input('mean of the Gaussian to create Rician...>');
rp2=rpara^2;
%use 5000 random variables
x=normrnd(0,st,1,5000);
xx=normrnd(0,st,1,5000);%another gaussian random variable
x1=xx+rpara;%Gaussian with different means
x2=x.^2;
xx2=x1.^2;
Page 29 of 246
xy=x2+xx2;
sst=2*st2;
KdB=10*log10(rp2/sst);
kkdb=num2str(KdB);
titlefigure=strcat('KdB=',kkdb)
r=sqrt(xy);%Rician random variable
meanp=mean(r)
varp=var(r);%variance
ax=0.:0.2:20;% range of values for the histogram
figure
yy=hist(r,ax);
%hist(r,ax),title('histogram of Rician Distribution');
ax1=rp2+ax.^2;
bes1=besseli(0,ax*rpara/st2);
y=(1/st2)*ax.*bes1.*exp(-ax1/(2*st2));
yg=sqrt(1/(2*pi*varp))*exp(-(ax-meanp).^2/(2*varp));%Gaussian pdf
plot(ax,yy/max(yy),'+',ax,y/max(y),ax,yg/max(yg),'*'),title(titlefigure)
xlabel('envelope')
ylabel('pdf or histogram')
legend('hostogram','envelope pdf','Gaussian approx.')
xf=input('enter 1 for another mean and 0 to stop..>>');
if xf==0
break
else
end;
end;
Page 30 of 246
Another way to explore this relationship is to see if the ratio of the median to mean is equal to
unity. This happens when Rician becomes Gaussian.
Page 31 of 246
Problem 28. nakagenerice.m
clear
%nakagenerice.m
%generates Nakagami distributed random numbers and estimates the parameters
%conduct the Chi-square testing for Rayleigh and Nakagami and Rice
mval=input('enter the value of m......>');
om=input('enter the value of omega....>');
N=input('the number of random numbers to be generated...>');
y=gamrnd(mval,om/mval,1,N);%Generates Gamma distributed random variables
x=sqrt(y);%generates Nakagami dsitributed random variable which is the square root of the
Gamma variable
my=mean(x.^2)%gives the value of omega
omega=my
av4=mean((x.^2-my).^2);
mn=my*my/av4%m-value directly
mm=20;%number of bins
xx=sort(x); % random samples
Page 32 of 246
inter=max(x)-min(x); %interval for chi-square test
intstep=inter/mm; %size of sub-interval
intval=[min(x):intstep:max(x)]; %samples at the sub-intervals
k=[zeros(1,mm)]; %number of samples in each sub-interval intialization
for i=1:N
for j=1:mm
if xx(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
end;
end;
p=zeros(1,mm);
for i=1:mm
yin=intval(i+1)*intval(i+1);
zin=intval(i)*intval(i);
p(i)=gamcdf(yin*mn,mn,my)-gamcdf(zin*mn,mn,my); %probabilities at the sub-interval
samples
end;
np=p.*N;
q=0;
for i=1:mm
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
chisquare_Nakagami=q%chisquare value
q_Rayl=chirayleigh(x,mm)
if mval<=1%do not conduct the Rice test
break
end;
%%%% testing for Rice
%%from the paper by Nakagami
%using the moments of the data
a4=mean(xx.^4);
a = (2*my*my-a4)^0.25; %Rician parameter
b=sqrt(0.5*(my-a^2));
inter = max(xx) - min(xx); %interval for chi-square test
intstep = inter/mm; %size of sub-interval
intval = [min(xx):intstep:max(xx)]; %samples at the sub-intervals
k = [zeros(1,mm)]; %number of samples in each sub-interval
%counting the samples in each sub-interval
for i = 1:length(xx)
for j = 1:mm
Page 33 of 246
if xx(i) <= intval(j+1)
k(j) = k(j) + 1;
break;
end;
end;
end;
Fy=1-marcumq(a/b,intval/b);%CDF uses marcumq function from Communications Toolbox
p = zeros(1,mm);
for i = 1:mm
p(i) = Fy(i+1) - Fy(i); %probabilities at the sub-interval samples
end;
np = p.*length(xx);
q = 0;
for i = 1:mm
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
q_Rice=q
**
The above program needs the following segment: chirayleigh
function [q]=chirayleigh(yy,m)
%Tests for Rayleigh distribution
%[chu)]=chirayleigh(samp,bins)
y=sort(yy); % random samples
N=length(yy);
my=mean(yy);%mean
inter=max(y)-min(y); %interval for chi-square test
intstep=inter/m; %size of sub-interval
intval=[min(y):intstep:max(y)]; %samples at the sub-intervals
k=[zeros(1,m)]; %number of samples in each sub-interval intialization
for i=1:N
for j=1:m
if y(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
end;
end;
myp=my*sqrt(2/pi);%Rayleigh parameter
p=zeros(1,m);
for i=1:m
p(i)=raylcdf(intval(i+1),myp)-raylcdf(intval(i),myp); %probabilities at the sub-interval samples
Page 34 of 246
end;
np=p.*N;
q=0;
for i=1:m
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
*****
Problem 29. outlognorm.m
%outlognorm.m
%computes the outage probability for a given average power and a fixed threshold
% as a function of the standard deviation of lognormal fading
%also generates the outage from a set of random numbers
clear
close all
%outage probability calculation for lognormal
N=2000;%number of random numbers to be generated
pdb=input('enter the average power in dBm....>>>>');
pthr=input('threshold power in dBm... less than the average power >')
st=[1:1:15];%standard deviation of fading
sq=sqrt(2)*st;
sqt=1./sq;
ff=(pdb-pthr)*sqt;
pout=0.5*erfc(ff);
for k=1:15;
x=normrnd(pdb,k,1,N);
count=0;
for kk=1:N;
if x(kk)<=pthr
count=count+1;
else
end;
end;
pouts(k)=count/N;% outage from simulation..random numbers
end;
plot(st,pout,'g',st,pouts,'r')
legend('Theoretical Outage','Simulated Outage')
xlabel('standard deviation of fading dB')
ylabel('outage probability')
Page 35 of 246
enter the average power in dBm....>>>>-95
threshold power in dBm... less than the average power >-100
Problem 30. 0.5
2
av t
out
P P
P erfc

1
]
2 1
2
av t
out
P P
P erf

1

1
]
( )
2.65
1 2 2
av t
out
P P
dB
erfinv P

]
Problem 31. Gausschiexp.m
clear
close all
%Gausschiexp.m
%generates exponential from two Gaussian random numbers
%conducts a chi-square test to validate exponential pdf
x1=normrnd(0,.5,1,10000);%10000 Gaussian random numbers
x2=normrnd(0,.5,1,10000);%10000 Gaussian random numbers
yy=x1.^2+x2.^2;
m=20;%number of bins
Page 36 of 246
y=sort(yy); % random samples
N=length(yy);%size of the sample
my=mean(y);%mean and exponential parameter
inter=max(y)-min(y); %interval for chi-square test
intstep=inter/m; %size of sub-interval
intval=[min(y):intstep:max(y)]; %samples at the sub-intervals
k=[zeros(1,m)]; %number of samples in each sub-interval intialization
for i=1:N
for j=1:m
if y(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
end;
end;
p=zeros(1,m);
for i=1:m
p(i)=expcdf(intval(i+1),my)-expcdf(intval(i),my); %probabilities at the sub-interval samples
end;
np=p.*N;
q=0;
for i=1:m
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
chi_squaretest_val=q
Problem 32. unitoGaussian.m
Chi-square values
21.5713
24.3384
19.3305
19.3305
%unitoGaussian.m
%test to see whether the sum of uniform random variables tend towards Gaussian
%conducts chi-square tests
clear
close all
Page 37 of 246
N=1000
x1=rand(1,N);
x2=rand(1,N);
x3=rand(1,N);
x4=rand(1,N);;
x5=rand(1,N);
x6=rand(1,N);
xx2=x1+x2+x3;
xx3=xx2+x4;
xx4=xx3+x5;
xx5=xx4+x6;
m=20;%number of bins
subplot(2,2,1)
hist(xx2), title('sum of three random variables')
chigauss(xx2,m)%chi-square value
subplot(2,2,2)
hist(xx3),title('sum of four random variables')
chigauss(xx3,m)%chi-square value
subplot(2,2,3)
hist(xx4),title('sum of five random variables')
chigauss(xx4,m)%chi-square value
subplot(2,2,4)
hist(xx5),title('sum of six random variables')
chigauss(xx4,m)%chi-square value
also requires the following program
function [q]=chigauss(yy,m)
%Tests for Normal distribution
%[chu)]=chigauss(samp,bins)
y=sort(yy); % sort samples
N=length(yy);
mean=mean(y);
stdev=std(y);
inter=max(y)-min(y); %interval for chi-square test
intstep=inter/m; %size of sub-interval
intval=[min(y):intstep:max(y)]; %samples at the sub-intervals
k=[zeros(1,m)]; %number of samples in each sub-interval intialization
for i=1:N
for j=1:m
if y(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
end;
Page 38 of 246
end;
p=zeros(1,m);
for i=1:m
p(i)=normcdf(intval(i+1),mean,stdev)-normcdf(intval(i),mean,stdev); %probabilities at the
sub-interval samples
end;
np=p.*N;
q=0;
for i=1:m
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
Problem 33. The results show that as the number of random variables increase, the sum of
the random variables approach Gaussian. The Rayleigh fading is a result of multiple paths and
when the number of multiple paths increase, the density function of the sum of the phasors
Page 39 of 246
giving rise to the amplitude (inphase and quadrature components) approach Gaussian and the pdf
envelope approaches Rayleigh.
Problem 34.rayoutage1
clear
%rayoutage1
close all
%generates Rayleigh faded signal with 10 multiple paths
%compares the outage to theoretical outage
numpaths = 10; %number of paths
Fc = 900e6; %carrier frequency
Fs = 4*Fc; %sampling frequency
Ts = 1/Fs; %sampling period
t = [0:Ts:1999*Ts]; %time array
wc = 2*pi*Fc; %radian frequency
ray = zeros(1,length(t)); %received signal
for i = 1:numpaths
a = weibrnd(1,3,1,length(t)); %scattering strengts are Weibull distributed
ray = ray + a.*cos(wc*t+unifrnd(0,2*pi,1,length(t)));
end;
[rayi rayq] = demod(ray,Fc,Fs,'qam'); %demodulated signal
env_ray = sqrt(rayi.^2+rayq.^2); %envelope of received signal
%computation of the outage probabilities
power_ray=env_ray.^2;
powerdB=10*log10(power_ray);
mean_power=10*log10(mean(env_ray.^2))
MK=length(env_ray)
for k=1:20;
pow(k)=mean_power-2*k; %threshold power
kps=pow(k);
ratio=10^(kps/10)/10^(mean_power/10);
poutth(k)=1-exp(-ratio);%theoretical outage
count=0;
for ku=1:MK;
power=powerdB(ku);%power in dB
if power <= kps
count=count+1;
else
end;
end;
poutsim(k)=count/MK;%outage probability simulated
end;
figure
plot(pow,poutth,':',pow,poutsim,'--'),title('Outage ---Rayleigh')
xlabel('threshold power dBm')
Page 40 of 246
ylabel('outage probability')
legend('pout_{th}','pout_{sim}')
Problem 35. riceout1.m
clear
%riceout1.m
%generates a fading signal where a direct (LOS) component is present
%generates the RF signal and calculate the outage
close all
numpaths = 10; %number of paths
Fc = 900e6; %carrier frequency
Fs = 4*Fc; %sampling frequency
Ts = 1/Fs; %sampling period
t = [0:Ts:1999*Ts]; %time array
wc = 2*pi*Fc; %radian frequency
rice = zeros(1,length(t)); %received signal
for i = 1:numpaths-1
a = weibrnd(1,3,1,length(t)); %scattering strengtsh are Weibull distributed
Page 41 of 246
rice = rice + a.*cos(wc*t+unifrnd(0,2*pi,1,length(t)));
end;
rice = rice + 4.5*cos(wc*t);%adds the direct path
[ricei riceq] = demod(rice,Fc,Fs,'qam'); %demodulated signal
env_rice = sqrt(ricei.^2+riceq.^2); %envelope of received signal
b = sqrt((std(ricei)^2 + std(riceq)^2)/2); %Rician parameter
a = mean(ricei); %Rician parameter
power_rice=env_rice.^2;
powerdB=10*log10(power_rice);
mean_power=10*log10(mean(env_rice.^2))
MK=length(env_rice)
for k=1:20;
pow(k)=mean_power-2*k; %threshold power
kps=pow(k);
count=0;
for ku=1:MK;
power=powerdB(ku);%power in dB
if power <= kps
count=count+1;
else
end;
end;
poutsim(k)=count/MK;%outage probability simulated
kbs=10^(kps/10);%power in mW
poutth(k)=1-marcumq(a/b,sqrt(kbs)/b);%from the communications toolbox
end;
figure
plot(pow,poutsim,pow,poutth),title('Outage ---Rician')
xlabel('thrshold power dBm')
ylabel('outage probability')
legend('poutth','poutsim')
Page 42 of 246
Problem 36.lognormf.m
clear
close all
%exploration of the generation of lognormal
%lognormf.m
%generates a set of lognormal random numbers based on the principle that the procuct of a set of
random
%numbers will give rise to lognormal
mm=input('number of components for the product operation to check for lognormal..');
for k=1:1000;
x(k)=prod(raylrnd(1,1,mm));%generates the product of mm Rayleigh random numbers
end;
subplot(2,1,1)
hist(x),title('histogram of the product of Rayleigh numbers')
xlabel('volt')
yy=10*log10(x.^2);
subplot(2,1,2)
hist(yy),title('histogram after conversion..10log_{10}x^2..')
xlabel('dBm')
Page 43 of 246
%Tests for Normal distribution
m=20;%number of bins for the chi-square test
y=sort(yy); % sort samples
N=length(y);
mean=mean(y);
stdev=std(y);
inter=max(y)-min(y); %interval for chi-square test
intstep=inter/m; %size of sub-interval
intval=[min(y):intstep:max(y)]; %samples at the sub-intervals
k=[zeros(1,m)]; %number of samples in each sub-interval intialization
for i=1:N
for j=1:m
if y(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
end;
end;
p=zeros(1,m);
for i=1:m
p(i)=normcdf(intval(i+1),mean,stdev)-normcdf(intval(i),mean,stdev); %probabilities at the
sub-interval samples
end;
np=p.*N;
q=0;
for i=1:m
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
chi_square_val=q
Page 44 of 246
Problem 37. fadlogfm.m
%fadlogfm.m
%explores the generation of lognormal fading. There is multiple scattering. There are also
multiple paths.
%This will lead to Rayleigh envelope where the mean of the envelope will be random
clear
close all
%simulates lognormal fading
fc=1e5;%carrier frequency
ppf=2*pi*fc;
N=11;% Number of mutiple paths
%a are considered to be Gamma distributed
fs=4*fc;%sampling rate
Ts=1/fs;
t = [0:Ts:1999*Ts]; %time array
nn=length(t);
for kr=1:1000;%1000 rf waveforms are genaretd to see the statistics of the mean and the meadian
powers
%multiple reflections
Page 45 of 246
%
%ggm is the result of multiple scattering; thus each multipath is produced by multiple
(20)scattering.
%the statistics of the mean and median of the Rayleigh have been computed.
%NOTE THAT THE MULTIPLE REFLECTIONS OCCUR FIRST AND THEN THIS
MULTIPLY REFLECTED COMPONENTS
%GET REFLECTED/SCATTERED/DIFFRACTED TO TAKE MULTIPLE PATHS TO
THE RECEIVER.
%THE MULTIPLE SCATTERING COMPONENTS IDENTIFIED BY EACH OF THE
ggm
%WILL BE RAYLEIGH DUE TO THE PRESENCE OF MUTIPLE SCATTERERS IN
THE REGION
%IN WHICH THE THE SCATTERING TAKES PLACE.
ggm=prod(raylrnd(1.5,1,20));%generates the product of 20 Rayleigh r.v
cr=zeros(1,nn);
for m=1:N;
phterm=2*pi*unifrnd(0,2*pi,1,nn);
cr=cr+ggm*cos(ppf*t+phterm);%Rayleigh
end;
[x,y]=demod(cr,fc,fs,'qam');
ae=(1/N)*sqrt(x.^2+y.^2);%ae will be Rayleigh
ae=ae;
mm(kr)=mean(ae);
med(kr)=median(ae);
end;
mm2=mm.^2;
med2=med.^2;
mmdB=10*log10(mm2);%mean power in dBm
meddB=10*log10(med2);%median power in dBm
%%% note that both average ( or median) of envelope and average of the power will be
lognormal
plot(t*1e3,cr/max(abs(cr))),title('rf signal incorporating lognormal fading');
xlabel('time ms')
ylabel('rf signal volt')
xlim([0 0.5])
figure
subplot(2,2,1)
hist(mm),title('histogram of the mean power')
xlabel('volt')
subplot(2,2,2)
hist(med),title('histogram of the median power')
xlabel('volt')
Page 46 of 246
subplot(2,2,3)
hist(mmdB),title('histogram of the mean power (dBm)')
xlabel('dBm')
subplot(2,2,4)
hist(meddB),title('histogram of the median power (dBm)')
xlabel('dBm')
Problem 38. fadlogfm.m (See the previous problem # 37)
Page 47 of 246
Problem 39.lognormf.m
clear
close all
%exploration of the generation of lognormal
%lognormf.m
%generates a set of lognormal random numbers based on the principle that the procuct of a set of
random
%numbers will give rise to lognormal
mm=input('number of components for the product operation to check for lognormal..');
for k=1:1000;
x(k)=prod(raylrnd(1,1,mm));%generates the product of mm Rayleigh random numbers
end;
subplot(2,1,1)
hist(x),title('histogram of the product of Rayleigh numbers')
xlabel('volt')
yy=10*log10(x.^2);
subplot(2,1,2)
hist(yy),title('histogram after conversion..10log_{10}x^2..')
xlabel('dBm')
Page 48 of 246
%Tests for Normal distribution
m=20;%number of bins for the chi-square test
y=sort(yy); % sort samples
N=length(y);
mean=mean(y);
stdev=std(y);
inter=max(y)-min(y); %interval for chi-square test
intstep=inter/m; %size of sub-interval
intval=[min(y):intstep:max(y)]; %samples at the sub-intervals
k=[zeros(1,m)]; %number of samples in each sub-interval intialization
for i=1:N
for j=1:m
if y(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
end;
end;
Problem 40. lognormfchi.m
clear
close all
%exploration of the generation of lognormal
%lognormfchi.m
%generates a set of lognormal random numbers based on the principle that the procuct of a set of
random
%numbers will give rise to lognormal
%chi-square tests directly and indirectly using Gaussian
mm=input('number of components for the product operation to check for lognormal..');
for k=1:1000;
x(k)=prod(raylrnd(1,1,mm));%generates the product of mm Rayleigh random numbers
end;
subplot(2,1,1)
hist(x),title('histogram of the product of Rayleigh numbers')
xlabel('volt')
yy=10*log10(x.^2);
subplot(2,1,2)
hist(yy),title('histogram after conversion..10log_{10}x^2..')
xlabel('dBm')
%%% testing directly for lognormal
m=20;
Page 49 of 246
N=length(x);
%Tests for lognormal distribution
%[chu)]=chilogn(samp,bins)
y=sort(x); % random samples
ms=std(log(y));%sigma of the lognormal *** not the standard deviation
inter=max(y)-min(y); %interval for chi-square test
intstep=inter/m; %size of sub-interval
intval=[min(y):intstep:max(y)]; %samples at the sub-intervals
k=[zeros(1,m)]; %number of samples in each sub-interval intialization
for i=1:N
for j=1:m
if y(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
end;
end;
my=mean(log(y));%parameter mu of the lognormal pdf*** not the mean of lognormal
p=zeros(1,m);
for i=1:m
p(i)=logncdf(intval(i+1),my,ms)-logncdf(intval(i),my,ms); %probabilities at the sub-interval
samples
end;
np=p.*N;
q=0;
for i=1:m
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
ch_lognorm_val=q
clear q
clear y
%Tests for Normal distribution
m=20;%number of bins for the chi-square test
y=sort(yy); % sort samples
N=length(y);
mean=mean(y);
stdev=std(y);
inter=max(y)-min(y); %interval for chi-square test
intstep=inter/m; %size of sub-interval
intval=[min(y):intstep:max(y)]; %samples at the sub-intervals
k=[zeros(1,m)]; %number of samples in each sub-interval intialization
Page 50 of 246
for i=1:N
for j=1:m
if y(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
end;
end;
p=zeros(1,m);
for i=1:m
p(i)=normcdf(intval(i+1),mean,stdev)-normcdf(intval(i),mean,stdev); %probabilities at the
sub-interval samples
end;
np=p.*N;
q=0;
for i=1:m
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
chi_square_val=q
Problem 41.hatawalf.m
clear
close all
% hatawalf.m Power loss calculations
%using Hata model and Walfisch
carf=880;%carrier frequency of in MHz
lcrf=log10(carf);
ht=30;%height in meters of the BS
lht=log10(ht);
hr=1.5;%MU ant. height in meters
lhr=log10(11.75*hr);
N=60;%number of increments for distance
distmax=30;%coverage distance in Kms
for kk=1:30;
d(kk)=1+0.5*(kk-1);
fact1=69.55+26.16*lcrf-13.83*lht;
fact2=(44.9-6.55*lht)*log10(d(kk));
fftq=fact1+fact2;
%antenna correction factor MU...
ahr=3.2*(lhr)^2-4.97;% large cities; freq. above 400 MHz
Page 51 of 246
amr=(1.1*lcrf-0.7)*hr-(1.56*lcrf-0.8);
alar(kk)=fftq-ahr;%Hata model
lfree=32.4+20*log10(d(kk))+20*lcrf;%free space loss
sw=15;%street width
hb=30;%building height=antenna height=separation of buildings
dhb=0;%no difference in heights of bdg and antenna
dhm=hb-hr;
ang=90;%angle phi
lrts=-16.9+10*lcrf-10*log10(sw)+20*log10(dhm)+4-.114*90;
lms=0+54+18*log10(d(kk))+(-4+1.5*(carf/925-1))*lcrf-9*log10(hb);
alf(kk)=lfree+lrts+lms;%W-I model
end;
plot(d,alar,d,alf);
legend('Hata model','Walfish-Ikegami model')
%axis([1 30 -140 -60]);
xlabel('distance Km');
ylabel('power loss dB');
%for transfering to excel directly as columns
d=d';
alf=alf';
alar=alar';
Page 52 of 246
Problem 42. See the textbook; relevant sections
Problem 43. See the textbook; relevant sections
Problem 44. coheBW.m
%coheBW.m
%plot of the correlation of faded channels
clear
close all
for k=1:50;
x(k)=0.05*(k-1);
x1=x(k);
sigma=1;
y(k)=1/(1+(2*pi*x1*sigma)^2);%corr coef. freq
y1=besselj(0,2*pi*x1);
yy(k)=y1^2;%corr. Coeff time
end;
Page 53 of 246
subplot(2,1,1)
plot(x,y), title('frequency correlation')
xlabel('\Delta f')
ylabel('\rho (\Delta f,0)')
subplot(2,1,2);
plot(x,yy),title('temporal correlation')
xlabel('\Delta t')
ylabel('\rho (0,\Delta t)')
The delay can be described using the exponential pdf,
( ) ( )
1
exp f U



_


,
where is the average delay. Making use of the properties of the exponential density function,
we have [ ] ; 0.5 E ms

. Thus, the maximum data rate will be approximately equal


to
1
2000bps

.
Page 54 of 246
Problem 45.fadcomRayl. m and chirayleigh.m (see next problem)
clear
%fadcomRayl.m simulates multiptah fading varying the number of paths
%Compares the histogram to a Rayleigh pdf
close all
fc=900e3;%carrier frequency
ppf=2*pi*fc;
N1=[3 5 7 10]
%a are considered to be Gamma distributed
fs=4*fc;%sampling rate
dt=1/fs;
nn=1e-3/dt;%total number of samples in one m sec
M=2^(nextpow2(nn))
dist=1000;%distance between transmit and receive in meters
avdel=dist/3e8;%average delay in seconds
for kmm=1:4
N=N1(kmm)
for k=1:nn;
t(k)=k*dt;
ci=0.0;
cir=0.0;
for m=1:N;
phterm=2*pi*rand(1);
ci=ci+gamrnd(1.4,1)*cos(ppf*t(k)+phterm);%Rayleigh including Doppler
end;
cr(k)=ci;
end;
[x,y]=demod(cr,fc,fs,'qam');
ae=(1/N)*sqrt(x.^2+y.^2);
pha=pi+angle(x+i*y);%phase to be centered around 2*pi
numb=num2str(N);
fx=strcat('Multipath fading....','N=',numb);
figure
subplot(2,2,1)
plot(t*1e3,cr),title(fx)
xlabel('time ms')
ylabel('rf signal volt')
xlim([0 .1])
aes=20*log10(ae);
subplot(2,2,2)
plot(t*1e3,aes),title(fx)
xlabel('time ms')
ylabel('relative power dB')
xlim([0 .1])
Page 55 of 246
subplot(2,2,3)
ax=0.:0.1:5;% range of values for the histogram
yy=hist(ae,ax);
bb=mean(ae)*sqrt(2/pi);%Rayleigh parameter b
y=raylpdf(ax,bb);%Rayl density function of parameter b
plot(ax,yy/max(yy),'+',ax,y/max(y)),title(fx)
legend('histogram','Rayleigh pdf')
xlabel('envelope')
qq=chirayleigh(ae,20)%chi-square value
end;
Page 56 of 246
Page 57 of 246
Page 58 of 246
Page 59 of 246
Page 60 of 246
Problem 46.fadconRayl (see previous problem) and chirayleigh
function [q]=chirayleigh(yy,m)
%Tests for Rayleigh distribution
%[chu)]=chirayleigh(samp,bins)
y=sort(yy); % random samples
N=length(yy);
my=mean(yy);%mean
inter=max(y)-min(y); %interval for chi-square test
intstep=inter/m; %size of sub-interval
intval=[min(y):intstep:max(y)]; %samples at the sub-intervals
k=[zeros(1,m)]; %number of samples in each sub-interval intialization
for i=1:N
for j=1:m
if y(i)<=intval(j+1)
k(j)=k(j)+1;
break;
end;
Page 61 of 246
end;
end;
myp=my*sqrt(2/pi);%Rayleigh parameter
p=zeros(1,m);
for i=1:m
p(i)=raylcdf(intval(i+1),myp)-raylcdf(intval(i),myp); %probabilities at the sub-interval samples
end;
np=p.*N;
q=0;
for i=1:m
q = q + ((k(i)-np(i))^2)/np(i); %chi-square test
end;
N = 3; Chi-square value = 4.7997e+003
N = 5; Chi-square value = 380.6133
N = 7; Chi-square value = 284.7777
N = 10; Chi-square value = 29.6699
Problem 47 .pulsefading.m
clear
%pulsefading.m fading including a carrier frequency
%three delays are created; Pulse stream is delayed and added
%the a uniform phase is introduced in the RF pulse stream; three pulses are added
close all
%examines the fading of pulse/shapes
%the program prompts the fractional delays
fc=10e3;%carrier frequency
ppf=2*pi*fc;
fs=12*fc;%sampling rate
ddt=1/fs;
nn=1e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn))
dist=1000;%distance between transmit and receive in meters
Page 62 of 246
avdel=dist/3e8;%average delay in seconds
%kp*ku:kp*ku+1
N=8;%number of bits
a=[1 1 -1 -1 -1 1 -1 1];
kp=floor(nn/8);%creates the width of the pulse
for ku=1:8;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
s(k)=a(ku);%creates the pulse stream
sf(k)=a(ku)*cos(ppf*tt(k));%rf pulse
sf1(k)=a(ku)*cos(ppf*tt(k)+2*pi*rand(1));%random phase
sf2(k)=a(ku)*cos(ppf*tt(k)+2*pi*rand(1));%random phase
end;
end;
del=input('enter the fractional (of the duration) delay...between 0.25 and 0.75..');
dd1=round(del*kp);
for k=1:kp*ku;
if k<=dd1
ss1(k)=0;
else
ss1(k)=s(k-dd1);%creates a delayed pulse stream
end;
end;
del2=input('enter the fractional (of the duration) delay...between 0.25 and 0.75..');
dd2=round(del2*kp);
for k=1:kp*ku;
tt2(k)=k*ddt;
if k<=dd2
ss2(k)=0;
else
ss2(k)=s(k-dd2);%creates a delayed pulse
end;
end;
sum=s+ss1+ss2;%added pulse shapes
sum=sum/max(abs(sum));%normalizes to unity
rfsum=sf+sf1+sf2;%added RF pulses
rfsum=rfsum/max(abs(rfsum));%normalizes to unity
plot(tt*1e3,s,tt*1e3,sf),title('bit stream [1 1 -1 -1 -1 1 -1 1]')
ylim([-2 2]);
xlabel('time ms')
ylabel('volts')
legend('input bit stream','input RF bit stream')
Page 63 of 246
figure
plot(tt*1e3,sum,tt*1e3,rfsum),title('fading-effects of delay and random phase')
ylim([-2 2]);
xlabel('time ms')
ylabel('volts')
legend('bit stream in fading','RF bit stream in fading')
Page 64 of 246
Problem 48. pulsefading
See the m file and results of the previous exercise (# 48)
Problem 49. pulsefadingRayl
clear
%pulsefadingRayl.m fading including a carrier frequency
%three delays are created; Pulse stream is delayed and added
%three pulses are added
%includes Rayleigh weighting at each time instant
%the program prompts the fractional delays
close all
%examines the fading of pulse/shapes
fc=10e3;%carrier frequency
ppf=2*pi*fc;
fs=12*fc;%sampling rate
ddt=1/fs;
Page 65 of 246
nn=1e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn))
dist=1000;%distance between transmit and receive in meters
avdel=dist/3e8;%average delay in seconds
%kp*ku:kp*ku+1
N=8;%number of bits
a=[1 1 -1 -1 -1 1 -1 1];
kp=floor(nn/8);%creates the width of the pulse
for ku=1:8;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
s(k)=a(ku);%creates the pulse stream
ss1(k)=a(ku)*raylrnd(1);%Rayleigh weighted
sf(k)=a(ku)*cos(ppf*tt(k));%rf pulse
sf1(k)=raylrnd(1)*a(ku)*cos(ppf*tt(k));%rf pulse Rayleigh weighted
sf2(k)=raylrnd(1)*a(ku)*cos(ppf*tt(k));%rf pulse Rayleigh weighted
sf3(k)=raylrnd(1)*a(ku)*cos(ppf*tt(k));%rf pulse Rayleigh weighted
end;
end;
del=input('enter the fractional (of the duration) delay...between 0.25 and 0.75..');
dd1=round(del*kp);
for k=1:kp*ku;
if k<=dd1
ss2(k)=0;
else
ss2(k)=s(k-dd1)*raylrnd(1);
end;
end;
del2=input('enter the fractional (of the duration) delay...between 0.25 and 0.75..');
dd2=round(del2*kp);
for k=1:kp*ku;
if k<=dd2
ss3(k)=0;
else
ss3(k)=s(k-dd2)*raylrnd(1);
end;
end;
sum=ss1+ss2+ss3;%added pulse shapes;Rayleigh weighted
sum=sum/max(abs(sum));%normalizes to unity
rfsum=sf1+sf2+sf3;%added RF pulses Rayleigh weighted
rfsum=rfsum/max(abs(rfsum));%normalizes to unity
plot(tt*1e3,s,tt*1e3,sf),title('bit stream [1 1 -1 -1 -1 1 -1 1]')
ylim([-2 2]);
Page 66 of 246
xlabel('time ms')
ylabel('volts')
legend('input bit stream','input RF bit stream')
figure
plot(tt*1e3,sum,tt*1e3,rfsum),title('Rayleigh weighted fading')
ylim([-2 2]);
xlabel('time ms')
ylabel('volts')
legend('bit stream in fading','RF bit stream in fading')
Page 67 of 246
Problem 50. pulsefadingRayl
See exercise # 49.
Page 68 of 246
Chapter 3
Page 69 of 246
Problem 1 amps.m
clear
close all
%amps.m calculates the spectrum of the am and fm signals based on AMPS system
%modulating signal is of frequency 4KHz
N=4096*2;% use 2048 so that spectra are reasonably sharp
af=4e3;%carrier frequency of 40 KHz
% one cannot use the carrier frequency (900 MHz) used in AMPS since the sampling rate
% would be very high and it will be difficult to show
%the sidebands that will only be at a separtion of 4 KHz.
mf=5e2;
beta=2;%modulation index for FM
mu=0.2;%modulation index for AM
for p=1:N;
t(p)=p/(60*af);
%step size or sampling interval should be sufficient to prevent aliasing
%should be at least of the order of (1/2.max freq.)
tt=t(p);
c(p)=cos(2*pi*af*tt);%carrier wave
f2(p)=cos(2*pi*tt*mf);%modulating signal
freq(p)=cos(2*pi*af*tt+beta*sin(2*pi*tt*mf));
amp(p)=c(p)*(1.0+mu*f2(p));
end
Ts=t(2)-t(1);
Ws=2.*pi/Ts;
freqmax=0.5*Ws/(2*pi)
FA=fft(amp);
FAMP=FA(1:N/2+1)*Ts;
W=Ws*(0:N/2.)/N;% W is in radians/s
WF=(1/(2*pi))*W;%WF is in cycles/s
FAM=fft(freq);
FAMM=FAM(1:N/2+1)*Ts;
subplot(2,2,1);
plot(t*1e3,amp);
%title('Carrier Freq: 40 KHz. AM signal- \mu=0.2');
axis([0 4 -1.5 1.5]);
xlabel('time ms');
ylabel('volts');
subplot(2,2,2);
plot(t*1e3,freq);
% title('Carrier Freq: 40 KHz. FM signal- \beta=3');
axis([0 4 -1.5 1.5]);
Page 70 of 246
xlabel('time ms');
ylabel('volts');
subplot(2,2,3);
plot(WF*1e-3,abs(FAMP)/max(abs(FAMP)));
axis([0 8 0 1])
% title('Carrier Freq: 40 KHz. Spectrum of AM- \mu=0.2');
xlabel('frequency KHz');
ylabel('Normalized Spectrum');
subplot(2,2,4);
plot(WF*1e-3,abs(FAMM)/max(abs(FAMM)));
%title('Carrier Freq: 40 KHz. Spectrum of FM- \beta=3');
xlabel('frequency KHz');
ylabel('Normalized Spectrum');
axis([0 8 0 1])
Problem 2. amps.m (previous exercise)
Page 71 of 246
Problem 3. Let m(t) be the message signal. The DSB-SC signal then becomes
( ) ( ) ( )
0
cos 2
i
s t m t f t . The average power of this signal is ( ) ( ) ( )
2 2 2
0
1
cos 2
2
i
S m t f t m t .
The upper bar represents the average.
The signal coming out of the modulator will be
( ) ( ) ( ) ( ) ( ) ( ) ( ) ( )
2
0 0 0 0
cos 2 cos 2 cos 2 cos 2
o i
s t s t f t m t f t f t m t f t . The average signal
power at the output will be ( ) ( )
( ) ( )
2
2
0 0
cos 2
2 4
m t m t
S m t f t
1

1
]
, after the high frequency
component is removed. Comparing the input signal power to the demodulator ( )
i
S to the output
signal power ( )
o
S , we have
2
i
o
S
S .
If n(t) is the noise at the input to the demodulator, the noise term becomes ( ) ( )
0
cos 2 n t f t . The
power corresponding to this term will be
( ) ( )
2 2
0
1
cos 2
2 2 4
n t f t

_ _


, ,
. Note that we have
made use of the fact that the variance of the noise (which has zero mean) is nothing but the
spectral density given by
2

. If the bandwidth of the message signal is B, the filtered noise


power at the output of the demodulator, N
0
, will be
0
2
4 2
B
N B

_ _


, ,
.
The signal-to-noise ratio at the output of the demodulator is
2 0
0
2
i
i
DSB SC
S
S
B B
S
N

_

,

_

,
.
SSB-SC:
The output signal-to-noise ratio remains unchanged because both the signal and noise occupy
only half the bandwidth and their respective powers go down by
1
2
leaving
0
0
S
N
same as that for
BSB-SC.
Problem 4.
( ) ( ) ( ) ( ) ( ) ( ) ( )
0
2 2 2
0 1 0 0 2 0 0 0
cos 2 cos 2 2 cos 2
out
e t a a m t A f t a m t A f t m t A f t 1 + + + + + 1
] ]
Page 72 of 246
Figure Ex 3.4
The spectra of some of the terms are shown in Figure Ex 3.4. In the absence of the term m
2
(t),
the minimum carrier frequency would have been 2W. However, the existence of the m
2
(t) term
requires that the minimum carrier frequency be at least equal to 3W to prevent distortion. The
cos
2
(2f
0
t) is filtered out. The carrier frequency can be lowered m(t)<<1, in which case we can
ignore m
2
(t). The minimum carrier frequency will then be 2W.
Problem 5
% spectbrect.m
clear
%spectbrect.m calculates the spectrum of the BPSK
%pulses created using data points NNN
NNN=[128 256 512];
for k=1:3
NN=NNN(k);;
N=1024;%number of samples to calculate FFT
fc=36/NN;
for p=1:1:NN;
t(p)=p;
frequency
0
W
2W f
0 f
0
+W f
0
-W
|e
out
(f)|
m
2
(t)
m(t)
m(t)cos(2f
0
t)
cos(2f
0
t)
Page 73 of 246
tt=t(p);
if (p>=0 & p<=NN/4);
BPSK(p)=0.5;%
elseif (p>NN/4 & p<=NN/2);
BPSK(p)=0.0;
else (p>NN/2);
BPSK(p)=0.0;
end;
end
for kk=NN+1:1:N;
BPSK(kk)=0.0;
t(kk)=kk;
end;
Ts=t(2)-t(1);
Ws=2.*pi/Ts;
freqmax=0.5*Ws/(2*pi);
FB=fft(BPSK);
FBP=FB(1:N/2+1)*Ts;
W=Ws*(0:N/2.)/N;% W is in radians/s
WF=(1/(2*pi))*W;%WF is in cycles/s
%datarate DT;
%DT=1/(NN/4);
%WWF=(WF)/DT;%freq units in data rate
FBMAX=max(abs(FBP));
for hh=1:1:N/2+1;
FFB(hh)=(abs(FBP(hh))/FBMAX);%BPSK
end;
plot(WF,(FFB.^2))
%ylim([-40 0])
%grid on
axis on
title('normalized spectrum of rectangular pulse');
xlabel('frequency');
ylabel('P(f)');
xlim([0 .05])
hold on
Page 74 of 246
end;
Problems 6-9. AMandQAM.m
%AMandQAM.m
% two channel amplitude modulation using the message signal in the form of a rectangular pulse
and a half sinusoidal pulse
%low paff filtered
%Results are compared between two channel AM and quadrature amplitude modulation
%modulation and demodulation are carreid out
clear
close all;%closes all figures on the screen
NN=128;
fs=1/NN;
for p=1:1:NN;
t(p)=p;
tt=t(p);
if p<=NN/2
QP1(p)=0.50;
QP2(p)=0.5*sin(pi*tt/(NN/2));
else
QP1(p)=0.0;
Page 75 of 246
QP2(p)=0.0;
end;
end
plot(t,QP1,t,QP2)
xlabel('time Samples')
ylabel('volts')
ylim([0 1])
legend('unfiltered Siganl I','unfiltered Signal II')
%low pass filter the signals using Butterworth filters
[b,a]=butter(10,.1);
QPL1=filtfilt(b,a,QP1);
QPL2=filtfilt(b,a,QP2);
figure
plot(t,QPL1,t,QPL2)
xlabel('time Samples')
ylabel('volts')
legend('filtered signal I','filtered signal II')
ylim([0 1])
%two channel AM
am1=QPL1.*cos(2*pi*t*30/NN);
am2=QPL2.*cos(2*pi*t*12/NN);
am=am1+am2;%Am signal two channel
figure
plot(t,am1,t,am2,t,am)
xlabel('time Samples')
ylabel('volts')
legend('signal I','signal II','AM')
figure
[pxx1 f]=PSD(am,128,fs);%power spectrum of the AM signal showing two frequencies
plot(f,pxx1),title('power spectrum of the AM signal')
ylabel('volt^2')
xlabel('frequency')
amq=QPL1.*cos(2*pi*t*30/NN)+QPL2.*sin(2*pi*t*30/NN);%QAM signal
figure
plot(t,amq),title('Quadrature amplitude mod. signal')
xlabel('time Samples')
ylabel('volts')
figure
[pxx2 f]=PSD(amq,128,fs);%PSD of QAM signal showing only a single frequency
plot(f,pxx2),title('power spectrum of the QAM signal')
ylabel('volt^2')
xlabel('frequency')
amd1=am.*cos(2*pi*t*30/NN );%multiplication with the first carrier
[b,a]=butter(10,.1);
amdd1=filtfilt(b,a,amd1);%low passfiltered signal
Page 76 of 246
figure
plot(t,2*amdd1),title('demodulated output Signal I (AM)')
xlabel('time Samples')
ylabel('volts')
ylim([0 1])
amd2=am.*cos(2*pi*t*12/NN );%multiplication with the second carrier
amdd2=filtfilt(b,a,amd2);%low filtering
figure
plot(t,2*amdd2),title('demodulated output Signal II (AM)')
xlabel('time Samples')
ylabel('volts')
ylim([0 1])
%%%QAM recovery
amq1=amq.*cos(2*pi*t*30/NN);%multiplication by cosine
amqq1=filtfilt(b,a,amq1);%low filtering
amq2=amq.*sin(2*pi*t*30/NN);%multiplication by sine
amqq2=filtfilt(b,a,amq2);%low pass filtering
figure
plot(t,2*amqq1),title('demodulated output Signal I (QAM)')
xlabel('time Samples')
ylabel('volts')
ylim([0 1])
figure
plot(t,2*amqq2),title('demodulated output Signal II (QAM)')
xlabel('time Samples')
ylabel('volts')
ylim([0 1])
Page 77 of 246
Page 78 of 246
Page 79 of 246
Page 80 of 246
Page 81 of 246
Page 82 of 246
Page 83 of 246
Page 84 of 246
Page 85 of 246
Page 86 of 246
Problem 10. Nyquistpulse.m
clear
close all
%Nyquistpulse.m, creates Nyquist's pulse and their spectra
%calculates the spectra of the pulses
alpha=.9;%raised cosine roll off factor
al=num2str(alpha);
T=4;%period
dt=1/(8*T);
N=4096;
for kk=1:N;
m=-4*T+(kk)*dt;
t(kk)=m;
if m==0;
sincf(kk)=1;
else
mp=pi*m;
sincf(kk)=sin(mp/T)/(mp/T);%sinc function
end;
Page 87 of 246
factor=(1-(4.0*alpha*m/(2*T)).^2);
raic(kk)=sincf(kk)*cos(pi*m*alpha/T)/factor;%raised cosine pulse
if (m>=-T/2 & m<=T/2)
rect(kk)=1;%rectangular pulse
rcp(kk)=0.5*(1+cos(2*pi*m/T));%RC pulse
else
rect(kk)=0.0;
rcp(kk)=0.0;
end;
end;
%N=1024;
ts=t(2)-t(1);
Ws=2*pi/ts;
fre=fft(rect);
fsi=fft(sincf);
frc=fft(raic);
frcc=fft(rcp);
frec=fre(1:N/2+1)*ts;%rect
fsinc=fsi(1:N/2+1)*ts;%sinc
fraic=frc(1:N/2+1)*ts;%raised cosine
frcf=frcc(1:N/2+1)*ts;%Full RC
f=(1/(2*pi))*Ws*(0:N/2)/N;
figure (1)
subplot(2,2,1);
t=t/T;
plot(t,rect,'k');
title('rectangular pulse');
axis([-4 4 -.4 1.4])
xlabel('multiples of T')
set(gca,'xtick',[-4 -3 -2 -1 0 1 2 3 4]);
grid on;
subplot(2,2,2)
plot(t,sincf,'k'),title('sinc pulse');
axis([-4 4 -.4 1.4])
set(gca,'xtick',[-4 -3 -2 -1 0 1 2 3 4]);
xlabel('multiples of T')
grid on;
subplot(2,2,3);
plot(t,raic,'k');
xlabel('multiples of T')
title(['raised cosine: \alpha ='al]);
axis([-4 4 -.4 1.4])
set(gca,'xtick',[-4 -3 -2 -1 0 1 2 3 4]);
grid on;
subplot(2,2,4);
Page 88 of 246
plot(t,rcp,'k'),title('RC pulse');
axis([-4 4 -.4 1.4])
set(gca,'xtick',[-4 -3 -2 -1 0 1 2 3 4]);
xlabel('multiples of T')
grid on;
figure (2)
subplot(2,2,1)
plot(f*T,abs(frec),'k'),title('rectangular pulse')
xlim([0 4])
ylim([0 5])
xlabel('multiples of 1/T')
set(gca,'xtick',[0 1 2 3 4]);
grid on;
subplot(2,2,2)
plot(f*T,abs(fsinc),'k'),title('sinc pulse');
xlim([0 4])
ylim([0 5])
xlabel('multiples of 1/T')
set(gca,'xtick',[0 1 2 3 4]);
grid on;
subplot(2,2,3);
plot(f*T,abs(fraic),'k');
title(['raised cosine: \alpha ='al]);
xlim([0 4])
ylim([0 5])
xlabel('multiples of 1/T')
set(gca,'xtick',[0 1 2 3 4]);
grid on;
subplot(2,2,4);
plot(f*T,2*abs(frcf),'k'),title('RC pulse');
xlim([0 4])
ylim([0 5])
xlabel('multiples of 1/T')
set(gca,'xtick',[0 1 2 3 4]);
grid on;
Page 89 of 246
Problem 11. Nyquistpulse.m (see exercise # 10)
Page 90 of 246
Problem 12. spectb.m
clear
%spectb.m calculates the spectrum of the a pulse and an RF pulse
close all
NN=128;
N=1024;%number of samples to calculate FFT
fc=36/NN;
for p=1:1:NN;
t(p)=p;
tt=t(p);
if (p>=0 & p<=NN/4);
BPSK(p)=0.5*cos(2*pi*tt*fc);%
elseif (p>NN/4 & p<=NN/2);
BPSK(p)=0.0;
else (p>NN/2);
BPSK(p)=0.0;
end;
end
Page 91 of 246
for kk=NN+1:1:N;
BPSK(kk)=0.0;
t(kk)=kk;
end;
Ts=t(2)-t(1);
Ws=2.*pi/Ts;
freqmax=0.5*Ws/(2*pi);
FB=fft(BPSK);
FBP=FB(1:N/2+1)*Ts;
W=Ws*(0:N/2.)/N;% W is in radians/s
WF=(1/(2*pi))*W;%WF is in cycles/s
%datarate DT;
DT=1/(NN/4);
WWF=(WF)/DT;%freq units in data rate
FBMAX=max(abs(FBP));
for hh=1:1:N/2+1;
FFB(hh)=(abs(FBP(hh))/FBMAX);%BPSK
end;
subplot(2,1,1);
plot(WWF,(FFB.^2)),title('normalized spectrum of RF pulse');
xlabel('frequency R (data rate)');
ylabel('P(f)');
%ylim([-40 0])
%grid on
axis on
subplot(2,1,2);
plot((WWF-fc/DT),(FFB.^2)),title('baseband spectrum');
xlabel('frequency R (data rate)');
ylabel('M(f)');
%ylim([-40 0])
xlim([0 10]);
%grid on
axis on
Page 92 of 246
Problem 13. specwaveforms.m
clear
%specwaveforms.m calculates the spectrum of the BPSK,QPSK, and MSK wave forms(1
symbol)
close all
NN=128;
N=512;%number of samples to calculate FFT
for p=1:1:NN;
t(p)=p;
tt=t(p);
if (p>=0 & p<=NN/4);
BPSK(p)=0.5*cos(2*pi*tt*12/NN);%This is an RF signal ..
QPSK(p)=0.5*cos(2*pi*tt*12/NN);%This is an RF signal ..
MSK(p)=0.5*cos(2*pi*tt*12/NN)*sin(pi*tt/(NN/2));%This is an RF signal ..
elseif (p>NN/4 & p<=NN/2);
BPSK(p)=0.0;
QPSK(p)=0.50*cos(2*pi*tt*12/NN);
MSK(p)=0.5*cos(2*pi*tt*12/NN)*sin(pi*tt/(NN/2));
else (p>NN/2);
BPSK(p)=0.0;
Page 93 of 246
QPSK(p)=0.0;
MSK(p)=0.0;
end;
end
for kk=NN+1:1:N;
BPSK(kk)=0.0;
QPSK(kk)=0.0;
MSK(kk)=0.0;
t(kk)=kk;
end;
Ts=t(2)-t(1);
Ws=2.*pi/Ts;
freqmax=0.5*Ws/(2*pi);
FB=fft(BPSK);
FBP=FB(1:N/2+1)*Ts;
W=Ws*(0:N/2.)/N;% W is in radians/s
WF=(1/(2*pi))*W;%WF is in cycles/s
%datarate DT;
DT=1/(NN/4);
WWF=(WF-12/NN)/DT;%freq units in data rate
FQ=fft(QPSK);
FQP=FQ(1:N/2+1)*Ts;
FM=fft(MSK);
FMP=FM(1:N/2+1)*Ts;
FQMAX=max(abs(FQP));
FBMAX=max(abs(FBP));
FMMAX=max(abs(FMP));
for hh=1:1:N/2+1;
FFB(hh)=(abs(FBP(hh))/FBMAX);%BPSK
FFQ(hh)=(abs(FQP(hh))/FQMAX);%QPSK
FFM(hh)=(abs(FMP(hh))/FMMAX);%MSK
end;
plot(WWF,FFB,'b',WWF,FFQ,'k',WWF,FFM,'r');
title('Spectra of Digital Waveforms');
xlabel('Normalized Frequency (f-f_{0})T');%shifted by the carrier frequency
ylabel('|G(f)|');
Page 94 of 246
axis([0 5.0 0 1]);
legend('BPSK','QPSK','MSK')
Problem 14. specfuncpower.m
clear
close all
%specfuncpower.m calculates the spectrum of the BPSK,QPSK, and MSK wave forms(1
symbol)
%no carrier modulation
%it also calculates the decrease in power in the sidebands
NN=128;
N=512;%number of samples to calculate FFT
close all
for p=1:1:NN;
t(p)=p;
tt=t(p);
if (p>=0 & p<=NN/4);
BPSK(p)=0.5;
QPSK(p)=0.5;
MSK(p)=0.5*sin(pi*tt/(NN/2));
elseif (p>NN/4 & p<=NN/2);
Page 95 of 246
BPSK(p)=0.0;
QPSK(p)=0.50;
MSK(p)=0.5*sin(pi*tt/(NN/2));
else (p>NN/2);
BPSK(p)=0.0;
QPSK(p)=0.0;
MSK(p)=0.0;
end;
end
for kk=NN+1:1:N;
BPSK(kk)=0.0;
QPSK(kk)=0.0;
MSK(kk)=0.0;
t(kk)=kk;
end;
Ts=t(2)-t(1);
Ws=2.*pi/Ts;
freqmax=0.5*Ws/(2*pi);
FB=fft(BPSK);
FBP=FB(1:N/2+1)*Ts;
W=Ws*(0:N/2.)/N;% W is in radians/s
WF=(1/(2*pi))*W;%WF is in cycles/s
%datarate DT;
DT=1/(NN/4);
WWF=(WF)/DT;%freq units in data rate
FQ=fft(QPSK);
FQP=FQ(1:N/2+1)*Ts;
FM=fft(MSK);
FMP=FM(1:N/2+1)*Ts;
FQMAX=max(abs(FQP));
FBMAX=max(abs(FBP));
FMMAX=max(abs(FMP));
for hh=1:1:N/2+1;
FFB(hh)=(abs(FBP(hh))/FBMAX);%BPSK
FFQ(hh)=(abs(FQP(hh))/FQMAX);%QPSK
FFM(hh)=(abs(FMP(hh))/FMMAX);%MSK
end;
Page 96 of 246
plot(WWF,FFB,'b',WWF,FFQ,'k',WWF,FFM,'r');
title('Spectra of Digital Waveforms');
xlabel('Normalized Frequency (f)T');
ylabel('|G(f)|');
axis([0 5.0 0 1]);
legend('BPSK','QPSK','MSK')
%%%computes the power contained in the sidebands
NK=length(FFB)
pb(1)=FFB(1)*FFB(1)*WF(1);
pq(1)=FFQ(1)*FFQ(1)*WF(1);
pm(1)=FFM(1)*FFM(1)*WF(1);
for k=2:NK;
pb(k)=pb(k-1)+FFB(k)*FFB(k)*WF(k);
pq(k)=pq(k-1)+FFQ(k)*FFQ(k)*WF(k);
pm(k)=pm(k-1)+FFM(k)*FFM(k)*WF(k);
end;
figure
plot(WWF,pb/pb(NK),'b',WWF,pq/pq(NK),'k',WWF,pm/pm(NK),'r');
title('Power contained');
xlabel('Normalized Frequency fT');
ylabel('Power');
xlim([0 5])
legend('BPSK','QPSK','MSK')
Page 97 of 246
Problem 15.corrandconv.m
clear
%corrandconv.m calculates the correlation and convolution of a rectangular pulse and a
sinusoidal pulse
close all
NN=128;
N=512;%number of samples to calculate FFT
for p=1:1:NN;
t(p)=p;
tt=t(p);
BP(p)=1;
QP(p)=cos(2*pi*tt*12/NN);
end
xb=conv(BP,BP);
xq=conv(QP,QP);
rb1=0;
rq1=0;
for k=1:128;
Page 98 of 246
rq(k)=QP(k)^2+rq1;%Correlation (integral up to T; T going from 1 to 128
rb(k)=BP(k)^2+rb1;%Correlation (integral up to T; T going from 1 to 128
rb1=rb(k);
rq1=rq(k);
end;
subplot(2,2,1)
plot(xb),title('convolution of the rectangular pulse')
xlim([0 255])
subplot(2,2,2)
plot(rb,'r'),title('correlation of the rectangular pulse')
xlim([0 255])
subplot(2,2,3)
plot(xq),title('convolution of the sine pulse')
xlim([0 255])
ylim([-80 80])
subplot(2,2,4)
plot(rq,'r'),title('correlation of the sine pulse')
xlim([0 255])
ylim([-80 80])
Page 99 of 246
0 1 0 0 2 0 0
0
50
1 0 0
1 5 0
convol ut i on of t he r ect angul ar pul se
0 1 0 0 2 0 0
0
5 0
1 0 0
1 5 0
cor r el at i on of t he r ect angul ar pul se
0 1 0 0 2 0 0
- 50
0
50
convol ut i on of t he si ne pul se
0 1 0 0 2 0 0
- 5 0
0
5 0
cor r el at i on of t he si ne pul se
T
T T
T
T=128
t i me
Problem 16. corrandconv.m (See Problem 15)
Problem 17.rocgennormal
clear
close all%closes all the curves on the screen
%rocgenNormal.m
%generates ROC from a set of Gaussian random numbers by
%plotting the probability of false alarm vs prob. of detection
%inputs are the number of random numbers and the standard deviation
%the means of the two sets are zero and 1 respectively
N=input('enter the number of Random numbers.....');
for kbr=1:100
ss=input('enter the standard deviation....');
Page 100 of 246
x=normrnd(0,ss,1,N);%N Gaussian random numbers mean zero and std of ss
y=normrnd(1,ss,1,N);%N Gaussian random numbers mean 1 and std of ss
maxx=max(x);
minx=min(x);
step=(maxx-minx)/N;
for mm=1:N;
step1(mm)=minx+mm*step;
count1=0;
count2=0;
for k=1:N
if x(k)<=step1(mm)
count1=count1+1;
else
end;
if y(k)<=step1(mm)
count2=count2+1;
else
end;
end;
PD(mm)=1-count2/N;
PF(mm)=1-count1/N;
end;
plot(PF,PD),title('ROC for Gaussian signals')
xlabel('Probability of false alarm')
ylabel('Probability of detection')
area_under_the_ROC_curve=0.5+polyarea(PF,PD)
hold on
nm=input('enter 1 for another value of std dev and 0 to stop...')
if nm==0
break
end
end;
Page 101 of 246
Problem 18 rocgenRayleigh
clear
close all%closes all the curves on the screen
%rocgenRay.m
%generates ROC from a set of Rayleigh random numbers by
%plotting the probability of false alarm vs prob. of detection
%inputs are the number of random numbers the Rayleigh parameter b
N=input('enter the number of Random numbers.....');
for kbr=1:100
b1=input('Rayleigh parameter....');
x=raylrnd(b1,1,N);% N Rayleigh random numbers with the parameter b
y=raylrnd(b1+1,1,N);%N Rayleigh random numbers with the parameter b+1
maxx=max(x);
minx=min(x);
step=(maxx-minx)/N;
for mm=1:N;
step1(mm)=minx+mm*step;
count1=0;
count2=0;
for k=1:N
Page 102 of 246
if x(k)<=step1(mm)
count1=count1+1;
else
end;
if y(k)<=step1(mm)
count2=count2+1;
else
end;
end;
PD(mm)=1-count2/N;
PF(mm)=1-count1/N;
end;
plot(PF,PD),title('ROC for Rayleigh signals')
xlabel('Probability of false alarm')
ylabel('Probability of detection')
area_under_the_ROC_curve=0.5+polyarea(PF,PD)
hold on
nm=input('enter 1 for another value of std dev and 0 to stop...')
if nm==0
break
end
end;
Problem 19. rocgenNormal and rocgenRay.m (See the two previous exercises)
Problem 20
clear
%problem320.m
for b=1:1:15;
% sn is the signal to noise ratio in DBs;
sn(b)=b;
snr(b)=10.0^(b/10);
xx=erfc(sqrt(snr(b)));
bpsk(b)=0.5*xx;%BPSK no fading
dpsk(b)=0.5*exp(-snr(b));%DPSK no fading
end;
figure (1)
semilogy(sn,bpsk,'r',sn,dpsk,'k'); %y axis is log;
legend('BPSK','DPSK')
Page 103 of 246
axis([1.0 15.0 .00001 0.1]);
xlabel('signal-to-noise ratio dB')
ylabel('probability of error')
2 4 6 8 10 12 14
10
-4
10
-3
10
-2
10
-1
signal-to-noise ratio dB
p
r
o
b
a
b
i
l
i
t
y

o
f

e
r
r
o
r
eqn. 3.84
eqn. 3.105
Problem 21. The output of the integrator will either be
( ) ( ) ( )
2
0 0
0 0
cos 2 cos 2
2
T T
T
A f t dx n t f t dx A n + +

where n will be zero mean Gaussian with a variance of
0
2 2
N T
_

,
or
( ) ( )
0
0
cos 2
T
n t f t dx n

.
Page 104 of 246
The two hypotheses now become
1
, '1'
' 0'
r n
r n

where n and n1 are Gaussian random variables with identical variances of


0
2 2
N T
_

,
, with n
having zero mean and n1 having a mean of
2
T
A
_

,
. These two Gaussian random variables are
shown in Figure Ex 3.20S, with the decision boundary. The threshold will be the midway point,
4
T
A .
The probability of false alarm and probability of miss are indicated in the figure and they will be
equal. Therefore, the error probability given by
( )
2
miss falsealarm
falsealarm
P P
P e P
+
.
( )
2
2
2
2
0
4
exp 1 1
2 2 2 4 2
2
n
T
A
AT E
P e dn erfc erfc
N

1

1
]

.
Problem 22. The output of the integrator will either be
( ) ( ) ( )
2
0 0
0 0
cos 2 cos 2
2
T T
T
A f t dx n t f t dx A n + +

where n will be zero mean Gaussian with a variance of
0
2 2
N T
_

,
or
( ) ( ) ( )
2
0 0
0 0
cos 2 cos 2
2
T T
T
A f t dx n t f t dx A n + +

.
The two hypotheses now become
Page 105 of 246
1
2
, '1'
' 0'
r n
r n

where n
1
and n
2
are Gaussian random variables with identical variances of
0
2 2
N T
_

,
, with n n1
having a mean of
2
T
A
_

,
and n
2
having a mean of
2
T
A . These two Gaussian random variables
are shown in Figure Ex 3.21S, with the decision boundary. The threshold will be the midway
point, i.e. 0.
The probability of false alarm and probability of miss are indicated in the figure and they will be
equal. Therefore, the error probability given by
( )
2
miss falsealarm
falsealarm
P P
P e P
+
.
( )
2
2
2
2
2
0 0
exp 1 1
2 2 2 2
2
T
n A
AT E
P e dn erfc erfc
N

_
+

,

1

1
]

.
Problem 23.BPSASKsim.m
clear
close all
%BPSASKsim.m
%generates OOK and BPSK signals
%adds noise
%coherent demodulation followed by LPF
%OOK signal is also detected incoherently
close all
fc=10e3;%carrier frequency
ppf=2*pi*fc;
fs=12*fc;%sampling rate
ddt=1/fs;
nn=1e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn))
N=8;%number of bits
a=[1 1 -1 -1 -1 1 -1 1];%for BPSK
b=[1 1 0 0 0 1 0 1];%for ASK
kp=floor(nn/8);%creates the width of the pulse
Page 106 of 246
sd=input('enter the std dev.of additive white noise 0.01 to .7 ..');
for ku=1:8;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
s(k)=a(ku);%creates the pulse stream
sa(k)=b(ku);%ASK data
sf(k)=a(ku)*cos(ppf*tt(k))+normrnd(0,sd);%rf signal plus noise BPSK
sam(k)=b(ku)*cos(ppf*tt(k))+normrnd(0,sd);%rf signal plus noise ASK signal
end;
end;
plot(tt*1e3,s,tt*1e3,sf),title('data and BPSK signal')
ylim([-4 4])
legend('Data','BPSK signal')
figure
plot(tt*1e3,sa,tt*1e3,sam),title('data and OOK signal')
ylim([-4 4])
legend('Data','OOK signal')
for k=1:kp*8;
sfd(k)=sf(k)*2*cos(ppf*tt(k));%coherent demodulation
samd(k)=sam(k)*2*cos(ppf*tt(k));%coherent demodulation OOK signal
end;
[bb,aa]=butter(5,.2);
sfd=filtfilt(bb,aa,sfd);
samd=filtfilt(bb,aa,samd);
figure
plot(tt*1e3,s,tt*1e3,sfd)
legend('Data','BPSK demodulated data')
ylim([-4 4])
figure
plot(tt*1e3,sa,tt*1e3,samd)
ylim([-4 4])
legend('Data','OOK demodulated data')
sq1=sam.^2;%square the OOK signal
ssq=sqrt(sq1);%gets the envelope by taking the square root
sq2=filtfilt(bb,aa,ssq);
figure
plot(tt*1e3,sa,tt*1e3,sq2)
ylim([-4 4])
legend('Data','OOK envelope detected data')
Page 107 of 246
Problem 24. BPSASKsim.m
Page 108 of 246
Problem 25.
Input
1 0 0 1 1 1 0 1 0
DPSK encoded bits
1 1 0 1 1 1 1 0 0 1
Transmitted phases
0 0 0 0 0 0 0
Problem 26. The phases are based on the following phase constellation
1 1 /4
1 1 3/4
1 1 5/4
1 1 7/4
1 1
1 1
1 1
1 1
Page 109 of 246
1 0 0 1 1 1 0 1
I Q I Q I Q I Q
Phases 7/4 3/4 /4 3/4
Phase shifts /2 /2
Problem 27.
Problem 28. qpq.m
clear;
close all
%qpq.m
%creates a sequential way to generate QPSK waveforms
N=8;%number of bits
T=100;%bit duration units
a=[1 1 -1 -1 -1 1 1 1];
fc=1/100;% minimum carrier freq; higher values may not show phase changes clearly
for jj=1:N/2;
pp=2*jj-1;%creates the counter for the symbols
for kk=2*T*(jj-1)+1:2*T*jj;
x(kk)=kk;
1 1
-1 -1 1 -1
-1 1
1 0 1 0
0 1 1 1
Phase shift /2 /2 /2 0 -/2 0
7/4
5/4
3/4
/4
/4
3/4
3/4
Page 110 of 246
qpsk1(kk)=(a(pp)*cos(2*pi*fc*kk)+a(pp+1)*sin(2*pi*fc*kk))/sqrt(2);%carrier wave
cos(2*pi*fc*t)
qpsk2(kk)=(a(pp)*cos(2*pi*fc*kk+pi/4)+a(pp+1)*sin(2*pi*fc*kk+pi/4))/sqrt(2);%cos(2*pi*fc*t
+pi/4)
end;
end;
subplot(2,1,1)
plot(x/T,qpsk1,'k.'),title('QPSK')
subplot(2,1,2);
plot(x/T,qpsk2,'k.'),title('QPSK (shifted by \pi /4)')
Problem 29 oqpq.m
clear;
close all
%oqpq.m
%creates a sequential way to generate OQPSK waveforms
N=8;%number of bits
T=100;%bit duration units
a=[1 1 -1 -1 -1 1 1 1];
Page 111 of 246
fc=1/100;% minimum carrier freq; higher values may not show phase changes clearly
for jj=1:N/2;
pp=2*jj-1;%creates the counter for the symbols
for kk=2*T*(jj-1)+1:2*T*jj;
x(kk)=kk;
ai(kk)=a(pp)*cos(2*pi*fc*kk);%in phase terms unshifted
aq(kk)=+a(pp+1)*sin(2*pi*fc*kk);% quadrature terms shifted
end;
end;
for pq=1:(N-1)*T;
xx(pq)=pq;
opsk(pq)=(ai(pq+100)+aq(pq))/sqrt(2.0);%first term creates shifted in phase terms
end;
plot(xx/T,opsk,'k.'),title('OQPSK')
axis([0 7 -1 1])
Problem 30 p4qp.m
Page 112 of 246
clear;
close all
%p4qp.m
%creates a sequential way to generate pi/4QPSK waveforms...simple program
N=8;%number of bits
T=100;%bit duration units
a=[1 1 -1 -1 -1 1 1 1];
fc=1/100;% minimum carrier freq; higher values may not show phase changes clearly
ph=1;
for jj=1:N/2;
ph1(jj)=ph;
ph=abs(ph-1);
if ph1(jj)<=0;
phase=pi/4;
else
phase=0;
end;
pp=2*jj-1;%creates the counter for the symbols
for kk=2*T*(jj-1)+1:2*T*jj;
x(kk)=kk;
p4sk(kk)=(a(pp)*cos(2*pi*fc*kk+phase)+a(pp+1)*sin(2*pi*fc*kk+phase))/sqrt(2);
end;
end;
plot(x/100,p4sk,'k.');
title('\pi/4QPSK')
Page 113 of 246
Problem 31. p4qpac.m
clear;
close all
%p4dqpac.m
%creates a sequential way to generate pi/4DQPSK waveforms...simple program
% Note that the once the phase is differntailly encoded, thre is no need
%to switch between constellations.
N=8;%number of bits
T=100;%bit duration units
a=[1 1 -1 -1 -1 1 1 1];
fc=1/100;% minimum carrier freq; higher values may not show phase changes clearly
pph=0.0;%accumulated phase
for jj=1:N/2;
pp=2*jj-1;%creates the counter for the symbols
c=a(pp)+a(pp+1)*i;%this is to calculate the phase angle of the symbol
cc=angle(c);
phe=cc+pph; %pph is the accumulated phase
for kk=2*T*(jj-1)+1:2*T*jj;
Page 114 of 246
x(kk)=kk;
p4dsk(kk)=cos(phe)*cos(2*pi*fc*kk+pi/4)+sin(phe)*sin(2*pi*fc*kk+pi/4);
%there is no need to divide by sqrt(2.0) if one is using cos or sin of phase
% instead of 1 and -1
end;
pph=phe;
end;
plot(x/100,p4dsk,'*');
title('\pi/4 DQPSK')
Page 115 of 246
Problem 32. Symbol rate = 0.5x10
4
symbols/s
Problem 33.
(a) The BER of the QPSK scheme is the same as the BER of BPSK. The symbol error rate of
the QPSK is twice the BER, equal to
4
2 10

.
(b) 2 120
QPSK BPSK
BW BW kHz .
(c) Spectral efficiency of QPSK is twice the spectral efficiency of BPSK.
(d)
8
3 180
levelPSK BPSK
BW BW kHz

.
(e) 1.5 90
MSK BPSK
BW BW kHz .
Problem 34 .msk.m
clear;
close all
%msk.m
%creates a sequential way to generate MSK waveforms
N=8;%number of bits
T=100;%bit duration units
a=[1 1 -1 -1 -1 1 1 1];
fc=1/100;% minimum carrier freq; higher values may not show phase changes clearly
fs=1/400;%carrier frequency for MSK
for jj=1:N/2;
pp=2*jj-1;%creates the counter for the symbols
for kk=2*T*(jj-1)+1:2*T*jj;
x(kk)=kk;
ai(kk)=a(pp)*cos(2*pi*fc*kk);%in phase terms unshifted
aq(kk)=a(pp+1)*sin(2*pi*fc*kk);% quadrature terms unshifted
end;
end;
1 1
1 1
1 1
1 1
Page 116 of 246
for pq=1:(N-1)*T;
xx(pq)=pq;
mskw(pq)=(ai(pq+100)*cos(2*pi*fs*pq)+aq(pq)*sin(2*pi*fs*pq));%first term creates shifted
in phase terms
end;
plot(xx/T,mskw,'k.'),title('MSK')
axis([0 7 -1 1])
Problem 35 .mskdf.m
clear;
%mskdf%creates MSK waveforms using DFM;
N=8;
T=100;%bit duration units
a=[1 1 -1 -1 -1 1 1 1];
fc=1/100;% minimum carrier freq; higher values may not show phase changes clearly
wc=2*pi*fc;%carrier freq. in radians
Page 117 of 246
msf=2*pi/(4*T);%msk frequency
phase=0.0;
for jj=1:N;
for kk=T*(jj-1)+1:T*jj;
x(kk)=kk;
xkk=kk-(jj-1)*T;
msk(kk)=cos(msf*a(jj)*xkk+wc*kk+phase);
end;
phase=phase+a(jj)*pi/2;
end;
plot(x/100,msk,'*')
title('[1 1 -1 -1 -1 1 1 1]');
axis([0 8 -1 1])
Problem 36.fsk.m
clear
%fsk.m;creates a FSK signal
T=100;%bit duration
N=8;%number of bits
a=[1 1 -1 -1 1 1 1 1];
fc=1/100;%carrier frequency
Page 118 of 246
step=1;%number of points in 1 sec
for jj=1:N
for kk=T*(jj-1)+1:T*N;
x(kk)=kk;%time axis
xfsk(kk)=cos(2*pi*(fc+a(jj)/400)*kk);%carrier frequency 1..fc+ 1/(4*T) or fc-
1/(4*T)
end;
end;
plot(x/100,xfsk);
title('FSK')
ylim([-1.5 1.5])
Problem 37. spec.m
clear
%spec.m calculates the spectrum of the BPSK,QPSK, and MSK wave forms(1 symbol)
NN=128;
N=512;%number of samples to calculate FFT
Page 119 of 246
for p=1:1:NN;
t(p)=p;
tt=t(p);
if (p>=0 & p<=NN/4);
BPSK(p)=0.5*cos(2*pi*tt*12/NN);
QPSK(p)=0.5*cos(2*pi*tt*12/NN);
MSK(p)=0.5*cos(2*pi*tt*12/NN)*sin(pi*tt/(NN/2));
elseif (p>NN/4 & p<=NN/2);
BPSK(p)=0.0;
QPSK(p)=0.50*cos(2*pi*tt*12/NN);
MSK(p)=0.5*cos(2*pi*tt*12/NN)*sin(pi*tt/(NN/2));
else (p>NN/2);
BPSK(p)=0.0;
QPSK(p)=0.0;
MSK(p)=0.0;
end;
end
for kk=NN+1:1:N;
BPSK(kk)=0.0;
QPSK(kk)=0.0;
MSK(kk)=0.0;
t(kk)=kk;
end;
Ts=t(2)-t(1);
Ws=2.*pi/Ts;
freqmax=0.5*Ws/(2*pi);
FB=fft(BPSK);
FBP=FB(1:N/2+1)*Ts;
W=Ws*(0:N/2.)/N;% W is in radians/s
WF=(1/(2*pi))*W;%WF is in cycles/s
%datarate DT;
DT=1/(NN/4);
WWF=(WF-12/NN)/DT;%freq units in data rate
FQ=fft(QPSK);
FQP=FQ(1:N/2+1)*Ts;
FM=fft(MSK);
FMP=FM(1:N/2+1)*Ts;
FQMAX=max(abs(FQP));
FBMAX=max(abs(FBP));
FMMAX=max(abs(FMP));
Page 120 of 246
for hh=1:1:N/2+1;
FFB(hh)=(abs(FBP(hh))/FBMAX);%BPSK
FFQ(hh)=(abs(FQP(hh))/FQMAX);%QPSK
FFM(hh)=(abs(FMP(hh))/FMMAX);%MSK
end;
plot(WWF,FFB,'b',WWF,FFQ,'k',WWF,FFM,'r');
title('Spectra of Digital Waveforms');
xlabel('Normalized Frequency (f-f_{0})T');
ylabel('|G(f)|');
axis([0 5.0 0 1]);
legend('BPSK','QPSK','MSK')
Page 121 of 246
Problem 38. gmshape.m
clear
close all
% gmshape.m calculates the shape of the pulse
% only the effect of one pulse passing thro' the Gaussian filter
T=64;
N=7*T;%number of pionts for plotting
MM=4;% we are looking at the 4th pulse only
M1=(MM-1)*T;
M2=MM*T;
bt1=.15;%B.T for GMSK calculation
bt2=.3;
bt3=.5;
bt4=10;
B01=bt1/T;% bandwidth
B02=bt2/T;
B03=bt3/T;
B04=bt4/T;
a1=(0.5887/B01);% alpha
a2=(0.5887/B02);
a3=(0.5887/B03);
a4=(0.5887/B04);
si1=a1/(sqrt(2.0)*pi);% sigma for the Gaussian impulse response
sip1=si1*sqrt(2.0);%sqrt(2)*sigma
si3=a3/(sqrt(2.0)*pi);
sip3=si3*sqrt(2.0);
si2=a2/(sqrt(2.0)*pi);
sip2=si2*sqrt(2.0);
si4=a4/(sqrt(2.0)*pi);
sip4=si4*sqrt(2.0);
T4=1/(4*T);
for p=1:1:N;
tt(p)=p;
G1(p)=T4*(erfc((M1-p)/sip1)-erfc((M2-p)/sip1));
G2(p)=T4*(erfc((M1-p)/sip2)-erfc((M2-p)/sip2));
G3(p)=T4*(erfc((M1-p)/sip3)-erfc((M2-p)/sip3));
G4(p)=T4*(erfc((M1-p)/sip4)-erfc((M2-p)/sip4));
end;
GMSK1=G1/max(G1);
Page 122 of 246
GMSK2=G2/max(G2);
GMSK3=G3/max(G3);
GMSK4=G4/max(G4);
t=tt/T;%time in units of bit duration
set(0,'DefaultAxesXgrid','on');
set(0,'DefaultAxesYgrid','on');
plot(t,G1/max(G4),'k',t,G2/max(G4),'k',t,G3/max(G4),'k',t,G4/max(G4),'k');
%title('GMSK Pulse Shape');
xlabel('time xT');
ylabel('amplitude');
ylim([0 1.2])
Problem 39 .eyepat.m
clear
%eyepat.m creates the eye pattern for a rectangular pulse stream being low
% pass filtered. bt=100 corresponds to infinite bandwidth
%automatically produces the title. It plots 4 figures at a time using subplots
Page 123 of 246
pi2=sqrt(2*pi);
si=0.05;%standard deviation for noise
N=16;%number of bits, minimum number so that the tails will show up
%the tails will extend over several bits
T=50;% bit (duration)
T4=4*T;% note that in this case the pulse height is (1/(2T);
%bt=1000;%B.T is the GMSK parameter; Here this determines the 3dB BW of the LPF
kt=1;
for kh=1:10;
bt=input('enter the value of BT...>');
yn=input('enter 1 if noise is to be added and 0 for no noise..>');
B=bt/T;%bandwidth
alpha=0.5887/B;
sigma=alpha/(sqrt(2.)*pi);
sig=sqrt(2.0)*sigma;
subplot(2,2,kt)%Note a maximum of four figures only
%We have a rectangular pulse passing through a Gaussian LPF with a bandwidth B
for uu=1:20;
for kk=1:N;
yr=rand(1);
if yr<=.5
a(kk)=-1;
else
a(kk)=1;
end;
end;
for kq=1:N*T;
xx(kq)=kq;
y=0.0;
for kn=1:N;
knt=kn*T-xx(kq);
knt1=(kn-1)*T-xx(kq);
y=y+(1/T4)*a(kn)*(erfc(knt1/sig)-erfc(knt/sig));%creates the total pulse shape
end;
if yn==1;
yy(kq)=y+0.05*y*randn(1);%adds noise
else
yy(kq)=y;
end;
end;
maxy=max(abs(yy));
%figure (kt)
plot(xx/T,yy/maxy);
Page 124 of 246
hold on
end;
axis([2 4 -1.2 1.2])
BT=num2str(bt);%creates a string
if yn==1;
fname= strcat('BT=',BT,' noise present');
else
fname=strcat('BT=',BT);%gives BT=appropriate value
end;
title(fname)
xlabel('\fontname{courier} \fontsize{10} t/T');
kt=kt+1;
hold off;
pr=input('enter 1 for more, and 0 to stop.....>');
if pr==0
break
else
end;
end;
Problem40. eyepat.m
Page 125 of 246
Problem 41.gmphase.m
clear
close all
%gmphase.m to see the integral becomes 0.5 for the GMSK analytical expression
% as t goes to T;
T=100;
bbt=[0.1 0.2 0.3 0.5 50]%Bt values
for kt=1:5;
%bt=.5;
bt=bbt(kt);
B=bt/T;%bandwidth
alpha=0.5887/B;
pi2=sqrt(2*pi);
sigma=alpha/(sqrt(2.)*pi);
sig=sqrt(2.0)*sigma;
T4=4*T;
si2=sig*sig;
sip=2.0*sigma/sqrt(2.0*pi);
kn=10;%looking at the 10th pulse
Page 126 of 246
for kq=T:20*T;
tt(kq)=kq;
t=kq-1;%integration up point; t
Tn=kn*T-t;%NT-t;
Tn1=(kn-1)*T-t;%((N-1)*T-t;
TT=kn*T;
TT1=(kn-1)*T;
aa1=TT*erf(TT/sig);
aa2=Tn*erf(Tn/sig);
aa3=sip*(exp(-(Tn.^2)/si2)-exp(-(TT.^2)/si2));
bb1=TT1*erf(TT1/sig);
bb2=Tn1*erf(Tn1/sig);
bb3=sip*(exp(-(Tn1.^2)/si2)-exp(-(TT1.^2)/si2));
etot=aa1-aa2-aa3-(bb1-bb2-bb3);%creates the total integral allowing the effect of
tphase(kq)=etot/T4;
end;
plot((tt/T-9),tphase,'k');
axis([-5 5 -0.1 .6])
axis on;
grid on
hold on;
end;
ylabel('phase term')
Page 127 of 246
Problem 42.gmsk.m
clear
%gmsk.m
%generates gmsk waveforms
T=100;%bit duration
N=8;%the number of bits
a= [1 1 -1 -1 -1 1 1 1];
bt=input('enter the value of BT..>>')
B=bt/T;%bandwidth
alpha=0.5887/B;
pi2=sqrt(2*pi);
sigma=alpha/(sqrt(2.)*pi);
carf=1/100;%carrier frequency
h=0.5;%modulaion index
sig=sqrt(2.0)*sigma;
sip=2*sigma/sqrt(2.0*pi);;
T4=4*T;
T2=2*T;
si2=sig*sig;
Page 128 of 246
carf=1/T;%carrier frequency
h=0.5;%modulaion index
yy(1)=0.0;%the first integral t=0 to t=0 is zero.
%t goes from 0-99 eventhough the samples are from 1-100
for kq=2:N*T;%assumed that the samplig rate is 1;
y=0.0;
for kn=1:N;
t=kq-1;%integration up point; t
Tn=kn*T-t;%NT-t;
Tn1=(kn-1)*T-t;%((N-1)*T-t;
TT=kn*T;
TT1=(kn-1)*T;
aa1=TT*erf(TT/sig);
aa2=Tn*erf(Tn/sig);
aa3=sip*(exp(-(Tn.^2)/si2)-exp(-(TT.^2)/si2));
bb1=TT1*erf(TT1/sig);
bb2=Tn1*erf(Tn1/sig);
bb3=sip*(exp(-(Tn1.^2)/si2)-exp(-(TT1.^2)/si2));
etot=aa1-aa2-aa3-(bb1-bb2-bb3);
y=y+(1/T4)*a(kn)*etot;%creates the total integral allowing the effect of
end;
yy(kq)=y;
end;
for kx=1:N*T;
x(kx)=kx;
gmsk(kx)=cos(2*pi*carf*kx+2*pi*h*yy(kx));
end;
BT=num2str(bt);
fname=strcat('gmsk ',' BT= ',BT)
plot(x/100,gmsk,'+'),title(fname);
xlabel('time ms')
ylabel('amplitude')
ylim([-1 1])
Page 129 of 246
Problem 43. gmspfnal.m
clear
% gmspfnal.m calculates the spectrum of the GMSK modulated waveform
%takes complete overlap. The integral for each bit is calculated including
%the contribution from all bits and is found outside the loop so that
%integral values may be reused with appropriate weighting when new bit
%sequences are created for Spectral averaging
%bt=[0.2 0.3 .5 .7 1. 1000];%GMSK parameter
T=128;
N=32;
T2=2*T;
M=2.^nextpow2(T*N);%number of samples to calculate FFT; next pow2
% gets the M to be equal to an integer multiple of 2 next to T*N
bt=0.3;
B=bt/T;%bandwidth
alpha=0.5887/B;
pi2=sqrt(2*pi);
sigma=alpha/(sqrt(2.)*pi);
carf=1/T;%carrier frequency
Page 130 of 246
h=0.5;%modulaion index
sig=sqrt(2.0)*sigma;
T4=4*T;
si2=sig*sig;
sip=2*sigma/sqrt(2.0*pi);
fxx=zeros(1,M/2+1);%creates initial values for averaging
%*** calculates the integral values outside
yy(1)=0.0;%the first integral t=0 to t=0 is zero.
%t goes from 0-99 eventhough the samples are from 1-100
for kq=2:N*T;%assumed that the samplig rate is 1;
for kn=1:N;%considers complete overlap
t=kq-1;%integration up point; t
Tn=kn*T-t;%NT-t;
Tn1=(kn-1)*T-t;%((N-1)*T-t;
TT=kn*T;
TT1=(kn-1)*T;
aa1=TT*erf(TT/sig);
aa2=Tn*erf(Tn/sig);
aa3=sip*(exp(-(Tn.^2)/si2)-exp(-(TT.^2)/si2));
bb1=TT1*erf(TT1/sig);
bb2=Tn1*erf(Tn1/sig);
bb3=sip*(exp(-(Tn1.^2)/si2)-exp(-(TT1.^2)/si2));
etot(kq,kn)=aa1-aa2-aa3-(bb1-bb2-bb3);%creates the total integral allowing the effect of
complete overlap
end;
end;
%*** calculates the integral values outside
for ap=1:25;%for averaging the spectra
for kq=1:N;%creates random values of + or -1
yr=rand(1);
if yr<=0.5;
a(kq)=1.0;
else
a(kq)=-1;
end;
end;
for mq=2:N*T;%assumed that the sampling rate is 1;
y=0.0;
for mn=1:N;%considers complete overlap
y=y+(1/T4)*a(mn)*etot(mq,mn);%creates the total integral allowing the effect of effect of
complete overlap
Page 131 of 246
end;
yy(mq)=y;
end;
for kx=1:N*T;
x(kx)=kx-1;
gmsk(kx)=cos(2*pi*carf*kx+2*pi*h*yy(kx));
end;
for jp=N*T+1:M
x(jp)=jp-1;
gmsk(jp)=0.0;
end;
[pxx,f]=psd(gmsk,M,1);%generates M/2+1 output points
for uu=1:M/2+1;%performs averaging of 'psd's from each iteration
fp=fxx(uu);
fxx(uu)=fp+pxx(uu);
end;
end;
pxxdb=10*log10((fxx)/max(fxx));% Power spectral density in dB
plot((f-carf)*T,pxxdb);
axis([0 5 -100 0])
xlabel('Normalized Frequency (f-f_{0})T');
ylabel('Power Spectral Density (dB)')
title('Power Spectrum of GMSK')
grid on;
hold on;
Page 132 of 246
Problem 44. Show that a 4-levl PSK and 4 level QAM are equivalent.
Four level PSK
Four level QAM (version I) Four level QAM (version 2)
If all the signals are equally likely, the average power for 4 level PSK and 4 level QAM (version
I) =
2 2 2 2 2
1
2 2 2 2 2
4
A A A A A 1 + + +
]
.
For the 4 level QAM (version 2), if the circles of the radii are 3 Aand A (which will make the
minimum distance between the symbols in QAM and PSK the same),
the average power =
2 2 2 2 2
1
3 3 2
4
A A A A A 1 + + +
]
.
Thus, the average powers of 4 level PSK and 4 level QAM are the same.
Problem 45. The bit error rate or the probability of error, BER, of a coherent BPSK system is
given by
0
1
2
E
BER erfc
N

where
2
2
T
E A . The amplitude is given by A and the data rate
1
R
T
. The noise power spectral
density is given by N
0
. Rewriting the equation for the error rate and expressing erfc function in
terms of erf function to take advantage of erfinv, we get
d =2A
2 2
1 2
d A A +
1
A
2
A
Page 133 of 246
2
0
2 1
2
T
BER erf A
N
.
( )
0
2 R e 1 2 A N rfinv BER 1
]
.
R=1kbps A=
R=10kbps A=
R=100kbps A=
Problem 46. For FSK, the error rate is given by
0
1
2 2
E
erfc
N
_


,
and therefore
( )
0
4 R e 1 2 A N rfinv BER 1
]
which is twice the amplitude required in the case of BPSK.
Problem 47 pskphaserr.m
%pskphaserr.m
clear
%computes the error rate for phase mismatch where the mismatch is considered to be
%a Gaussian random variable
global ssf
ssf1=32;%mismatch standard deviation in degrees
ssf=ssf1*pi/180;%phase mismatch standard deviation in radians
fr1=sqrt(2*pi*ssf*ssf);
for k=1:16;
global snr
sn(k)=k;%signal-to-noise raio in dB
snr=10.^(k/10);
aa=QUADL('fun',0,pi/2);
ber(k)=2*aa;%integrate from 0-pi/2 instead of -pi/2 to pi/2
end;
semilogy(sn,ber);
ylim([1e-6 0.1])
xlabel('SNR dB')
ylabel('Probability of error')
Requires the following function.
Page 134 of 246
function y=fun(xy)
%for the computation of BER when phase mismatch is random
global ssf
global snr
xx=tan(xy);
xx2=xx.^2;
x1=sec(xy);
x2=x1.^2;
ssf2=2*ssf*ssf;
ex=exp(-xx2/ssf2);
yy=cos(xx)*sqrt(snr);
y=(1/sqrt(pi*ssf2))*0.5*ex.*erfc(yy).*x1.*x1;
Problem 48.
%qpskphasemis.m
%calculates the degradation brought on by the pahse mismatch in QPSK
%BER for three vlaues of mismatch
clear
close all
angle=[0 10 20];
angler=angle*pi/180;%mismatch in radians
Page 135 of 246
for kk=1:3
xr=angler(kk)
for k=1:21;
snr(k)=k;%SNR
sn=10^(k/10);
sn1=sqrt(sn);
ax=cos(xr)+sin(xr);
snx=sn1*ax;
ay=cos(xr)-sin(xr);
sny=sn1*ay;
pe(k)=0.25*(erfc(snx)+erfc(sny));
end;
semilogy(snr,pe,'r');
xlabel('SNR dB');
ylabel('probability of error p_{\Delta\phi}(e)')
ylim([0.000001 .5])
xlim([2 20])
hold on
end;
Page 136 of 246
Problem 49 p4dqpskerr.m
clear
%p4dqpskerr.m
%computes the ber of p/4 DQPSK for baseband differential detection
for k=1:20;
sn(k)=k;%signal-to-noise raio in dB
snr=10.^(k/10);
ex=exp(-2*snr);
ee=sqrt(2)*snr;
bbx=0.0;
for kk=1:101;
ks=kk-1;
ax=(sqrt(2)-1)^ks;
bx=ax*besseli(ks,ee);
bbx=bx+bbx;
end;
dqpsk(k)=ex*(bbx-0.5*besseli(0,ee));%pi/4 DQPSK
xx=erfc(sqrt(snr));
bpsk(k)=0.5*xx;%BPSK no fading
end;
semilogy(sn,dqpsk,sn,bpsk);
ylim([0.000001 .5])
Page 137 of 246
Problem 50 pskmargin.m
clear
close all
%pskmargin.m
%computes the power margin as a function of the bit error rate for BPSK (Coherent) and DPSK.
for k=1:1001;
ber(k)=1e-6*(k-1)*10;
be2=2*ber(k);
ZB=(erfinv(1-be2))^2;%SNR required in BPSK
ZD=-log(be2);%SNR required in DPSK
ZFD=1/((1/(1-be2))^2-1);%SNR required in fading coherent BPSK
ZDD=1/be2-1;%SNR required in fading DPSK
CtoDP(k)=10*log10(ZD)-10*log10(ZB);%excess snr required to have identical error rates
BPSK and DPSK
end;
figure
semilogx(ber,CtoDP);
xlabel('bit error rate')
ylabel('Power Margin dB: DPSK-CBPSK')
Page 138 of 246
figure
Problem 51 shannon.m
clear
%shannon.m
%calculates the Shannon capacity theorem parameters
for k=1:64;
rb(k)=0.5*k;
sn(k)=10*log10((2.^rb(k)-1)/rb(k));
end;
semilogy(sn,rb);
xlim([-5 42])
ylim([0.25 24])
set(gca,'ytick',[0.25 0.5 1 2 4 8 16 24]);
set(gca,'xtick',[-6 0 6 12 18 24 30 36 42 ]);
grid on
xlabel('E/N_0 dB')
ylabel('R/W b/s/Hz')
Page 139 of 246
Values of power efficiency can be calculated from the expression for the BER (10
-5
).
Problem 52.
%BPSASKsim.m
clear
close all
%BPSASKsim.m
%generates OOK and BPSK signals
%adds noise
%coherent demodulation followed by LPF
%OOK signal is also detected incoherently
close all
fc=10e3;%carrier frequency
ppf=2*pi*fc;
fs=12*fc;%sampling rate
ddt=1/fs;
nn=1e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn))
N=8;%number of bits
Page 140 of 246
a=[1 1 -1 -1 -1 1 -1 1];%for BPSK
b=[1 1 0 0 0 1 0 1];%for ASK
kp=floor(nn/8);%creates the width of the pulse
sd=input('enter the std dev.of additive white noise 0.01 to .7 ..');
for ku=1:8;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
s(k)=a(ku);%creates the pulse stream
sa(k)=b(ku);%ASK data
sf(k)=a(ku)*cos(ppf*tt(k))+normrnd(0,sd);%rf signal plus noise BPSK
sam(k)=b(ku)*cos(ppf*tt(k))+normrnd(0,sd);%rf signal plus noise ASK signal
end;
end;
plot(tt*1e3,s,tt*1e3,sf),title('data and BPSK signal')
ylim([-4 4])
legend('Data','BPSK signal')
figure
plot(tt*1e3,sa,tt*1e3,sam),title('data and OOK signal')
ylim([-4 4])
legend('Data','OOK signal')
for k=1:kp*8;
sfd(k)=sf(k)*2*cos(ppf*tt(k));%coherent demodulation
samd(k)=sam(k)*2*cos(ppf*tt(k));%coherent demodulation OOK signal
end;
[bb,aa]=butter(5,.2);
sfd=filtfilt(bb,aa,sfd);
samd=filtfilt(bb,aa,samd);
figure
plot(tt*1e3,s,tt*1e3,sfd)
legend('Data','BPSK demodulated data')
ylim([-4 4])
figure
plot(tt*1e3,sa,tt*1e3,samd)
ylim([-4 4])
legend('Data','OOK demodulated data')
sq1=sam.^2;%square the OOK signal
ssq=sqrt(sq1);%gets the envelope by taking the square root
sq2=filtfilt(bb,aa,ssq);
figure
plot(tt*1e3,sa,tt*1e3,sq2)
ylim([-4 4])
legend('Data','OOK envelope detected data')
Page 141 of 246
Page 142 of 246
Problem 53. (See Problem 52)
Page 143 of 246
Page 144 of 246
Problem 54 see the m file for the previous exercise (BPSASKsim)
Page 145 of 246
Problem 55. BPSKphasesim
clear
%BPSKphasesim.m
%generates BPSK signalsadds noise coherent demodulation followed by LPF
%examines the case of phase mismatch both fixed and random
close all
fc=10e3;%carrier frequency
ppf=2*pi*fc;
fs=12*fc;%sampling rate
ddt=1/fs;
nn=2e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn))
N=8;%number of bits
a=[1 1 -1 -1 -1 1 -1 1];%for BPSK
kp=floor(nn/8);%creates the width of the pulse
sd=input('enter the std dev.of additive white noise 0.01-10 ..');
for ku=1:N;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
s(k)=a(ku);%creates the pulse stream
Page 146 of 246
sf(k)=a(ku)*cos(ppf*tt(k))+normrnd(0,sd);%rf signal plus noise BPSK
end;
end;
ph=input('enter the fixed phase mismatch in degrees...>>');
phr=ph*pi/180;%conver to radians
phrandom=input('enter the mean phase mismatch for random phase error..>>');
meanp=phrandom*pi/180;
'a 10% standard deviation is assumed'
plot(tt*1e3,s,tt*1e3,sf),title('data and BPSK signal')
ylim([-4 4])
legend('Data','BPSK signal')
for k=1:kp*N;
sd(k)=sf(k)*2*cos(ppf*tt(k));%coherent demodulation no mismatch
sdp(k)=sf(k)*2*cos(ppf*tt(k)+phr);% coherent demodulation fixed phase mismatch
sdpr(k)=sf(k)*2*cos(ppf*tt(k)+normrnd(meanp,meanp*.1));%coherent demodulation random
phase mismatch
end;
[bb,aa]=butter(5,.2);
sd=filtfilt(bb,aa,sd);
sdp=filtfilt(bb,aa,sdp);
sdpr=filtfilt(bb,aa,sdpr);
figure
plot(tt*1e3,s,tt*1e3,sd,tt*1e3,sdp,tt*1e3,sdpr)
legend('Data','BPSK demodulated data','BPSK demodulated data-Fixed phase mismatch','BPSK
demodulated data-random phase mismatch')
ylim([-4 4])
Page 147 of 246
Problem 56. same as (Problem 52)
Problem 57 . BPSKdetect.m
%BPSKdetect.m
%generates BPSK signals adds noise coherent demodulation followed by LPF
%examines the case of phase mismatch both fixed and random
%also detects the bits
close all
fc=10e3;%carrier frequency
ppf=2*pi*fc;
fs=12*fc;%sampling rate
ddt=1/fs;
nn=2e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn))
N=8;%number of bits
a=[1 1 -1 -1 -1 1 -1 1];%for BPSK
kp=floor(nn/8);%creates the width of the pulse
sd=input('enter the std dev.of additive white noise 0.001-1 ');
Page 148 of 246
for ku=1:N;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
s(k)=a(ku);%creates the pulse stream
sf(k)=a(ku)*cos(ppf*tt(k))+normrnd(0,sd);%rf signal plus noise BPSK
end;
end;
ph=input('enter the fixed phase mismatch in degrees...>>');
phr=ph*pi/180;%conver to radians
phrandom=input('enter the mean phase mismatch for random phase error..>>');
meanp=phrandom*pi/180;
'a 10% standard deviation is assumed'
sf=sf/abs(max(sf));
plot(tt*1e3,s,tt*1e3,sf),title('data and BPSK signal')
ylim([-4 4])
legend('Data','BPSK signal')
for k=1:kp*N;
sdd(k)=sf(k)*2*cos(ppf*tt(k));%coherent demodulation no mismatch
sdp(k)=sf(k)*2*cos(ppf*tt(k)+phr);% coherent demodulation fixed phase mismatch
sdpr(k)=sf(k)*2*cos(ppf*tt(k)+normrnd(meanp,meanp*.1));%coherent demodulation random
phase mismatch
end;
[bb,aa]=butter(5,.2);
sdd=filtfilt(bb,aa,sdd);
sdp=filtfilt(bb,aa,sdp);
sdpr=filtfilt(bb,aa,sdpr);
figure
plot(tt*1e3,s,tt*1e3,sdd,tt*1e3,sdp,tt*1e3,sdpr)
legend('Data','BPSK demodulated data','BPSK demodulated data-Fixed phase mismatch','BPSK
demodulated data-random phase mismatch')
ylim([-4 4])
for kk=1:N
ky=kp/2+(kk-1)*kp;
if sdd(ky)>0 %coh. demodulation noise only
b(kk)=1;
else
b(kk)=-1;
end;
if sdp(ky)>0;%coh. demodulation noise plus fixed phase
c(kk)=1;
else
c(kk)=-1;
end;
if sdpr(ky)>0;%coh. demodulation noise plus random phase
d(kk)=1;
Page 149 of 246
else
d(kk)=-1;
end;
end;
'input bit stream'
a
'output bit stream..coherent deomodulation'
b
'output bit stream coh. demodulation noise plus fixed phase'
c
'output bit stream coh. demodulation noise plus random phase phase'
d
Problem 58. Same m file in exercise# 57
Problem 59. Same m file in exercise# 58
Problem 60. qpqdemod.m
clear;
%qpqdemod.m
%creates a sequential way to generate QPSK waveforms and demodulates the QPSK
close all
fc=10e3;%carrier frequency
ppf=2*pi*fc;
fs=12*fc;%sampling rate
ddt=1/fs;
nn=2e-3/ddt;%total number of samples in one m sec
N=8;%number of bits
a=[1 1 -1 -1 -1 1 1 1];%for BPSK
kp=floor(nn/8);%creates the width of the pulse
sd=input('enter the std dev.of additive white noise 0.001-.1 ');
for jj=1:N/2;
pp=2*jj-1;%creates the counter for the symbols
for kk=2*kp*(jj-1)+1:2*kp*jj;
x(kk)=kk*ddt;
qpsk1(kk)=(a(pp)*cos(2*pi*fc*x(kk))+a(pp+1)*sin(2*pi*fc*x(kk)))/sqrt(2);
end;
end;
plot(x/(kp*ddt),qpsk1),title('QPSK')
Page 150 of 246
for km=1:N*kp;%adds noise and demodulates
kmt=km*ddt;
qpsnc(km)=(qpsk1(km)+normrnd(0,sd))*2*cos(2*pi*fc*kmt);
qpsns(km)=(qpsk1(km)+normrnd(0,sd))*2*sin(2*pi*fc*kmt);
end;
[bb,aa]=butter(10,.1);
qpsnc=filtfilt(bb,aa,qpsnc);%low pass filtered
qpsns=filtfilt(bb,aa,qpsns);%low pass filtered
mmu=0;
for jy=1:N/2;
mmu=mmu+1;
ky=kp+(jy-1)*2*kp;
if qpsnc(ky)>0
b(mmu)=1;
else
b(mmu)=-1;
end;
mmu=mmu+1
if qpsns(ky)>0;
b(mmu)=1;
else
b(mmu)=-1;
end;
end;
'transmitted bits'
a
'received bits'
b
Problem 61. DPSKdetect.m
clear
%DPSKdetect.m
%generates DPSK signals adds noise suboptimal demodulation followed by LPF
close all
fc=12e3;%carrier frequency
ppf=2*pi*fc;
fs=10*fc;%sampling rate
ddt=1/fs;
nn=2e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn))
N=8;%number of bits
a=[1 1 -1 -1 -1 1 -1 1];%for BPSK
ad(1)=1;%reference bit
Page 151 of 246
for kf=2:N+1
ar=a(kf-1)*ad(kf-1);
if ar==1;
ad(kf)=1;%DPSK bit
else
ad(kf)=-1;%DPSK bit
end;
end;
ad
kp=floor(nn/8);%creates the width of the pulse
sd=input('enter the std dev.of additive white noise 0.001-10 ');
for ku=1:N+1;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
if ku<=N
tt2(k)=k*ddt;
s(k)=a(ku);%input stream
else
end;
sdd(k)=ad(ku);%creates the DPSK pulse stream
sf(k)=ad(ku)*cos(ppf*tt(k))+normrnd(0,sd);%rf signal plus noise BPSK
end;
end;
sf=sf/abs(max(sf));
subplot(3,1,1)
plot(tt2*1e3,s,'k')
xlim([ 0 2.5])
ylim([-2 2])
legend('Data bits')
subplot(3,1,2)
plot(tt*1e3,sdd,'g')
ylim([-2 2])
xlim([ 0 2.5])
legend('DPSK bits')
subplot(3,1,3)
plot(tt*1e3,sf,'r')
ylim([-2 2])
xlim([ 0 2.5])
legend('DPSK signal')
for k=1+kp:(N+1)*kp;
sfr(k-kp)=2*sf(k)*sf(k-kp);
end;
[bb,aa]=butter(5,.2);
sfr=filtfilt(bb,aa,sfr);
figure
tt1=tt(1:(N+1)*kp-kp);%to get the original length. This is also equal to tt2
Page 152 of 246
subplot(2,1,1)
plot(tt2*1e3,s,'k')
ylim([-4 4])
xlim([0 2.5])
legend('Data stream ')
subplot(2,1,2)
plot(tt2*1e3,sfr,'r')
legend('DPSK demodulated data')
ylim([-4 4])
xlim([0 2.5])
for kk=1:N
ky=kp/2+(kk-1)*kp;
if sfr(ky)>0 %DPSK mod only
b(kk)=1;
else
b(kk)=-1;
end;
end;
'input bit stream'
a
'output bit stream..DPSK suboptimal'
b
Page 153 of 246
Problem 62. Use the same m file in exercise # 61.
Page 154 of 246
Problem 63.
clear
%DPSKopt.m
%generates DPSK signals adds noise optimal demodulation followed by LPF
%adds noise
close all
fc=12e3;%carrier frequency
ppf=2*pi*fc;
fs=10*fc;%sampling rate
ddt=1/fs;
nn=2e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn))
N=8;%number of bits
a=[1 1 -1 -1 -1 1 -1 1];%for BPSK
ad(1)=1;%reference bit
for kf=2:N+1
ar=a(kf-1)*ad(kf-1);
if ar==1;
ad(kf)=1;%DPSK bit
Page 155 of 246
else
ad(kf)=-1;%DPSK bit
end;
end;
ad
kp=floor(nn/8);%creates the width of the pulse
sd=input('enter the std dev.of additive white noise 0.001-0.01 ');
for ku=1:N+1;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
if ku<=N
tt2(k)=k*ddt;
s(k)=a(ku);%input stream
else
end;
sdd(k)=ad(ku);%creates the DPSK pulse stream
sf(k)=ad(ku)*cos(ppf*tt(k))+normrnd(0,sd);%rf signal plus noise BPSK
end;
end;
%sf=sf/abs(max(sf));
subplot(3,1,1)
plot(tt2*1e3,s)
legend('Data bits')
ylim([-2 2])
xlim([0 2.5])
subplot(3,1,2)
plot(tt*1e3,sdd)
legend('DPSK bits')
ylim([-2 2])
xlim([0 2.5])
subplot(3,1,3)
plot(tt*1e3,sf/max(abs(sf)))
ylim([-2 2])
xlim([0 2.5])
legend('DPSK signal')
for kk=1:(N+1)*kp;
sfc(kk)=2*sf(kk)*cos(ppf*tt(kk));
sfs(kk)=2*sf(kk)*sin(ppf*tt(kk));
end;
[bb,aa]=butter(10,.2);
sfr=filtfilt(bb,aa,sfc);
sfi=filtfilt(bb,aa,sfs);
for k=1+kp:(N+1)*kp;
x(k-kp)=sfr(k)*sfr(k-kp);
y(k-kp)=sfi(k)*sfi(k-kp);
end;
Page 156 of 246
xy=x+y;%
figure
tt1=tt(1:(N+1)*kp-kp);%to get the original length. This is also equal to tt2
subplot(2,1,1)
plot(tt2*1e3,s)
ylim([-2 2])
xlim([0 2.5])
legend('Data stream ')
subplot(2,1,2)
plot(tt2*1e3,xy)
legend('DPSK optimal demodulated data')
ylim([-2 2])
xlim([0 2.5])
for kk=1:N
ky=kp/2+(kk-1)*kp;
if xy(ky)>0
b(kk)=1;
else
b(kk)=-1;
end;
end;
'input bit stream'
a
'output bit stream..DPSK optimal'
b
Page 157 of 246
Problem 64.
( ) ( )
2 2
0
exp
u
erf u x dx

( ) ( )
2 2
0
exp 1 erf x dx

Therefore,
( ) ( ) ( ) ( ) ( ) ( )
2 2 2 2 2 2 2 2
0 0 0
1 exp exp exp exp
u u
u
erf u x dx x dx x dx x dx erfc u




.
Problem 65
( ) ( )
2 2
0
exp
u
erf u x dx

Let us put w = - u; We get,


( ) ( ) ( ) ( )
2 2 2 2
0 0
exp exp
w w
erf w x dx x dx erf w



.
Page 158 of 246
Problem 66
Filtered Noise
Problem 67. noise1
%noise1.m
clear
close all
%demonstrates.....the noise power after low pass filtering
%Gaussian random variables are generated with different variances and filtered through the same
filter
for k=1:10; %10 different noise variances
beta(k)=0.25*k;%value of beta
x=normrnd(0,sqrt(beta(k)),1,4096);%generate 4096 samples of Gaussian random numbers
..white noise
[a,b]=butter(5,.5);%Butterworth coefficients for LPF
xx=filtfilt(a,b,x);%low pass filtered
pow(k)=var(xx);%filtered noise variance
Power Spectral Density G
n
(f)
2

frequency
0
frequency
-W W 0
Power = area = W
Page 159 of 246
end;
plot(beta,pow,'*')
xlabel('\beta')
ylabel('LP Filtered variance')
We can see a linear relationship between spectral density and output noise power (for a fixed
LPF bandwidth).
The next section contains the effect of varying bandwidths on the output noise power for a fixed
input noise.
%noise2.m
clear
close all
%demonstrates.....the noise power after low pass filtering
%Gaussian random variables are generated a fixed variance and filtered through the different
LPFs
for k=1:8; %8 different LPF bandwidths
beta=2.1;%value of beta
Page 160 of 246
x=normrnd(0,sqrt(beta),1,4096);%generate 4096 samples of Gaussian random numbers ..white
noise
ff(k)=0.1*k;
[a,b]=butter(5,ff(k));%Butterworth coefficients for LPF
xx=filtfilt(a,b,x);%low pass filtered for different LPF
pow(k)=var(xx);%filtered noise variance
end;
plot(ff,pow,'*')
xlabel('normalized bandwidth')
ylabel('LP Filtered variance')
We can see a linear relationship between spectral density and bandwidth (for a fixed noise
spectral density).
Problem 68. Let ( ) ( ) ( )
1 0
cos 2 n t n t f t .
( ) ( ) ( ) ( ) ( ) ( )
2 2 2
2
1 0 0
1
cos 2 cos 2
2
n t n t f t n t f t n t .
Page 161 of 246
Problem 69. %noise3.m
%shows that the variance of the noise is reduced by 1/2 after multiplication by cos(2*pi*fc*t)
clear
close all
k=1:4096;
x=normrnd(0,1.3,1,4096);%generate 4096 samples of Gaussian random numbers ..white noise
y=cos(2*pi*(1/100)*k);%cos(2*pi*fc*t)
xy=x.*y;
ratio=var(x)/var(xy)
Problem 70 Let
( ) ( )
0
0
cos 2
T
out
n n t f t dt

is the output of the correlator.


The noise power is given by
( ) ( ) ( ) ( ) ( )
( ) ( ) ( ) ( )
2
0 0
0 0
0 0
0 0
cos 2 cos 2
cos 2 cos 2
T T
out
T T
n n t f t dt n f d
n n t f t f dtd



Because the noise is white,
( ) ( ) ( )
2
n t n t

,
the noise power becomes
( ) ( )
2
2
0
0
cos 2 .
2 2 2 2
T
out
T T
n f t dt spec density

.
n(t)
cos(2f
0
t)
0
T

n
out
Page 162 of 246
Thus, n
out
is a Gaussian random variable with zero mean and a variance of
2 2
T
.
Note: Result of exercise # 68 can be obtained by replacing the integration in exercise # 70 by
averaging, i.e.,
0
T

by
0
1
T
T
T

.
Problem 71. The narrowband noise n(t) is given by
( ) ( ) ( ) ( ) ( ) cos 2 sin 2
c c s c
n t n t f t n t f t .
The spectral density of the noise G
n
(f) is shown in figure.
The bandpass range is 2B. We must note that while n(t) is narrowband, n
s
(t) and n
c
(t) are low
pass components. Multiplying n(t) by ( ) cos 2
c
f t and low pass filtering, we get
( ) ( ) ( )
1
cos 2
2
c c
n t f t n t .
Similarly, multiplying n(t) by ( ) sin 2
c
f t and low filtering, we get
( ) ( ) ( )
1
sin 2
2
c s
n t f t n t .
The spectral densities of the inphase and quadrature components are obtained from
( ) ( ) ( )
2 1
cos 2
2
c c
n t f t n t 1
]
and
G
n
(f)
-f
c
f
c
2B
2B
2

0 frequency
Page 163 of 246
( ) ( ) ( )
2 1
sin 2
2
c s
n t f t n t 1
]
.
Using the results from exercise # 68, we have
( ) ( )
( ) ( )
2 2
2 2
1 1
2 4
1 1
2 4
c
s
n t n t
n t n t

.
We can now write the expressions for the spectral densities of the inphase and quadrature
components, G
nc
(f) and G
ns
(f), respectively as
( ) ( ) ( )
( ) ( ) ( )
2 2
2 2
2
2
nc c
ns s
G f n t n t
G f n t n t



.
These spectral densities are shown in figure below.
The power of the narrowband noise n(t) is 2 2 2
2 2
B B B

+ . The powers of the baseband
components, the inphase and quadrature, are equal. Each of them is equal to B .
-B 0 B
frequency

G
nc
(f) or G
ns
(f)
Page 164 of 246
Chapter 4
Problem 1
Signal power = -100 dBm or 10
-10
mW.
CCI Power=10
-12.1
mW
Noise Power =10
-11.9
mW
Overall signal-to-noise ratio =
10
12.1 11.9
0
10
16.6 12
6 6 10 10
S
dB
CCI N



+ +
Signal-to-CCI ratio =
10
12.1
10
20.98 13.21
6 6 10
S
dB
CCI



Problem 2
Signal power = -97dBm or 10
-9.7
mW.
CCI Power =10
-12
mW
Noise Power =10
-11.7
mW
Overall signal-to-noise ratio =
9.7
12 11.7
0
10
25 14
6 6 10 10
S
dB
CCI N



+ +
Signal-to-CCI ratio =
9.7
12
10
33.25 15.25
6 6 10
S
dB
CCI



Required signal-to-CCI ratio =
9.7
10
20 100
6
s
dB
P

where P
s
is the maximum CCI power
acceptable.
9.7
13
10
3.325 10 124.78
600
s
P mW dBm


Problem 3
1
d
d
P

;
( )
3
3.8
1
2 10
2
P Km mW


( )
3.8
3
2
3 10 .214 36.7
3
P Km W dBm
_


,
Page 165 of 246
( )
3.8
3 5
2
6 10 1.5 10 48.1
6
P Km mW dBm
_


,
Problem 4 Signal Power
4
4 ; CCI Power
4
10
Signal-to-CCI ratio =
4
10
39 15.9
4
dB
_


,
Problem 5 Signal-to-CCI ratio = 20 100 dB
3.2
100
8
d
_


,
;
1
3.2
8 100 33.7 d km
Problem 6 Received Power (dBm) = Transmitted Power (dBm)-Loss(dB)= -105dBm
Transmitted Power =-105+115 =10 dBm 10 mW.
Problem 7. Signal-to-CCI ratio =
1
20 100
6
D
dB
R

_


,
;
1
600 8.43
D
R

_


,
.
Problem 8.signal-to-noise ratio
1.9
96 ( 115) 19 10 dB
Threshold SNR
1.5
15 10 dB
Outage =
1.5
1.9
10
1 exp 0.3284
10
_


,
.
Outage
1.5
10
0.02 1 exp 1 exp
ThresholdSNR
averageSNR averageSNR
_ _


, ,
1.5
10
1565 31.2
log(0.98)
averageSNR dB
Noise Power = average signal power- average SNR=-96-31.2=-127.2 dBm
Problem 9 See the relevant section
Problem 10
Offered Load (From Table ) =13.188 Erl; Carried Load =13.188 x 0.98 = 12.98 Erl
Page 166 of 246
Total carried traffic = 12.98x10=129.8 Erl.
Problem 11 Offered Traffic = 63.9; Carried Traffic = 63. 9x 0.98 =66.62 Erl
Consumption (Erl) by a single user = holding time(hour) x number of calls/hour
= (2/60) x 2 = 0.0667 Erl
Total Number of Users possible = Carried Traffic/traffic generated by a single user
= 66.62/.0667= 939.
Problem 12. Provider A
Offered Traffic/cell=13.188 Erl; Carried Traffic/cell=12.98 Erl
Total Carried Traffic =12.98*100= 1298 Erl
Traffic Generated by a single user = 2x(3/60)= 0.1 Erl.
Number of users that can be supported = 1298/0.1=12980.
Provider B
Offered Traffic/cell=43.99 Erl; Carried Traffic/cell=43.11 Erl
Total Carried Traffic =43.11 x 35 = 1508 Erl
Traffic Generated by a single user = 2x(3/60)= 0.1 Erl.
Number of users that can be supported = 1508/0.1=15080.
Problem 13. Traffic generated by a single user =3x(3/60)= 0.15 Erl
Carried Traffic = Number of users x Traffic generated by a single user =700 x 0.15 = 105 Erl
Offered Traffic = 105/.98=107.14 Erl
From the Tables, this corresponds to 120 channels.
Problem 14. use outlognorm.m from exercise #2-29.
Page 167 of 246
Problem 15 . same as in (Problem 14).
Problem 16.raylsim.m
%raylsim
%simulates Rayleigh random numbers and computes the outage
clear
close all
%envelope Rayleigh.......power is exponential%
Pav=input('enter the average power in dBm...>>');
P=10^(Pav/10);%power in mW
xe=exprnd(P,1,2000);%2000 random numbers, exponential with a mean corresponding to P dBm
for k=1:15;
x=Pav-k;%thrshold equal to the average power less than k
xp(k)=10^(x/10);%conversion to mW
xd(k)=k;%Difference between the thrshold and average power
count=0;
for kk=1:2000
if xe(kk)<=xp(k)
Page 168 of 246
count=count+1;
else
end;
end
pouts(k)=count/2000;
end;
%theoretical outage
pthout=1-exp(-xp./P);
plot(xd,pouts,'g',xd,pthout,'r')
legend('simulated outage','theoretical outage')
ylabel('Outage Probability')
xlabel('Relative threshold (below the average power) dB')
Problem 17. same as in (Problem 16).
Problem 18
Power at the unsplit cell boundary
tu
P R

Page 169 of 246


Power at the cell boundary after splitting
3
split
R
P

_


,
P
t u
= 1W and =3. For identical performance, the powers at the cell boundaries must be
the same.
Thus,
3
3
3
tu split
R
P R P


,
.
3
1
3 27
tu
split
P
P W .
Problem 19. The outage probability, P
out
, under lognormal fading conditions is given by
1
2 2
av th
p p
erfc

1
1
]
where all the quantities in decibel units (P
av
and P
th
in dBm and in dB).
( )
2 1 2 110
th av out
P P erfinv P dBm 1
]
.
Problem 20. Long term fading margin =6 dB. If the loss is 0.7 dB/km, the margin
corresponds to a reduction in transmission distance of
6
0.7
km or 8.5 km. Similarly, the short
term margin of 4 dB corresponds to a reduction in transmission distance of
4
0.7
km or 5.7 km.
The total reduction will be 14.2 km.
Problem 21. poutagefringe.m
%poutagefringe.m
clear
close all
%plots of equations in Chapter 4 for the calculation of the outage probability at the boundary
%shows that the second term of the equation for the area outage probability is a mere correction
(?)
sig=[4 6 8];%standard deviation of fading
loss=[2.5 3 3.5];% loss parameter
gamma=loss(1);
for kk=1:3;
sigma=sig(kk)*log(10)/10;%conversion from dB to nepers (sse Lognormal dist)
sigma2=(sqrt(2)*sigma);
for k=1:41;
M(k)=k;%fading margin in dB
mk=10^(k/10);%margin converted to power units
xx=log(mk)/sigma2;
outf(k)=0.5*erfc(xx);%outage at the fringe
end;
semilogy(M,100*outf,'k')
Page 170 of 246
xlabel('Fading Margin M dB')
ylabel('Outage Probability at the boundary %')
ylim([.1 100])
hold on
end;
Problem 22.poutagearea.m
%poutagearea.m
clear
close all
%plots of equations in Chapter 4 for the calculation of the area outage probability
sig=[4 6 8];%standard deviation of fading
loss=[2.5 3 3.5];% loss parameter
gamma=loss(1);
for kk=1:3;
sigma=sig(kk)*log(10)/10;%conversion from dB to nepers (sse Lognormal dist)
sigma2=(sqrt(2)*sigma);
for k=1:41;
M(k)=k;%fading margin in dB
mk=10^(k/10);%margin converted to power units
Page 171 of 246
xx=log(mk)/sigma2;
outf(k)=0.5*erfc(xx);%outage at the fringe
yy=sigma2/gamma;
outar(k)=outf(k)-0.5*erfc(xx+yy)*exp(2*xx*yy+yy^2);
end;
semilogy(M,100*outar,'b')
xlabel('Fading Margin M dB')
ylabel('Outage Probability (area) %')
ylim([.1 100])
hold on
end;
Problem 23. The probability of outage is ( )
2
1
2
2
out
m
P R erfc


,
where the power margin
M (dB) is expressed as
10
10log M m . We have ( )
1 1
log 10 2.30 6 1.38
10 10
e dB
.
Outage =01.;
Using the relationship between erfc and erf functions, we can write
[ ]
2
2 1.38 1 2 .01 3.2 m erfinv ; ( )
10
10 log 5 M m dB
Outage =05.;
Page 172 of 246
[ ]
2
2 1.38 1 2 .05 2.27 m erfinv ( )
10
10 log 3.6 M m dB
Power at a distance of 4 Km is
5
10 mW

. Threshold power is 91 dBm. Including the margin,


we have minimum required power =-91+5=-86 dBm
8.6
10 mW

(outage of 0.01), and


91+3.6=-87.4 dBm
8.74
10 mW

.
3.5
5
3.5
8.6
1
3.5
8.74
2
1
10
4
1
10
1
10
d
d


,
_


,
_


,
.
1 2
42 ; 46 d km d km .
Problem 24.
Omni-directional antenna
Number of Channels/Sector = 54
Offered Traffic at a GOS of 2% = 43.4 Erl
Carried Traffic = 43.4 x 0.98 = 42.53 Erl
Trunking Efficiency =
42.53
% 78.7%
54

120
o
Sector antenna
Number of Channels/sector =54/3 = 18
Offered Traffic at a GOS of 2% = 11.5Erl
Carried Traffic = 11.5 x 0.98 = 11.27 Erl
Total Carried Traffic= 11.27x3 = 33.81 Erl
Trunking Efficiency =
33.81
% 62.6%
54

60
o
Sector antenna
Number of Channels/sector =54/6 = 9
Offered Traffic at a GOS of 2% = 4.35Erl
Carried Traffic = 4.35 x 0.98 = 4.26 Erl
Total Carried Traffic= 4.26x6 = 25.6 Erl
Page 173 of 246
Trunking Efficiency =
25.6
% 47.41%
54
.
Problem 25. signal-to-noise ratio=
9
12 11
10
62.5 18
6 10 10
dB



+
.
Problem 26. Let the desired signal power (average) be P
avs
Watts. Let the co-channel power
(average) at the MU be P
avc
Watts.
We have
10
10log
avs
avc
P
P


,
. The probability density function of the desired signal power, P
s
,
will be
( )
1
exp
s
s
avs avs
p
f p
P P
_


,
and the pdf of the co-channel power, P
c
, will be
( )
1
exp
c
c
avc avc
p
f p
P P
_


,
.
Outage occurs when the co-channel power exceeds the desired signal power.
Outage probability = { }
c s
Prob P P > .
Assuming that the two powers are independent, this outage probability is given by the shaded
area below.
( ) ( )
0 0
1
1
s
p
avc
out s c c s
avs
avc avs
avc
P
P f p f p dp dp
P
P P
P

1

1
+
1
]
+

.
p
c
p
s
P
s
>P
c
P
s
<P
c
Page 174 of 246
10
1
1 10
out
P
_

,

+
Problem 27. outprotectionRayl.m
%outprotectionRayl
clear
close all
%computes the outage as a function of the protection ratio, i.e. ratio of the
%desired signal power to CCI power
%Rayleigh fading
alpha=[0:2:40];%protection in dB
alp=10.^(alpha/10);
outage=1./(1+alp);
semilogy(alpha,outage,'k'),title(' Rayleigh faded signal and Rayleigh faded CCI')
xlabel('Protection ratio \alpha dB')
ylabel('Outage probability')
Page 175 of 246
Figure P 4-27
Problem 28. Let us assume that mean desired power be P
0
dBm and the mean CCI power be
P
d
dBm. WE have [ ]
0 d
P P dB .
We have (if we designate Y as the desired signal power and X as the CC power in dBm)
( )
( )
2
2
2
1
exp
2
2
d
x P
f x

1
1
]
and
( )
( )
2
0
2
2
1
exp
2
2
y P
f y

1
1
]
.
Page 176 of 246
Outage occurs when X Y or when 0 X Y .
We solve this problem easily by finding out the density function of Z X Y . Knowing that
both X and Y are Gaussian and independent random variables, Z will also be a Gaussian random
variable with a variance equal to the sum of the variances
( )
2
2 and mean equal to the
difference of the means ( ) . The density function of Z is given by
( )
( )
2
2
2
1
exp
2
2 z
z
z
f z

1
+
1
1
]
where
2 2
2
z
.
The outage occurs when 0 Z and thus, the outage probability is given by
( )
2
2
2
0
1 1 1
exp
2 2 2 2 2
2
out
z z
z
z
P dz erfc erfc

1
_ +
_
1

,
1
,
]

.
Problem 29. outprotectionlogn.m
%outprotectionlogn
clear
close all
%computes the outage as a function of the protection ratio, i.e. ratio of the
%desired signal power to CCI power when lognormal fading is present
alpha=[0:2:40];%protection in dB
sigma=[4 6 8 10];
for k=1:4
sig=sigma(k);
sig2=2*sig;
outage=0.5*erfc(alpha/sig2);
semilogy(alpha,outage,'k')
hold on
end;
title(' Lognormal faded signal and Lognormal faded CCI')
xlabel('Protection ratio \alpha dB')
ylabel('Outage probability')
Page 177 of 246
ylim([0.000001 .5])
Problem 30. Raylrandomoutage.m
%Raylrandomoutage
%generates exponentially distributed random variables with powers (desired and CCI)
%to obtain outage under the conditions that both desired signal and CCI signal are Rayleigh
faded.
clear
close all
N=5000;% random numbers
for k=1:21
alpha(k)=k-1;
alp=10^(alpha(k)/10);
x=exprnd(1,1,N);
y=exprnd(1/alp,1,N);
count=0;
Page 178 of 246
for kk=1:N
if y(kk)>=x(kk);
count=count+1;
else
end;
end;
outage(k)= count/N;
end;
semilogy(alpha,outage),title(' Rayleigh faded signal and Rayleigh faded CCI..random numbers')
xlabel('Protection ratio \alpha dB')
ylabel('Outage probability')
Problem 31. lognrandomoutage.m
%lognrandomoutage
%generates exponentially distributed random variables with powers (desired and CCI)
Page 179 of 246
%to obtain outage under the conditions that both desired signal and CCI signal are lognormal
faded.
clear
close all
N=6000;% random numbers
for ks=1:5
sigma=2*ks;%standard deviation of fading
for k=1:16
alpha(k)=k-1;
x=normrnd(alpha(k),sigma,1,N);%average power equal to the difference in powers (signal)
y=normrnd(0,sigma,1,N);%average power equal zero ....CCI
count=0;
for kk=1:N
if y(kk)>=x(kk);
count=count+1;
else
end;
end;
outage(k)= count/N;
end;
semilogy(alpha,outage,'k')
hold on
end;
xlabel('Protection ratio \alpha dB')
ylabel('Outage probability')
title(' Lognormal faded signal and lognormal faded CCI..random numbers')
ylim([0.001 0.5])
Page 180 of 246
Figure P. 4-31
Page 181 of 246
Chapter 5
Problem 1. The density function of the signal-to-noise ratio in the absence of any diversity is
given by
0 0
1
exp


_


,
where is the signal-to-noise ratio and
0
is the average signal-to-noise
ratio. We are given that is 3 dB or 2. The threshold SNR is 0 dB or 1. The outage probability in
the absence of any fading is
1
0
1 1 1
exp 1 exp 0.2835
3 3 3
d
_ _


, ,

. When diversity is used,


the density function of the SNR is given by
( )
0 0
1 1
exp
1 !
M
M
M


_

,
. The outage probability
is given by
1 5
6
6
0
1 5087 1
exp 1- exp - 1.4 10
120 3 3 3645 3
d


_ _


, ,

. (Note: You may use gamcdf


from the Statistics Toolbox to get the integral or use the Symbolic Toolbox to evaluate the
integral).
Problem 2. The density function of the signal-to-noise ratio in the absence of any diversity is
given by
0 0
1
exp


_


,
where is the signal-to-noise ratio and
0
is the average signal-to-noise
ratio. We are given that is 3 dB or 2. The threshold SNR is 0 dB or 1. The outage probability in
the absence of any fading is
1
0
1 1 1
exp 1 exp 0.2835
3 3 3
d
_ _


, ,

. When diversity is used,


the density function of the SNR is given by
5
0 0 0
1 exp exp
M

1 _ _

1
, , ]
. The outage
probability is given by
5 6
1
4
0
1
2 1 exp exp 1 exp 5.8 10
3 3 3
d


1 1 _ _ _

1 1
, , , ] ]

. (Note:
You may use the Symbolic Toolbox to evaluate the integral).
Problem 3.Consider the case of a Rayleigh distributed envelope with a pdf given by
( ) ( )
2
2 2
exp
2
x x
f x U x
b b
_


,
where
( )
2 2
2 E X b (Average Power). If we set a threshold envelope value of x
T
, the probability
that the detected envelope will be less than this threshold (i.e., outage probability) is given by
Page 182 of 246
2 2
2 2 2
0
exp 1 exp
2 2
T
x
T
x x x
dx
b b b
_ _


, ,

.
The probability that all the M channels (diversity envelopes) will have their respective envelopes
to be less than
T
x will be
2
2
1 exp
2
M
T
x
b
1
_

1
, ]
.
The probability that at least one channel would have an envelope that will be greater than the
threshold will be
2
2
1 1 exp
2
M
T
x
b
1
_

1
, ]
The probability density function of the selection combiner using envelopes is obtained as
( )
1
2 2 2
2 2 2 2
1 1 exp 1 exp exp
2 2 2
M M
T T T T
T
T
d x x x x
M U x
dx b b b b


1 1 _ _ _

' ; 1 1
, , , ] ]

.
Replacing
T
x with x, we can now write the general expression for the pdf of the selection
combiner of envelopes as
( ) ( )
1
2 2
2 2 2
1 exp exp
2 2
M
M
x x x
f x M U x
b b b

1
_ _

1
, , ]
.
If we put M =1, we have no diversity, the expression above becomes a Rayleigh density
function.
Problem 4 Raylseldiv.m
%Raylseldiv.m
clear
close all
%generates the pdf of selection diversity when envelopes are considered
b=1;
M1=[1 3 6];
x=0:0.01:5;
for k=1:3
M=M1(k);
Page 183 of 246
ex1=exp(-x.^2/2);
ex2=(1-ex1).^(M-1);
y=M*x.*ex1.*ex2;
plot(x,y,'r');
hold on
end;
xlabel('Envelope')
ylabel('pdf')
Problem 5. The density function of the election combiner may be derived using order
statistics. Let X
1
, X
2
, ..X
k
be k independent identically distributed random variables. We are
seeking the density function of the random variable { }
1 2
max , ,
k
Z X X X L where Z is the
output of the selection combiner.
Let us assume that X
1
is the largest of the set. This means that the rest of the random numbers
must be less than z. Thus, the probability that X
1
lies between z and z+dz will be given by
( ) ( )
1 1 3
Pr Pr , , z X z dz X z X z + L .
Page 184 of 246
This probability is also equal to ( ) f z dz . In other words,
( ) ( ) ( ) ( ) ( )
1
1 1 3
2
Pr Pr , ,
n
k
x x
n
f z dz z X z dz X z X z f z dz F z

+

L
We could have chosen any other variable as the largest one in place of X
1
. The CDF is indicated
by F. Since all such possibilities are mutually exclusive, the density function f(z) of the
maximum is given by
( ) ( ) ( )
1
m n
k k
x x
m n m
f z f z F z


.
Because all the random variables are identically distributed, the density function becomes
( ) ( ) ( )
1 k
x x
f z kf z F z

1
]
.
Problem 6. simpleselection.m
%simpleselection.m
%conducts a selection diversity using Rayleigh random numbers
clear
close all
N=1000;
x1=raylrnd(1,1,N);
x2=raylrnd(1,1,N);
x3=raylrnd(1,1,N);
x4=raylrnd(1,1,N);
x5=raylrnd(1,1,N);
x6=raylrnd(1,1,N);
x7=raylrnd(1,1,N);
x8=raylrnd(1,1,N);
x9=raylrnd(1,1,N);
x10=raylrnd(1,1,N);
xsel=max(max(max(max(max(max(max(max(max(x1,x2),x3),x4),x5),x6),x7),x8),x9),x10);
n=1:N;
plot(n(1:10),x1(1:10),'g*',n(1:10),x2(1:10),'k+',n(1:10),xsel(1:10),'rd')
ratio1=mean(x1)/std(x1)
ratiosel=mean(xsel)/std(xsel)
xlabel('sample number')
ylabel('sample values')
legend('any one set','another set','largest of the ten sets')
Page 185 of 246
( )
( )
1.9012
.
4.76 10
.
Mean
Nodiversity
Std Dev
Mean
Selectiondiversityof
Std Dev

Only 10 samples are shown.


Problem 7. berpsk.m
clear
%berpsk.m
%caculates the ber fo CBPSK, DPSK, and Coherent GMSK for fading and no fading using
analytical means.
for b=1:1:50;
% sn is the signal to noise ratio in DBs;
sn(b)=b;
snr(b)=10.0^(b/10);
xx=erfc(sqrt(snr(b)));
bpsk(b)=0.5*xx;%BPSK no fading
Page 186 of 246
denmr=sqrt(1.0+1.0/snr(b));
bpskf(b)=0.5*(1-1.0/denmr);% BPSK fading;
dpsk(b)=0.5*exp(-snr(b));%DPSK no fading
dpskf(b)=0.5*1/(1+snr(b));%DPSK fading
factor=sqrt(0.89*snr(b));
factor2=sqrt(1+0.89*snr(b));
gmsk(b)=erfc(factor);%GMSK no fading; factor =0.89 for BT=0.3
gmskf(b)=0.5*(1-factor/factor2);%GMSK fading
end;
figure (1)
semilogy(sn,bpsk,'r',sn,bpskf,'k'); %y axis is log;
legend('BPSK--Gaussian Channel','BPSK--Rayleigh Channel')
axis([1.0 50.0 .00001 0.1]);
xlabel('signal-to-noise ratio dB')
ylabel('probability of error')
figure (2)
semilogy(sn,dpsk,'r',sn,dpskf,'k'); %y axis is log;
legend('DPSK--Gaussian Channel','DPSK--Rayleigh Channel')
axis([1.0 50.0 .00001 0.1]);
xlabel('signal-to-noise ratio dB')
ylabel('probability of error')
figure (3)
semilogy(sn,gmsk,'r',sn,gmskf,'k'); %y axis is log;
legend('GMSK--Gaussian Channel','GMSK--Rayleigh Channel')
axis([1.0 50.0 .00001 0.1]);
xlabel('signal-to-noise ratio dB')
ylabel('probability of error')
Page 187 of 246
Problem 8. The density function of the scaling factor is uniform. The bit error rate for BPSK
is given by
( )
1
2
erfc z where Z is the SNR. The probability of error when the scaling factor is
random is given by
2
1
2
erfc a z where the pdf of a is given by
( ) 0.5; 0 2 f a a .
The average probability of error when the scaling factor is present is given by
( ) ( )
2 2
2 2
0 0
1 1 1
2 2 4
erfc a z da erfc a z da

This integral has been evaluated numerically.
%pskpuniformfading.m
clear
close all
Page 188 of 246
%computes the error rate uniform fading :exercise 4-6
for k=2:50;
global snr
sn(k)=k;%signal-to-noise raio in dB
snr=10.^(k/10);
aa=quadl('funerr',0,2);%numerical integration
ber(k)=0.5*erfc(sqrt(snr));
berf(k)=aa;
end;
semilogy(sn,ber,'g',sn,berf,'r');
ylim([1e-6 0.1])
legend('no fading','fading-uniform density')
xlabel('signal-to-noise ratio dB')
funerr.m
function y=funerr(xx)
global snr
%for pskuniformfading
y=0.25*erfc(sqrt(snr*xx.^2));
Page 189 of 246
The error rates come down very slowly as the signal-to-noise ratio increases. This means that a
high power margin may be required to compensate for the fading.
Problem 9. The density function of the phase, ( ) ( )
9
,
2 9 9
f rad

. The probability
of error when the phase mismatch is uniform is given by
( )
18
18
9 1
cos
2 2
erfc z d

.
%pskpuniphase.m
clear
close all
%computes the error rate uniform fading
for k=2:50;
global snr
sn(k)=k;%signal-to-noise raio in dB
snr=10.^(k/10);
aa=quadl('funpha',-pi/9,pi/9);%numerical integration
ber(k)=0.5*erfc(sqrt(snr));
berf(k)=aa;
end;
semilogy(sn,ber,'g',sn,berf,'k');
ylim([1e-6 0.1])
xlim([2 15])
legend('no fading','uniform phase')
xlabel('signal-to-noise ratio dB')
ylabel('Probability of error')
funpha.m
function y=funpha(xx)
global snr
%for pskuniphase
y=(9/(2*pi))*0.5*erfc(sqrt(snr)*cos(xx));
Page 190 of 246
The probability of error in presence of fading is only slightly worse than the probability error in
the absence of fading.
Problem 10. The Rician pdf is given by
2 2
0 0
0 2 2 2
exp
2
a A aA a
I
b b b
_ +
_


,
,
with K(dB) given by
( ) ( )
10
10log K dB k where
2
0
2
2
A
k
b
The pdf ( )
Rice
f z of the power (or the signal-to-noise
ratio) of the power (or SNR) Z =A
2

is given by
( )
( )
( )
[ ]
[ ]
0
0 0 0
1 1
exp exp 4 1
Rice
z k k z
f z k I K k
z z z
_ _ + +
+


, ,
where
[ ]
2 2 2 2
0 0
2 2 1 z averagepower a z b A b k + +
Note that when 0 k , the pdf of the SNR becomes
0 0
1
exp
z
z z
_


,
as we have seen in the case
of Rayleigh fading.
Page 191 of 246
The average error probability is given by ( )
0
1
2
Rice
erfc z f z dz

.
The integration to obtain the average probability of error can be done numerically using
trapezoidal rule.
%ricianerror1.m
%calculates the error probability in Rician fading for BPSK
%uses trapz to calculate the integral
clear all
close all
KD=[-25 -10 0 5 10 15];%K factor in dB
for m=1:6
kdb=10^(KD(m)/10);
k1=kdb+1;
for k=4:50;
snr(k)=k+1;%snr in dB
sn=10^(snr(k)/10);
x=0:pi/500:0.99*pi/2;%converts the integral from 0-inf to 0-pi/2
x1=tan(x);
x2=x1.^2;
er=0.5*erfc(sqrt(x1));
ex=exp(-x1*k1/sn);
exi=besseli(0,sqrt(4*kdb*k1*x1/sn));
xxs=1+x2;%sec^2
y=ex.*er.*exi.*xxs;
zz=trapz(x,y);
z(k)=exp(-kdb)*zz*k1/sn;%error rate in fading%%%%%% uses trapz to compute the integral
yy(k)=0.5*erfc(sqrt(sn));%no fading
end;
semilogy(snr,z,'r',snr,yy,'g')
ylim([0.0000001 .5])
xlim([5 25])
hold on
end;
Page 192 of 246
It is seen that as the Rician parameter increases in value, the error probability approaches that of
the no fading or Gaussian channel case. The higher values of the direct component mitigates the
variation in the signal components from the multipaths, reducing the effects of fading. We can
also come to the same conclusion by looking at the results from Chapter 2 where it is argued that
the channel becomes Gaussian as the K value increases.
Problem 11. The average error probability is given by ( ) ( )
0
1
exp
2
Rice
z f z dz

.
The integration to obtain the average probability of error can be done numerically using
trapezoidal rule.
%ricianerrordpsk.m
%calculates the error probability in Rician fading for DPSK
%uses trapz to calculate the integral
clear all
close all
KD=[-25 -10 0 5 10 15];%K factor in dB
for m=1:6
Page 193 of 246
kdb=10^(KD(m)/10);
k1=kdb+1;
for k=4:50;
snr(k)=k+1;%snr in dB
sn=10^(snr(k)/10);
x=0:pi/500:0.99*pi/2;%converts the integral from 0-inf to 0-pi/2
x1=tan(x);
x2=x1.^2;
er=0.5*exp(-x1);
ex=exp(-x1*k1/sn);
exi=besseli(0,sqrt(4*kdb*k1*x1/sn));
xxs=1+x2;%sec^2
y=ex.*er.*exi.*xxs;
zz=trapz(x,y);
z(k)=exp(-kdb)*zz*k1/sn;%error rate in fading%%%%%% uses trapz to compute the integral
yy(k)=0.5*exp(-sn);%no fading
end;
semilogy(snr,z,'r')
ylim([0.0000001 .5])
xlim([5 30])
hold on
end;
semilogy(snr,yy,'g')
xlabel('SNR dB')
ylabel('Probability of error')
Page 194 of 246
Problem 12. The first step in the diversity calculations is the derivation of the pdf of the
selection combiner. Using results of exercise # 5, we can write the expression for the pdf of the
selection combiner as
( ) ( ) ( )
1
1 1
, 0 2
2 2
M
M
div
a
f a Mf a F a M a

_
1
]
,
.
(Verify that this is a valid density function).
The average error probability is given by
( )
( )
( )
1 2 2
2 2
0 0
1 1 1
2 2 2 2
M
div
a
erfc a z f a da M erfc a z da


,

.
The average error probability is plotted for M=2, 4, 6.
pskuniformdiv.m
Page 195 of 246
%pskuniformdiv.m
clear
close all
%computes the error rate uniform fading with diversityexercise 4-6
global M
mn=[1 2 4 8];
for mm=1:4
M=mn(mm);
mfact=(M/2)*(1/2)^(M-1);
for k=1:16;
global snr
sn(k)=k+4;%signal-to-noise raio in dB
snr=10.^(sn(k)/10);
aa=quadl('funerrdiv',0,2);%numerical integration
berf(k)=(M/2)*aa;
end;
semilogy(sn,berf);
ylim([1e-6 0.1])
xlabel('signal-to-noise ratio dB')
ylabel('Probability of error')
hold on
end;
ssn=10.^(sn/10);
ber=0.5*erfc(sqrt(ssn));
semilogy(sn,ber,'g');
funerr.m
function y=funerr(xx)
global snr
%for pskuniformfading
y=0.25*erfc(sqrt(snr*xx.^2));
Page 196 of 246
Problem 13. The average error probability will be given by ( )
2
1
2
erfc a z f a da

.
Using the given density function, the average error probability is
( ) ( ) ( )
2
0
1
0.1 0.5 1 0.4 2
2
erfc za a a a da

+ + 1
]
.
This can be simplified to
0.1 1 1 0.1 1
(0) 0.5 0.4 4 0.2 4
2 2 2 2 4
erfc erfc z erfc z erfc z erfc z + + + + .
pskdeltafad.m
clear
close all
%pskdeltafad.m
%computes the average error probability for the exercise where the fading has a discrete density
function
Page 197 of 246
ssn=2:1:20;%snr in dB
sn=10.^(ssn/10);
ber=0.5*erfc(sqrt(sn));%no fading
berf=(1/20)*erfc(0)+0.25*erfc(sqrt(sn))+.2*erfc(sqrt(4*sn));%fading
berfd=(0.01/2)*erfc(0)+(0.35/2)*erfc(sqrt(sn))+(.64/2)*erfc(sqrt(4*sn));%fading after selection
diversity M=2
berfeq=(0.01/2)*erfc(0)+(0.1/2)*erfc(sqrt(sn))+(.33/2)*erfc(sqrt(4*sn))+(.4/2)*erfc(sqrt(9*sn))+
(.16/2)*erfc(sqrt(16*sn)); %equal gain M=2
semilogy(ssn,ber,'r',ssn,berf,'g',ssn,berfd,'k',ssn,berfeq,'b')
xlabel('signal-to-noise ratio dB')
ylabel('Average error probability')
ylim([0.0000001 .5])
xlim([5 20])
It is seen that error floor exists and it is equal to 0.05.
Problem 14. The first step in this exercise is to determine the pdf of the selection diversity
output. We have two independent identically distributed random variables, each having a pdf of
Page 198 of 246
( ) ( ) ( ) ( )
0.1 0.5 1 0.4 2 , 1,2.
j j j j
f a a a a j
1
+ +
]
The selection diversity output will be { }
1 2
max , a a a . This probability may be obtained as
follows:
outcome prob.
0 0.1
a
1
1 0.5
2 0.4
outcome prob.
0 0.1
a
2
1 0.5
2 0.4

Outcomes of choosing the largest
a
1
a
2
Largest Prob of this event Prob of this outcome
0 0 0 0.1*0.1 0.1*0.1=0.01

0 1 1 .1*.5
1 0 1 .1*.5 2(.1*.5)+.5*.5=0.35
1 1 1 .5*.5

0 2 2 0.1*0.4
2 0 2 0.1*0.4
1 2 2 0.5*0.4 2(0.1*0.4+.5*.4)+0.4*0.4=0.64
2 1 2 0.5*0.4
2 2 2 0.4*0.4
Thus, the pdf of the selection diversity is given by
( ) ( ) ( ) ( ) 0.01 0.35 1 0.64 2
sel
f a a a a + + .
The average error probability after selection diversity is given by
( ) ( ) ( ) ( )
2
0
1 .01 0.35 0.64
0.01 0.35 1 0.64 2 0 4
2 2 2 2
erfc a z a a a da erfc erfc z erfc z

+ + + + 1
]
.
See the m file and figure in the solution to exercise # 13.
Page 199 of 246
Problem 15. The equal gain diversity is a simple addition of the two outcomes: The pdf of
the equal gain diversity is given by
( ) ( ) ( ) ( ) ( ) ( ) 0.01 0.1 1 0.33 2 0.4 3 .16 4
eq
f a a a a a a + + + + .
The average error probability through the use of an equal gain diversity system is
( ) ( ) ( ) ( ) ( )
( )
2
0
1
0.01 0.1 1 0.33 2 0.4 3 .16 4
2
.01 0.1 0.33 0.4 0.16
0 4 9 16
2 2 2 2 2
erfc a z a a a a a da
erfc erfc z erfc z erfc z erfc z

+ + + + 1
]
+ + + +

.
Note that the improvement over the selection diversity occurs at low values of the SNR. As SNR
goes to infinity, the error floor for the selection and equal gain diversity becomes 0.005.
See the m file and figure in the solution to exercise # 13.
Problem 16. The error probability in Gaussian channels for DPSK format is given by
( )
1
exp
2
z where z is the signal-to-noise ratio. When fading is present, the signal-to-noise ratio
becomes a random variable. Nakagami fading is a general fading model which can encompass
both Rayleigh and Rician fading. The pdf of the Nakagami distributed envelope is given by
( )
2 1
2
2 exp
m
m
m a m
a
m

_ _



, ,
.
Once again defining Z=A
2
, the pdf ( )
N
f z of the Nakagami distributed signal-to-noise ratio is
given by
( )
( )
1
0 0
exp
m
m
N
m z m
f z z
z m z

_ _

, ,
where z
0
is the average signal-to-noise ratio given by
2
0
z a z .
When m=1, we have Rayleigh statistics and when m>1 we have Rician statistics. When m ,
we approach the ideal Gaussian channel.
Page 200 of 246
The average error probability (for DPSK) in Nakagami fading is given by
( ) ( ) ( )
( )
1
0 0 0 0
1 1
exp exp exp
2 2
m
m
N
m z m
z f z dz z z dz
z m z

_ _

, ,

.
This can be easily integrated to
0
1
2
m
m
m z
1
1
+
]
.
nakadpsk.m
%nakadpsk.m
%computation of BER in presence of Nakagami fading
close all
clear
m=[1 1.5 2 5 10 50];%m=1 corresponds to Rayleigh
for km=1:6;
naka=m(km);%m-value
for k=4:30;
sn(k)=k;
ss=10^(k/10);%snr
pe(k)=0.5*(naka/(naka+ss))^naka;
end;
semilogy(sn,pe);
xlabel('signal-to-noise ratio dB')
ylabel('Average error probability')
ylim([0.0000001 0.5])
xlim([5 30])
hold on
end;
sf=10.^(sn/10);
dpske=0.5*exp(-sf);%no fading
semilogy(sn,dpske,'r');
Page 201 of 246
It seen that as m increases, the error probability approaches that of Gaussian channel. The results
are similar to those seen with Rician fading. Large values of K correspond to high values of m.
Problem 17. nakabpsk.m
%nakabpsk.m
%computation of BER in presence of Nakagami fading
close all
clear
m=[1 1.5 2 5 10 50];%m=1 corresponds to Rayleigh
for km=1:6;
naka=m(km);%m-value
for k=4:30;
sn(k)=k;
ss=10^(k/10);%snr
mz=(naka/ss)^naka;
gm=gamma(naka);
x=0:pi/500:0.99*pi/2;%converts the integral from 0-inf to 0-pi/2
x1=tan(x);
x2=x1.^2;
xxs=1+x2;%sec^2
Page 202 of 246
er=0.5*erfc(sqrt(x1));
ex1=exp(-naka*x1/ss);
xm=x1.^(naka-1);
y=ex1.*xm.*er.*xxs;
zz=trapz(x,y);
pe(k)=zz*mz/gm;
end;
semilogy(sn,pe);
xlabel('signal-to-noise ratio dB')
ylabel('Average error probability')
ylim([0.0000001 0.5])
xlim([5 30])
hold on
end;
sf=10.^(sn/10);
bpske=0.5*erfc(sqrt(sf));%no fading
semilogy(sn,bpske,'r');
Page 203 of 246
Problem 18.The average error probability for the case of BPSK in presence of Rayleigh
fading can be expressed as
0 0 0
1 1
exp
2
z
erfc z dz
z z

where we have used the exponentially


distributed signal-to-noise ratio (when the envelope is Rayleigh distributed). The average signal-
to-noise ratio is given by z
0.
Equation above can be integrated (by parts) leading to
( ) ( )
0 0 0
0
1 1
exp exp
2 2
z z d
erfc z erfc z dz
z z dz

1
_ _
1
+
1
]
, , ]

( )
0 0
1
1 exp
2
z d
erfc z dz
z dz

1 _
1
+
1
]
, ]

where we have made use of the fact that erfc(0)=1.


( ) ( )
2 2 1
exp
x
z
d d
erfc z e dx z
dz dz z

1
1

1
]
1
]

.
This result has been obtained using Leibnizs rule (See the end of this section).
The average error probability now becomes
( )
0 0 0 0
1 1 1 1 1
1 exp exp 1 exp
2 2
z z
z dz z dz
z z z z

1 1 _ _

1 1
, , ] ]

This readily integrates to
0
1 1
1
2 1
1
z
1
1
1

1
+
1
1
]
.
Problem 19. The average probability of error for DPSK in Rayleigh fading is given by
( )
0 0 0
1 1
exp exp
2
z
z dz
z z

_


,

.
This can be simplified to
Page 204 of 246
( )
0 0 0 0
1 1 1 1
exp 1
2 2 1
z dz
z z z

_ 1
+

1

+
] ,

.
Problem 20.
%simpleselectionexp.m
%conducts a selection diversity using exponential random numbers
clear
close all
N=1000;
x1=exprnd(1,1,N);
x2=exprnd(1,1,N);
x3=exprnd(1,1,N);
x4=exprnd(1,1,N);
x5=exprnd(1,1,N);
x6=exprnd(1,1,N);
x7=exprnd(1,1,N);
x8=exprnd(1,1,N);
x9=exprnd(1,1,N);
x10=exprnd(1,1,N);
xsel=max(max(max(max(max(max(max(max(max(x1,x2),x3),x4),x5),x6),x7),x8),x9),x10);
n=1:N;
plot(n(1:10),x1(1:10),'g*',n(1:10),x2(1:10),'k+',n(1:10),xsel(1:10),'rd')
ratio1=mean(x1)/std(x1)
ratiosel=mean(xsel)/std(xsel)
xlabel('sample number')
ylabel('sample values')
legend('any one set','another set','largest of the ten sets')
Page 205 of 246
ratio = 0.96
ratio = 2.27 (after compounding)
Problem 21. The density function of the SNR (MRC) is
( )
0
1
0
1
1 !
M
M
e
M

where
0
is the average SNR. The probability that the SNR is less than a threshold
th
is given
by
( )
[ ]
0
1
0
0 0
1
, ,
1 !
th M
th M
e d gamcdf M
M

where gamcdf is the cumulative distribution function of the gamma distributed random variable.
We are given that
0
is 5 dB or 10 and
th
is 0 dB or 1.
The outage probability is 1, , 10 . gamcdf M
1
]
This function is available in the Statistics
Toolbox.
Page 206 of 246
For M=3, the outage is 0.0042.
For M = 4, the outage is 3.2397e-004.
Problem 22. Eqn. (5-18) from the text gives the outage probability for the case of a selection
combiner as
( )
0
1 exp
th
M

1

]
.
For M=3, the outage is 0.0199.
For M=4, the outage is 0.0054.
Problem 23. MRCSELcomp
clear
%MRCSELcomp.m
%compares the outage due to MRC and selection diversity
close all
SNRa=sqrt(3);%average SNR
SNRt=1;%threshold
M=1:8;%diversity order
MRCoutage=gamcdf(SNRt,M,SNRa);
SELoutage=(1-exp(-SNRt/SNRa)).^M;
semilogy(M,SELoutage,'r',M,MRCoutage,'k'),title('Outage--Diversity')
legend('Selection','MRC')
xlabel('M')
ylabel('Outage probability')
Page 207 of 246
Problem 24 .pskmargin.m
clear
close all
%pskmargin.m
%computes the power margin as a function of the bit error rate for BPSK (Coherent) and DPSK.
%computes the power margin as a function of the bit error rate for BPSK (Coherent) and
Rayleigh faded CBPSK.
for k=1:1001;
ber(k)=1e-6*(k-1)*10;
be2=2*ber(k);
ZB=(erfinv(1-be2))^2;%SNR required in BPSK
ZD=-log(be2);%SNR required in DPSK
ZFD=1/((1/(1-be2))^2-1);%SNR required in fading coherent BPSK
ZDD=1/be2-1;%SNR required in fading DPSK
CtoDP(k)=10*log10(ZD)-10*log10(ZB);%excess snr required to have identical error rates
BPSK and DPSK
CtoCfad(k)=10*log10(ZFD)-10*log10(ZB);%excess snr required to have identical error rates
BPSK and faded BPSK
Page 208 of 246
CDtoCDfad(k)=10*log10(ZDD)-10*log10(ZD);%excess snr between fading and no fading
DPSK
end;
figure
semilogx(ber,CtoDP);
xlabel('bit error rate')
ylabel('Power Margin dB: DPSK-CBPSK')
figure
semilogx(ber,CtoCfad);
xlabel('bit error rate')
ylabel('Power Margin dB: CBPSK(Rayleigh fading-no fading)')
figure
semilogx(ber,CDtoCDfad);
xlabel('bit error rate')
ylabel('Power Margin dB: DPSK-fading DPSK')
Problem 25.See pskmargin.m in solution to exercise # 24.
Page 209 of 246
Problem 26. We have seen (see Problem #27 of Chapter 2) that a Rician approaches a
Gaussian when the Rician parameter K (dB) goes up. Thus, because of the existence of the LOS
path, the Rician channel approximates to a Gaussian as K increases. Rayleigh channel, on the
other hand, will approach a Gauusian channel only if diversity is used. In other words, the
performance of the communication systems in Rician channels will be better than the
performance in Rayleigh channels.
Problem 27. channelcapray.m , cap.m, and cap2.m
%channelcapray.m
clear
close all
%computes the channel capacity in Rayleigh fading and in diversity
%C=log2(1+snr); snr will be exponentially distributed with the parameter average snr
global snra
global M
M=4;
for k=1:30;
Page 210 of 246
kr=-10+k;
snra=10^(kr/10);
sn(k)=kr;%signal-to-noise raio in dB
aa=quadl('cap',0,pi/2);
ab=quadl('cap2',0,pi/2);
cr(k)=aa;%Rayleigh faded capacity
c(k)=log2(1+snra);%Gaussian channel
cab(k)=ab;%MRC diversity M=4
end;
plot(sn,c,'k',sn,cr,'r',sn,cab,'g');
xlabel('average signal-to-noise ratio dB');
ylabel('average spectral efficiency bits/s/Hz')
function y=cap(x)
global snra
xx=tan(x);
xy=log2(1+xx);
x1=sec(x);
x2=x1.^2;
ex=exp(-xx/snra);
y=(1/snra)*ex.*xy.*x2;
function yy=cap2(x)
global snra
global M
xx=tan(x);
xy=log2(1+xx);
x1=sec(x);
x2=x1.^2;
ex=exp(-M*xx/snra);
M1=(M^M)/gamma(M);
y1=xx.^(M-1);
yy=((1/snra)^M)*M1*ex.*xy.*y1.*x2;
Page 211 of 246
Problem 28. See channelcapray.m, cap.m, and cap2.m in the solution to the Problem #
27.
Problem 29. channelcapNaka.m and capnaka.m
%channelcapNaka.m
close all
clear
%computes the channel capacity Nakagami fading
%C=log2(1+snr); snr will be exponentially distributed with the parameter average snr
m=[1 1.5 2 5];
global snra
global mm
for k=1:4
mm=m(k);
for k=1:30;
kr=-10+k;
snra=10^(kr/10);
sn(k)=kr;%signal-to-noise raio in dB
Page 212 of 246
abn=quadl('capnaka',0,pi/2);
cn(k)=abn;%Nakagami faded
c(k)=log2(1+snra);%Gaussian channel
end;
plot(sn,cn,'r');
xlabel('average signal-to-noise ratio dB');
ylabel('average spectral efficiency bits/s/Hz')
hold on
end;
plot(sn,c,'k')
function yy=capnaka(x)
global snra
global mm
xx=tan(x);
xy=log2(1+xx);
x1=sec(x);
x2=x1.^2;
ex=exp(-mm*xx/snra);
M1=(mm^mm)/gamma(mm);
y1=xx.^(mm-1);
yy=((1/snra)^mm)*M1*ex.*xy.*y1.*x2;
Page 213 of 246
Problem 30. Results of Problem #29 show that as the value of m increases, the channel
capacity approaches that of an ideal channel. When m increases beyond 1, the Rician parameter
K also increases (See Problem #27 of Chapter 2) with m. Thus, the performance of Rician
channel will approach that of an ideal channel when K becomes large.
Problem 31. Results of Problems #16 and #17 show that when the Nakagami
parameter goes up from m=1, the error probability (for a given SNR) starts coming down. If we
explore the properties of the Nakagami density functions and the pdf of the sum of two
Nakagami distributed random variables, it can be shown that the sum of two Nakagami
distributed random variable is another Nakagami random variable with vale of m
sum
=2m. The
equal gain diversity combination will lead to the sum of two envelopes from the two branches,
each Nakagami distributed. The sum will once again be Nakagami distributed with an m-value
equal to twice the m-value of the individual branch. Based on the results of exercises #16 and 17,
it can now be concluded that the increase in m value of the envelope brought on through
diversity will lead to lower error probabilities.
Problem 32. bpskfaddivM.m
***An important note**** When simulations are undertaken using random numbers, it must be
remembered that you may need to do the simulation a few times to verify the conclusions.
Page 214 of 246
clear
%bpskfaddivM.m fading
%three pulses are added
close all
%examines the fading of pulse/shapes
%the program prompts the fractional delays; noise added. demodulation of the faded and
unfaded BPSK modulation schemes
%equal gain diversity is used
fc=10e3;%carrier frequency
ppf=2*pi*fc;
fs=12*fc;%sampling rate
ddt=1/fs;
nn=1e-3/ddt;%total number of samples in one m sec
M=2^(nextpow2(nn));
N=8;%number of bits
a=[1 1 -1 -1 -1 1 -1 1];
kp=floor(nn/8);%creates the width of the pulse
del=0.3;%'enter the fractional (of the duration) delay...between 0.25 and 0.75.>>');
dd1=round(del*kp);
del2=0.56;%('enter the fractional (of the duration) second delay...between 0.25 and 0.75.>>');
dd2=round(del2*kp);
%sd=input('enter the std dev.of additive white noise (fraction of the signal voltage..0.02-0.7.>>');
sd=0.1;%std dev.of additive white noise (fraction of the signal voltage..0.02-0.7.
sdiv=[zeros(1,kp*8)];
mdiv=input('enter the order of diversity to be used 1,2,..10 or 15 >>>');
for kdiv=1:mdiv;%diversity of order
for ku=1:8;
for k=(ku-1)*kp+1:kp*ku
tt(k)=k*ddt;
s(k)=a(ku);%creates the pulse stream
sf(k)=a(ku)*cos(ppf*tt(k));%rf pulse
sf1(k)=5*rand(1)*cos(ppf*tt(k)+2*pi*rand(1));%random phase, random amplitude
sf2(k)=10*rand(1)*cos(ppf*tt(k)+2*pi*rand(1));%random phase,random amplitude
end;
end;
for k=1:kp*ku;
if k<=dd1
ss1(k)=0;
else
ss1(k)=s(k-dd1);%creates a delayed pulse stream
end;
end;
for k=1:kp*ku;
tt2(k)=k*ddt;
Page 215 of 246
if k<=dd2
ss2(k)=0;
else
ss2(k)=s(k-dd2);%creates a delayed pulse
end;
end;
sum=s+ss1+ss2;%added pulse shapes
sum=sum/max(abs(sum));%normalizes to unity
rfsum=sf+sf1.*ss1+sf2.*ss2;%added RF pulses, delayed, randomly weighted
rfsum=rfsum/max(abs(rfsum));%normalizes to unity
for k=1:kp*8;
sfd(k)=(rfsum(k)+normrnd(0,sd))*2*cos(ppf*tt(k));%coherent demodulation fading with noise
ssfd(k)=(sf(k)+normrnd(0,sd))*2*cos(ppf*tt(k));%coh. demodulation no fading
end;
[bb,aa]=butter(10,.2);
sfd=filtfilt(bb,aa,sfd);
ssfd=filtfilt(bb,aa,ssfd);
sdiv=sdiv+sfd;%add the demodulated signals from diversity
end;
sdiv=sdiv/max(abs(sdiv));%normalize
sfd=sfd/max(abs(sfd));
ssfd=ssfd/max(abs(ssfd));
plot(tt*1e3,s,tt*1e3,sf),title('bit stream [1 1 -1 -1 -1 1 -1 1]')
ylim([-2 2]);
xlabel('time ms')
ylabel('volts')
legend('input bit stream','input RF bit stream')
figure
plot(tt*1e3,sum,tt*1e3,rfsum),title('fading-effects of delay and random phase')
ylim([-2 2]);
xlabel('time ms')
ylabel('volts')
legend('bit stream in fading','RF bit stream in fading')
sfd=sfd/abs(max(sfd));
ssfd=ssfd/abs(max(ssfd));
mmd=num2str(mdiv);
title2=strcat('effect of diversity',' order= ', mmd)
figure
plot(tt*1e3,s,'r',tt*1e3,ssfd,'k',tt*1e3,sfd,'g',tt*1e3,sdiv,'b'),title(title2)
legend('Data','demodulated data-no fading','demodulated data-fading','diversity')
ylim([-2 2])
xlabel('time ms')
ylabel('volts')
for kk=1:N
ky=kp/2+(kk-1)*kp;
Page 216 of 246
if ssfd(ky)>0 %coh. demodulation noise only
b(kk)=1;
else
b(kk)=-1;
end;
if sfd(ky)>0;%coh. demodulation fading
c(kk)=1;
else
c(kk)=-1;
end;
if sdiv(ky)>0;%coh. demodulation diversity
d(kk)=1;
else
d(kk)=-1;
end;
end;
'input bit stream'
a
'output bit stream..coherent deomodulation'
b
'output bit stream coh. demodulation fading'
c
'output bit stream coh. demodulation diversity'
d
Page 217 of 246
Page 218 of 246
Page 219 of 246
Problem 33. See the m file and diagrams in Problem # 32.
Diversity of order 100
input data
1 1 -1 -1 -1 1 -1 1
output bit stream..coherent deomodulation
1 1 -1 -1 -1 1 -1 1
output bit stream coh. demodulation fading
-1 -1 1 1 1 -1 -1 -1
output bit stream coh. demodulation diversity
1 1 -1 -1 -1 1 -1 1
Page 220 of 246
Leibnizs Rule is used when we have to differentiate an integral. Let
( ) ( )
( )
( )
,
b u
a u
G u H x u dx

.
We are now interested in finding out the derivative of G w.r.t u.
( ) ( ) ( ) ( ) ( )
( )
( )
( ) , , ,
b u
a u
d d d
G u H b u u b u H a u u a u H x u dx
du du du u

+ 1 1 1 1 1 1
] ] ] ] ] ]

.
Page 221 of 246
Chapter 6
Problem 1

Frequency
0
5 KHz
Spectrum (Magnitude)
The bandwidth available = 400 KHz.
Number of channels available =
400
80
5
.
Problem 2
Page 222 of 246
2.

BPF
LPF
message
BPF
LPF
message
BPF
LPF
message
BPF
LPF
message
BPF
LPF
message
BPF
LPF
message
cos(2f
ck
t)
cos(2f
ck+1
t)
cos(2f
ck-1
t)
Problem 3. cdmapulse.m
clear
%cdmapulse.m
%generates the CDMA pulses
close all
N=8;
T=512;
Tc=T/N;
Page 223 of 246
for k=1:1024;
x(k)=k;
if k<=512
y(k)=1;
else
y(k)=-1;
end;
end;
for jp=1:2*N;%generates +1 and -1 with equal probability;
xj=rand(1);
if xj <=0.5
a(jp)=-1;
else
a(jp)=1;
end;
end;
for kk=1:1024;
xx(kk)=kk;
kf=floor((kk-1)/Tc);
jj=1+kf;%creates the chips
yy(kk)= a(jj);
zz1=yy(kk)+y(kk);
if zz1==0
z(kk)=1;%modulo 2 addition....-1+1 and 1+-1 ==1, -1+-1 and +1+1==0
else
z(kk)=0;
end;
end;
figure
subplot(3,1,1);
plot(x,y,'k'), title('two bits')
axis off
%ylim([-1.5 1.5]);
subplot(3,1,2);
plot(xx,yy,'k'), title('chip sequence')
axis off
%ylim([-1.5 1.5]);
subplot(3,1,3);
plot(x,z,'k'),title('modulo 2 addition of chip and data sequences')
axis off
Page 224 of 246
%ylim([-1.5 1.5]);
figure
for mm=1:1024
if mm<=512
yb(mm)=y(mm);
else
yb(mm)=0.0;
end;
if mm<=64
yyb(mm)=yy(mm);
else
yyb(mm)=0.0;
end;
end
plot(x,abs(fft(yb,1024))/max(abs(fft(yb,1024))),'r',x,abs(fft(yyb,1024))/max(abs(fft(yyb,1024))),'
k');
xlim([0 64])
xlabel('sample number')
ylabel('Normalized spectrum')
legend('data','chip')
figure
bpy=yy.*cos(2*pi*(1/Tc)*x);
figure
plot(x,bpy,'.')
ylim([-2 2])
ylabel('BPSK-DSSS signal')
xlabel('sample number')
xlim([1 1024])
Page 225 of 246
Problem 4. cdmapulse.m (See the m file in Problem #3)
Note that the 8
th
zero crossing of the bit spectrum falls on the first zero crossing of the chip
spectrum. In other words, there is 1:8 bandwidth expansion factor
Page 226 of 246
Problem 5. cdmapluse (see the m file in Problem # 3)
Page 227 of 246
Problem 6. Number of users or channels =64
Data rate= 4800 bps
BER in the absence of any thermal noise =
1
2 1
K
erfc
k
1
1

]
where K is the processing
gain.
Thus,
3
1 1
10 1
2 63 2 63
K K
erfc erf

_
1 1

1 1

] ] ,
. Using erfinv command from MATLAB,
we can write
( )
2
3
63 1 2 10 K erfinv

1

]
=301.
Chip rate = 4800 301 =1.448 megachips/s.
Problem 7. The BER is given by
1
2 1
K
erfc
k
1
1

]
with K=1000 and BER =10
-6
.
Page 228 of 246
The number of users is given by
( )
2
6
1000
1 90
1 2 10 erfinv

+
1

]
.
Problem 8. Processing gain = 20 dB 100 =
chiprate
datarate
.
Therefore, the chip rate must be 9600 100 96kbps .
Problem 9. Length of the PN sequence
10
2 1 2 1 1023
m
N .
Bit duration = 1023 .1 102.3 s s .
Processing Gain = ( )
10
10log 1023 30dB .
Problem 10. The difference in propagation delay corresponding to a distance of 200 meters
=
8
200
0.666
3 10
s

where we have used the speed of the e.m wave to be


8
3 10 / m s . The
minimum chip rate is
6
1 10
/
.666 10 6
megachips s

.
Problem 11. Consider a chip sequence of length K. A single chip is shown in Figure Ex. 6-9.
Its autocorrelation will be of triangular shape as shown.
Let p(t) be the chip shape as shown. The PN stream b(t) can be written as
( ) ( )
n c
n
b t a t nT

.
The chip sequence a
n
is periodic, i.e.,
n n K
a a
+
. Thus, the period of the PN stream is will be the
time occupied by the sequence, i. e., KT
c
.
time
T
c
1
T
c
-T
c
Page 229 of 246
The autocorrelation is now carried out over the whole period of the sequence, i.e., KT
c
. The
autocorrelation R
b
() is given by
( ) ( ) ( )
0
1
c
KT
b
c
R b t b t dt
KT
+

.
The autocorrelation R
b
() can be rewritten as
( ) ( ) ( )
1
0
0
1
.
c
KT
K
b n m c c
n m c
R a a p t KT p t KT dt
KT


The inner summation over m depends on the value of t since the summation can start somewhere
in the middle of the period and continue to the middle of the next period. The summation over
the chip values (property of the PN sequence) can be obtained easily by noting that
( )
1
0, , 2 ,...
1
K
k k m
k
K f orm K K
C m a a
elsewhere
+


'

.
The autocorrelation function now becomes
Page 230 of 246
( )
( ) ( )
( )
1
, 0
1
, 1
p p c c
b
c c
R R T T
K
R
T K T
K

'

where
( ) ( ) ( )
1
p
c
R x p t p t x dx
T

.
Noting that the autocorrelation of the chip shape is triangular, the autocorrelation function
becomes
( )
1 1
1
c
b
n c
nKT
R
K T K

1 _
_
+
1
,
, ]

.
Page 231 of 246
Problem 12. The power spectral density can be easily obtained by observing that the
autocorrelation function is periodic, with a period of KT
c
. The basic shape is triangular with a
width of 2T
c
. Since the autocorrelation function is periodic, we may write it as
( )
0
2
e
j nf
b n
n
R r


with f
0
=
1
c
KT
and r
n
are the Fourier series coefficients. Since the Fourier transform of a triangular
pulse shape is a
2
sinc function, we may write the power spectral density of the PN stream P
s
(f)
as
( ) ( ) ( )
0 s b n
n
P f R r f nf

1
]

where
2
2
2
1
, 0
sin
1
, 0
n
n
K
n
r
K K
n
n
K
K

1
_

'

1
+
_ ,

, 1

1
]

Thus, the PSD contains a series of delta functions.


Page 232 of 246
Problem 13.CDMAcor3.m
%CDMAcor3.m correlation of PN sequences of length 7
%alows two sets of inputs
clear
N=7;
a=[1 -1 -1 1 -1 +1 1]; %first set
loopagn = ['y'];
while(loopagn == 'y')
close all
T=5;%Chip duration time units
MM=64;%number of sequences
NT=N*T;
Page 233 of 246
for kn=1:MM;
kb1=(kn-1)*NT;
for kb=1:NT;
zz=1+floor((kb-1)/T);%this gives the chips of duration T and will repeat after 7 bits
y(kb1+kb)=a(zz);
x(kb1+kb)=kb1+kb;
end;
end;
plot(x,y),title('64 chip sequences, each sequence of length 7');
ylim([-2 2])
xlim([0 140])
figure
z=xcorr(y,'biased');%this is the correlation with MM sequences with itself; biased
normalizes
x1=[1:2*NT*MM-1];%creates the X-coordinates
x2=x1-NT*MM;%shifts the center to the origin
plot(x2,z),title('A single period of the correlation function')
xlim([-20 20])
grid on
figure
plot(x2,z),title('Multiple periods of the correlation function')
xlim([-40 40])
grid on
min(z)% this gives the min of the autocorrelation =-1/N
%check is this value equal to 1/N
[px f]=psd(y,length(y),1);%power spectral density
figure
plot(f,px/length(px)),title('Power Spectral Density of the PN sequence')
xlabel('Frequency')
ylabel('PSD')
loopagn = input('\n Do you want to look a second set (type y for yes): ', 's');
a=[-1 +1 +1 -1 +1 -1 -1];%second set
end
Page 234 of 246
Page 235 of 246
Problem 14. See the m file in Problem #13 .
Answer -0.1473
Problem 15.
Page 236 of 246
Problem 16.CDMAspec.m
%CDMAspec.m calculates the PSD of a CDMA sequence
clear
N=7;
a=[1 -1 -1 1 -1 +1 1];
%calculates the correlation function of the PN sequence
close all
fc=20e3;%carrier frequency
ppf=2*pi*fc;
fs=10*fc;%sampling rate
ddt=1/fs;
nn=1e-3/ddt;%total number of samples in one m sec
kp=floor(nn/8);%creates the width of the pulse
kw=0;
for MM=1:16
for ku=1:N;
for k=(ku-1)*kp+1:kp*ku
kw=kw+1;
tt(kw)=kw*ddt;
s(kw)=a(ku);%creates the pulse stream
Page 237 of 246
sf(kw)=a(ku)*cos(ppf*tt(kw));
end;
end;
end;
figure
plot(tt*1e3,s), title(' two sequences, each of length 7 b(t)');
xlim([0 14*kp*ddt*1e3])
xlabel('time ms')
ylim([-2 2])
y=fft(s,2048);%FT of the sequence giving the PSD
f=fs*(0:length(y)/2)/length(y);
px=y.*conj(y)/length(y);%PSD
figure
plot(f*1e-3,px(1:length(f))),title('PSD of the PN sequence')
xlabel('Frequency KHz')
px(1)
figure
plot(tt*1e3,sf),title('b(t)cos(2\pif_ct)')
xlim([0 14*kp*ddt*1e3])
ylim([-2 2])
xlabel('time ms')
yy=fft(sf,2048);%FT of the correlation giving the PSD
f=fs*(0:length(yy)/2)/length(yy);
pxy=abs(yy)/length(yy);%PSD
figure
plot(f*1e-3,pxy(1:length(f))), title('PSD of b(t)cos(2\pif_ct)') ;
xlabel('Frequency KHz')
b(t) is the chip sequence.
Page 238 of 246
Page 239 of 246
Problem 17 .use CDMAcor3.m of Problem # 13.
Page 240 of 246
Page 241 of 246
The results are similar to those of exercise #13.
Problem 18. CDMAcor30.m
%CDMAcor30.m correlation of CDMA sequences with 0 in place of -1
clear
close all
N=7;
a=[[1 0 0 1 0 +1 1]];
%calculates the correlation function of the PN sequence
close all
T=5;%Chip duration time units
MM=64;%number of sequences
NT=N*T;
for kn=1:MM;
kb1=(kn-1)*NT;
for kb=1:NT;
zz=1+floor((kb-1)/T);%this gives the chips of duration T and will repeat after 7 bits
y(kb1+kb)=a(zz);
x(kb1+kb)=kb1+kb;
Page 242 of 246
end;
end;
plot(x,y),title('64 chip sequences, each sequence of length 7');
ylim([-2 2])
xlim([0 140])
figure
z=xcorr(y,'biased');%this is the correlation with MM sequences with itself; biased
normalizes
x1=[1:2*NT*MM-1];%creates the X-coordinates
x2=x1-NT*MM;%shifts the center to the origin
plot(x2,z/max(z)),title('A single period of the correlation function')
xlim([-20 20])
grid on
figure
plot(x2,z/max(z)),title('Multiple periods of the correlation function')
xlim([-40 40])
grid on
Page 243 of 246
Note that the correlation is always positive.
Problem 19. Slow hopping. Processing gain= 5x3= 15 or 10xlog
10
(15) =11.8 dB
Problem 20.
%problem6_20.m
%calculates the loading factor as a function of the signal-to-noise ratio
%voice activity reduction, intercell interference etc.
clear all
close all
snreq=10; %snr required in dB
sn=10^(0.1*snreq);%snr in absolute units
alpha=1;
aff(1)=1.2;
aff(2)=2.0
for kp=1:2
af=aff(kp);
for kk=1:20;
xxn=snreq+2*kk;
Page 244 of 246
x(kk)=xxn;%thermal noise SNR in dB
xx=10^(.2*xxn);
yr(kk)=(1/xx)*(xx-sn)*(1/alpha)*(1/(1+af));
xs(kk)=xxn-sn;%the difference in SNR;
end;
subplot(2,1,kp)
fval=num2str(af);
title1=strcat('f=',fval)
plot(x,yr),title(title1)
xlabel('(E/N_0)_s')
ylabel('cell utilization N_u')
end;
10 15 20 25 30 35 40 45 50
0.43
0.44
0.45
0.46
f=1.2
(E/N
0
)
s
c
e
l
l

u
t
i
l
i
z
a
t
i
o
n

N
u
10 15 20 25 30 35 40 45 50
0.32
0.33
0.34
f=2
(E/N
0
)
s
c
e
l
l

u
t
i
l
i
z
a
t
i
o
n

N
u
Problem 21.
Page 245 of 246
%problem6_21.m
%calculates the reduction in signal-to-noise ratio as the number of users
%increase
clear
snr=10%minimum acceptable snr in dB
sn=10^(snr/10);%snr in absolute units
K=64;%512/8
Nmax=floor(1+K/sn)%maximum number of ideal users..integer value
stn=18;%signal-to-thermal noise
stnu=10^(stn/10);%snr in absolute units
for kk=1:60;
N1=Nmax+(kk-1);
N(kk)=N1-Nmax;%additional users
y1=N1-1+K*(1/stnu);
snn=K/y1;
y(kk)=10*log10(snn);%effective snr in dB
end;
plot(N,y)
xlabel('Number of additional users')
ylabel('Effective signal-to-noise ratio')
ylim([0 10])
Page 246 of 246
0 10 20 30 40 50 60
0
1
2
3
4
5
6
7
8
9
10
Number of additional users
E
f
f
e
c
t
i
v
e

s
i
g
n
a
l
-
t
o
-
n
o
i
s
e

r
a
t
i
o
Problem 22
Proceeding similar to example 6.8, we have
1.5 1.1
max
1.5 1.1
1000
10 10
1 1000 49
10 10
K
N

1
+
1

]
Including the intracell interference parameter,
1.5 1.1
max 1.5 1.1
10 10 1
1 1000 27
10 10 1 .8
i
N
1
_
+
1
+
,
]
.