|
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;
%星座映射图,第一列是星座图中的点,后面四列是该点对应的四位码
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; %通过对工作空间内的信息进行压缩的方法来释放内存空间
for s = 1:repeat_times
input_code = []; %输入码元
input_p = []; %同向分量
input_o = []; %正交分量
Transmit_16QAM = zeros(1,bit_length); %发送的调制信号
Received_16QAM = []; %接收到的16QAM信号
Decoded_16QAM_word = zeros(1,bit_length*4); %解调出的码元
%------------------------generate random code-----------------------%
input_code = floor(rand(1,bit_length*4)+0.5);
%------------------------------encode-------------------------------%
input_p = input_code(1:2:length(input_code)); %同向分量,取的是输入比特流的奇数位
input_o = input_code(2:2:length(input_code)); %正交分量,取的是输入比特流的偶数位
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位码元映射到星座图中对应的点
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); %选择欧式距离最小的星座点作为解调输出
if(Transmit_16QAM(j) ~= mapping(index))
error_number = error_number + 1; %计算误码个数
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') |
|