|
clear all;
% bit_length = 1000000/4;
bit_length = 100/4;
repeat_times = 5;
SNR_Max = 16;
SNR_resolution = 2;
SNR_indB = 0:SNR_resolution:SNR_Max;
%星座映射圖,第一列是星座圖中的點,后面四列是該點對應(yīng)的四位碼
mapping = [3+3i,0,0,0,0;3+i,0,0,0,1;
3-i,0,1,0,1;3-3i,0,1,0,0;
1+3i,0,0,1,0;1+i,0,0,1,1;
1-i,0,1,1,1;1-3i,0,1,1,0;
-1+3i,1,0,1,0;-1+i,1,0,1,1;
-1-i,1,1,1,1;-1-3i,1,1,1,0;
-3+3i,1,0,0,0;-3+i,1,0,0,1;
-3-i,1,1,0,1;-3-3i,1,1,0,0];
error_symbol_ratio = [];
t0 = clock;
for k = 1:length(SNR_indB)
error_number = 0;
pack; %通過對工作空間內(nèi)的信息進(jìn)行壓縮的方法來釋放內(nèi)存空間
for s = 1:repeat_times
input_code = []; %輸入碼元
input_p = []; %同向分量
input_o = []; %正交分量
Transmit_16QAM = zeros(1,bit_length); %發(fā)送的調(diào)制信號
Received_16QAM = []; %接收到的16QAM信號
Decoded_16QAM_word = zeros(1,bit_length*4); %解調(diào)出的碼元
%------------------------generate random code-----------------------%
input_code = floor(rand(1,bit_length*4)+0.5);
%------------------------------encode-------------------------------%
input_p = input_code(1:2:length(input_code)); %同向分量,取的是輸入比特流的奇數(shù)位
input_o = input_code(2:2:length(input_code)); %正交分量,取的是輸入比特流的偶數(shù)位
for j = 1:length(input_code)/4;
index1 = 4*input_p(2*j-1)*input_p(2*j)-6*input_p(2*j-1)-2*input_p(2*j)+3; %同向分量的4PAM編碼
index2 = 4*input_o(2*j-1)*input_o(2*j)-6*input_o(2*j-1)-2*input_o(2*j)+3; %正交分量的4PAM編碼
Transmit_16QAM(j) = index1+i*index2; %將每4位碼元映射到星座圖中對應(yīng)的點
end
%----------------------------adding noise-----------------------------%
Received_16QAM = AWGN(Transmit_16QAM,SNR_indB(k)+10*log10(4),10);
%------------------------------decoding-------------------------------%
for j = 1:length(Received_16QAM)
for m = 1:16;
metrics(m) = abs(Received_16QAM(j)-mapping(m));
end
[min_metrc index] = min(metrics);
Decoded_16QAM_word(4*j-3:4*j) = mapping(index,2:5); %選擇歐式距離最小的星座點作為解調(diào)輸出
if(Transmit_16QAM(j) ~= mapping(index))
error_number = error_number + 1; %計算誤碼個數(shù)
end
end
end
%-----------------------------error bits------------------------------%
error_symbol_ratio(k) = error_number/(bit_length*repeat_times); %計算誤碼率
k
end
etime(clock,t0)
%----------------------------draw curve-------------------------------%
semilogy(SNR_indB,error_symbol_ratio,'r-*');
grid;
xlabel('SNR per symbol/dB');
ylabel('Symbol error');
hold on;
%--------------------------draw theorotic curve-----------------------%
SNR_indB2 = 0:0.1:SNR_Max;
for i = 1:length(SNR_indB2)
SNR = 10^(SNR_indB2(i)/10); %16QAM性能的理論曲線
theo_err_prb(i) = 4*Qfunct(sqrt(3*4*SNR/15));
end
semilogy(SNR_indB2,theo_err_prb);
% --------------
semilogy(SNR_indB,SNR_indB,'b-o');
legend('16QAM','BPSK') |
|