06.06.2022 Views

B. P. Lathi, Zhi Ding - Modern Digital and Analog Communication Systems-Oxford University Press (2009)

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

11 . 9 MATLAB Exercises 653

% can be turned on or off by inputting jamming=l or 0

% Non-coherent MFSK detection

% only needs to compare the magnitude of each frequency bin .

%

clear;clf

n=lOOOO;

L=8;

Lh=l ;

%Number of data symbols in the simulation

% Number of frequency bands

% Number of hops per symbol (bit)

m=l ;

% Number of users

% Generating information bits

s_data=round (rand (n,m) );

% Turn partial band jamming on or off

jamming=input ('jamming=? (Enter 1 for Yes , 0 for No ) ');

% Generating random phases on the two frequencies

xbasel= [exp (j*2 *pi* rand (Lh*n, 1 ))];

xbase0= [exp{j*2 *pi* rand (Lh*n, 1 ))];

% Modulating two orthogonal frequencies

xmodsig= [kron ( s_data,ones (Lh, 1) ) .*xbasel kron( (l-s_data) ,ones (Lh, l) ) .*xbas,

clear xbaseO xbasel;

% Generating a random hopping sequence nLh long

Phop=round (rand (Lh*n, l)* (L-1) )+1; % PN hopping pattern ;

Xsiga=sparse (l:Lh*n, Phop ,xmodsig (:,1));

Xsigb=sparse (l:Lh*n, Phop ,xmodsig (:,2 ));

% Generating noise sequences for both frequency channels

noisel=randn (Lh*n,l)+j*randn (Lh*n, l) ;

noise2=randn (Lh*n,l)+j *randn (Lh*n, 1) ;

Nsiga=sparse (l:Lh*n, Phop ,noisel);

Nsigb=sparse (l:Lh*n, Phop ,noise2);

clear noisel noise2 xmodsig;

BER= [] ;

BER_az= [J;

% Add a jammed channel (randomly picked)

if (jamming )

nch=round (rand* (L- 1) )+1;

Xsiga(:,nch) =Xsiga(:,nch) *O;

Xsigb(:,nch) =Xsigb(:,nch) *O;

Nsiga(:,nch) =Nsiga(:,nch) *O;

Nsigb(:,nch) =Nsigb(: ,nch) *O;

end

% Generating the channel noise (AWGN )

for i=l :10,

Eb2N (i)= i;

Eb2N_num=10 A (Eb2N(i)/10) ;

Var_n=l/ (2*Eb2N_num) ;

signois=sqrt (Var_n) ;

ychl=Xsiga+s ignois*Nsiga ;

ych2=Xsigb+signois*Nsigb ;

% Non-coherent detection

%(Eb/N in dB)

% Eb/N in numeral

%1/SNR is the noise variance

% standard deviation

% AWGN complex channels

% AWGN channels

for kk=O :n-1,

Yvecl= []; Yvec2= [];

for kk2=1 :Lh,

Yvecl= [Yvecl ychl ( kk*Lh+kk2 ,Phop (kk*Lh+kk2 ))];

Yvec2=[Yvec2 ych2 ( kk* Lh+kk2 ,Phop (kk*Lh+kk2 ))];

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!