📄 qpsk.m
字号:
% Program 3-5
% qpsk.m
%
% Simulation program to realize QPSK transmission system
%
% Programmed by H.Harada and T.Yamamura
%
%******************** Preparation part *************************************
clear all;
sr=256000.0; % Symbol rate
ml=2; % 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=3; % 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
%******************** START CALCULATION *************************************
ebn0=0:10;
nloop=100; % Number of simulation loops
for i = 1:length(ebn0)
noe = 0; % Number of error data
nod = 0; % Number of transmitted data
Eb=ebn0; % Since N0=1
for iii=1:nloop
%*************************** Data generation ********************************
data1=rand(1,nd*ml)>0.5; % rand: built in function
%*************************** 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; % sum: built in function
attn=0.5*spow*sr/br*10.^(-ebn0(i)/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(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(ich5,qch5,1,nd,ml);
%************************** 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\t%e\n',iii,noe2/nod2); % fprintf: built in function
end % for iii=1:nloop
%********************** Output result ***************************
ber(i) = noe/nod;
Qx=(1/2)*erfc((10.^(Eb/10))/sqrt(2)); %Q function
end
% figure
figure
semilogy(ebn0,ber,'bo-',ebn0, Qx,'rx-');
Title('Performence of QPSK');
axis([0 10 1E-4 1]);
xlabel('Eb/N0(dB)');
ylabel('BER');
legend ('QPSK AWGN (Simulation)','QPSK AWGN (Theory)');
grid on;
%******************** end of file ***************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -