% msk2_fading.m
%
% Simulation program to realize MSK transmission system
% (under one path fading)
%
% Programmed by R.Sawai and H.Harada
%
%******************** Preparation part *************************************
sr=256000.0; % Symbol rate
ml=1; % ml:Number of modulation levels
br=sr.*ml; % Bit rate
nd = 100; % Number of symbols that simulates in each loop
ebn0=15; % Eb/N0
IPOINT=8; % Number of oversamples
%******************* Fading initialization ********************
% If you use fading function "sefade
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn); % sqrt: built in function
%********************** Fading channel **********************
% Generated data are fed into a fading simulator
[ifade,qfade]=sefade(ich2,qch2,itau,dlvl,th1,n0,itnd1,now1,length(ich2),tstp,fd,flat);
% Updata fading counter
itnd1 = itnd1+ itnd0;
%********************* Add White Gaussian Noise (AWGN) **********************
[ich3,qch3]= comb(ifade,qfade,attn);% add white gaussian noise
syncpoint = 1;
ich5=ich3(syncpoint:IPOINT:length(ich3));
qch5=qch3(syncpoint:IPOINT:length(qch3));
%**************************** MSK Demodulation *****************************
demoddata2(1,1)=-1;
for k=3:2:nd*ml+1
demoddata2(1,k)=ich5(1,k)*qch5(1,k-1)*cos(pi*(k))>0;
end
for n=2:2:nd*ml+1
demoddata2(1,n)=ich5(1,n-1)*qch5(1,n)*cos(pi*(n))>0;
end
[demodata]=demoddata2(1,2:nd*ml+1);
%************************** Bit Error Rate (BER) ****************************
noe2=sum(abs(data1-demodata)); % sum: built in function
nod2=length(data1); % length: built in function
noe=noe+noe2;
nod=nod+nod2;
fprintf('%d\%e\
',iii,noe2/nod2); % fprintf: built in function
end % for iii=1:nloop
%****************************** Data file ***********************************
ber = noe/nod;
fprintf('%d\%d\%d\%e\
',ebn0,noe,nod,noe/nod); % fprintf: built in function
fid = fopen('BERmsk2fad.dat','a');
fprintf(fid,'%d\%e\%f\%f\\
',ebn0,noe/nod,noe,nod); % fprintf: built in function
fclose(fid);
%******************** end of file ***************************下载本文