
% qam16_fading
%
% Simulation program to realize 16QAM transmission system
% (under one path fading)
%
% Programmed by H.Harada and R.Funada
%
%******************** preparation part *************************************
sr=256000.0; % Symbol rate
ml=4; % ml:Number of modulation levels (BPSK:ml=1, QPSK:ml=2, 16QAM:ml=4)
br=sr .* ml; % Bit rate
nd = 100; % Number of symbols that simulates in each loop
ebn0=15; % Eb/N0
IPOINT=8; % Number of oversamples
%********************** Filter initialization **************************
irfn=21; % Number of taps
alfs=0.5; % Rolloff factor
[xh] = hrollfcoef(irfn,IPOINT,sr,alfs,1); %Transmitter filter coefficients
[xh2] = hrollfcoef(irfn,IPOINT,sr,alfs,0); %Receiver filter coefficients
%******************* Fading initialization ********************
% If you use fading function "sefade
*** Attenuation Calculation ***********************
spow=sum(ich2.*ich2+qch2.*qch2)/nd;
attn=0.5*spow*sr/br*10.^(-ebn0/10);
attn=sqrt(attn);
%********************** Fading channel **********************
% Generated data are fed into a fading simulator
[ifade,qfade,ramp]=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
%*************** Compensate the fluctuation of fading by ramp*******************
ich3=ich3./ramp(1:length(ramp));
qch3=qch3./ramp(1:length(ramp));
[ich4,qch4]= compconv(ich3,qch3,xh2);
sampl=irfn*IPOINT+1;
ich5 = ich4(sampl:IPOINT:length(ich4));
qch5 = qch4(sampl:IPOINT:length(ich4));
%**************************** 16QAM Demodulation *****************************
[demodata]=qamdemod(ich5,qch5,1,nd,ml);
%******************** Bit Error Rate (BER) ****************************
noe2=sum(abs(data1-demodata));
nod2=length(data1);
noe=noe+noe2;
nod=nod+nod2;
fprintf('%d\%e\
',iii,noe2/nod2);
end % for iii=1:nloop
%********************** Output result ***************************
ber = noe/nod;
fprintf('%d\%d\%d\%e\
',ebn0,noe,nod,noe/nod);
fid = fopen('BERqamfad.dat','a');
fprintf(fid,'%d\%e\%f\%f\\
',ebn0,noe/nod,noe,nod);
fclose(fid);
%******************** end of file ***************************
