Single/Multipath Channel Model Verificaiton
EbNo vs. BER/SER under AWGN
BPSK vs. QPSK
Theory vs.
源代码在线查看: qpsk.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File Name: qpsk.m
% Function: qpsk simulation
% Author:
% Date: 11.28
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Preparation part %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
sr=256000.0; % symbol rate
ml=2; % number of modulation levels (QPSK:ml=2)
br=sr .* ml; % bit rate
nd = 1000; % number of symbols that simulates in each loop
Eb_N0=0:1:30;% Eb/N0
nloop=500; % number of simulation loops
for i=1:length(Eb_N0)
noe = 0; % number of error data
nod = 0; % number of transmitted data
soe = 0; % number of error symbol
sos = 0; % number of transmitted symbol
totalb = 0;
totals = 0;
for ii=1:nloop
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Data Generation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data1=rand(1,nd*ml)>0.5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% QPSK Modulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[ich,qch]=qpskmod(data1,nd,ml);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Attenuation Calculation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
spow=sum(ich.*ich+qch.*qch)/nd;
attn=0.5*spow*sr/br*10.^(-Eb_N0(i)/10);
attn=sqrt(attn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% AWGN %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[ich2,qch2]= qpskawgn(ich,qch,attn);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% QPSK Demodulation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[demodata]=qpskdemod(ich2,qch2,nd,ml);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BER/SER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
noe2=sum(abs(data1-demodata));
nod2=length(data1);
noe=noe+noe2;
nod=nod+nod2;
totalb = totalb + noe/nod;
soe = soe + qpskser(data1,demodata,ml);
sos = sos + length(data1) ./ ml;
totals = totals + soe/sos;
end % for ii=1:nloop
Avg_BER(i) = totalb/nloop;
Theory(i) = (1/2) * erfc(sqrt(10.^(Eb_N0(i)/10)));
SER(i) = totals/nloop;
SNR(i) = 10*log10(10^(Eb_N0(i)/10) ./ ml);
end % Eb_N0=0:1:10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Output EbN0 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%figure;clf;
% semilogy(Eb_N0,Avg_BER,'b-o');
% title('QPSK EbN0 vs. BER/SER (AWGN)');
% xlabel('Eb/N0(dB)');
% ylabel('BER/SER');
% grid on;
% hold on;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Theorectical BER %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% semilogy(Eb_N0,Theory,'r-*');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% semilogy(Eb_N0,SER,'r-*');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Output SNR %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;clf;
semilogy(SNR,Avg_BER,'b-o');
title('QPSK SNR vs. BER/SER (AWGN)');
xlabel('SNR(dB)');
ylabel('BER/SER');
grid on;
hold on;
%
% semilogy(SNR,SER,'r-*');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%