%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%qpsk
ebn0indB=0:1:14; % Eb/N0
for i=1:length(ebn0indB);
%ebn0=3; % Eb/N0
sr=256000.0; % Symbol rate
ml=2; % ml:Number of modulation levels (BPSK:ml=1, QPSK:ml=2, 16QAM:ml=4,64QAM=16)
br=sr .* ml; % Bit rate
nd = 128; % Number of symbols that simulates in each loop
IPOINT=8;
A = [1 1/exp(1) 1/exp(2)];
N = 64;
GI = 16;
Mt = 1;
Mr = 1;
sig2 = 1e-3;
N=64;
%************************* 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
%******************** START CALCULATION *************************************
nloop=10; % Number of simulation loops
noe = 0; % Number of error data
nod = 0; % Number of transmitted data
for iii=1:nloop
%*************************** Data generation ********************************
data1=rand(1,nd*ml)>0.5;
%*************************** QPSK Modulation ********************************
[ich,qch]=qpskmod(data1,1,nd,ml);
[ich1,qch1]= compoversamp(ich,qch,length(ich),IPOINT);
[ich2,qch2]= compconv(ich1,qch1,xh);
%**************************** Attenuation Calculation ***********************
spow=sum(ich2.*ich2+qch2.*qch2)/nd;
attn=0.5*spow*sr/br*10.^(-ebn0indB(i)/10);
attn=sqrt(attn); % sqrt: built in function
%********************* Add White Gaussian Noise (AWGN) **********************
[ich3,qch3]= comb(ich2,qch2,attn);% add white gaussian noise
[ich4,qch4]= compconv(ich3,qch3,xh2);
syncpoint=irfn*IPOINT+1;
ich5=ich4(syncpoint:IPOINT:length(ich4));
qch5=qch4(syncpoint:IPOINT:length(qch4));
%**************************** QPSK Demodulation *****************************
[demodata]=qpskdemod(ich1,qch1,1,nd,ml);
%************************** Bit Error Rate (BER) ****************************
noe2=sum(abs(data1-demodata));
nod2=length(data1);
noe=noe+noe2;
nod=nod+nod2;
end % for iii=1:nloop
%********************** Output result ***************************
ber = noe/nod;
s1(i)=ebn0indB(i);
s2(i)=ber;
%s3(i)=noe
%s4(i)=nod
semilogy(s1,s2,'r');axis([0, 14 ,0.1, 1]);
end
评论1