📄 float_1664qam24.m
字号:
% 表示t2*r4系统,码率= 1;
% 16qam 64qam
clear
clc
snr_min=0;
snr_max=35;
stepsize = 2.5;
%-------------全局参量--------------------------------%
Mod_type = 4; %qam调制有三种情况(2=4qam,4=16qam,6=64qam)
Ofdm_bits = 100; %一个ofdm符号长度
Tx_num = 2; %发送天线个数,这里仅仅是赋一个默认的初始值
Rx_num = 2; %接收天线个数
Time_length = 2; %进行正交编码的时隙长度,这里仅仅是赋一个默认的初始值(2 or 4)
Source_length = Tx_num*Ofdm_bits*Mod_type; %信源输出码子个数(映射前)
pqam_length = Ofdm_bits*Mod_type; %每根天线所需的码子个数(映射前)
sig_code = zeros(Tx_num,pqam_length);
sig_code = randint(Tx_num,pqam_length);
table16 = [1+j, 3+ j, 1+3j, 3+3j,...
1-j, 1-3j, 3- j, 3-3j,...
-1+j,-1+3j,-3+ j,-3+3j,...
-1-j,-3- j,-1-3j,-3-3j];
table64 = [1+j, 3+ j, 1+3j, 3+3j, 7+1j, 5+ j, 7+3j, 5+3j, 1+7j, 3+7j, 1+5j, 3+5j, 7+7j, 5+7j, 7+5j, 5+5j,...
1-j, 1-3j, 3- j, 3-3j, 1-7j, 1-5j, 3-7j, 3-5j, 7- j, 7-3j, 5- j, 5-3j, 7-7j, 7-5j, 5-7j, 5-5j,...
-1+j,-1+3j,-3+ j,-3+3j,-1+7j,-1+5j,-3+7j,-3+5j,-7+ j,-7+3j,-5+ j,-5+3j,-7+7j,-7+5j,-5+7j,-5+5j,...
-1-j,-3- j,-1-3j,-3-3j,-7- j,-5- j,-7-3j,-5-3j,-1-7j,-3-7j,-1-5j,-3-5j,-7-7j,-5-7j,-7-5j,-5-5j];
table16 = table16/sqrt(10);
table64 = table64/sqrt(42);
switch Mod_type
case 4
for i=1:Tx_num
for n=1:Ofdm_bits
table_index = sig_code(i,(n-1)*Mod_type+1)*8+sig_code(i,(n-1)*Mod_type+2)*4+...
sig_code(i,(n-1)*Mod_type+3)*2+sig_code(i,(n-1)*Mod_type+4);
qam_code(i,n) = table16(table_index+1);
end
end
case 6
for i=1:Tx_num
for n=1:Ofdm_bits
table_index = sig_code(i,(n-1)*Mod_type+1)*32+sig_code(i,(n-1)*Mod_type+2)*16+...
sig_code(i,(n-1)*Mod_type+3)*8+sig_code(i,(n-1)*Mod_type+4)*4+...
sig_code(i,(n-1)*Mod_type+5)*2+sig_code(i,(n-1)*Mod_type+6);
qam_code(i,n) = table64(table_index+1);
end
end
end
stbc_code = zeros(Time_length,Tx_num,Ofdm_bits); %stbc 编码矩阵
for m=1:Tx_num
stbc_code(1,m,:) = qam_code(m,:);
end
stbc_code(2,1,:) = -conj(qam_code(2,:));
stbc_code(2,2,:) = conj(qam_code(1,:));
ch_scale = sqrt(Tx_num);
stbc_code = stbc_code/ch_scale;
%-----------------------迭代开始 信噪比 由小到大------------------------%
iterative_length = 0;
for snr_db_step =snr_min:stepsize:snr_max % 信噪比从snr_min--snr_max
iterative_length = iterative_length+1
%------------(省略CP头和训练序列)上信道,乘性噪声------------------------%
rec_code = zeros(Time_length,Rx_num,Ofdm_bits);
channel_mul_noice = zeros(Tx_num,Rx_num,Ofdm_bits);
ch_mul_noice = sqrt(0.5)*(randn(Tx_num,Rx_num,Ofdm_bits)+j*randn(Tx_num,Rx_num,Ofdm_bits));
for n = 1:Time_length
for m = 1:Ofdm_bits
rec_code(n,:,m) = stbc_code(n,1:Tx_num,m)*ch_mul_noice(1:Tx_num,1:Rx_num,m);
end
end
%---------------------信号功率统计,加高斯白噪声----------------------------%
sig_pante_pow = 0;
for n = 1:Rx_num
Agwn = sqrt(10^(-snr_db_step/10)/2)*(randn(Time_length,1,Ofdm_bits)+j*randn(Time_length,1,Ofdm_bits));
rec_code(:,n,:) = rec_code(:,n,:) + Agwn;
end
rec_code = rec_code*ch_scale;
%%%%%%%%%%%%%%%%%%%%%%%%%% 定点仿真 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%------------------------接收信号并进行stbc译码----------------------------%
rec_code_r = real(rec_code);
rec_code_i = imag(rec_code);
ch_mul_noice_r = real(ch_mul_noice);
ch_mul_noice_i = imag(ch_mul_noice);
decode_out = zeros(Tx_num,Ofdm_bits);
demap_int = zeros(Tx_num,Ofdm_bits);
%rec_code = rec_code*qam_scale;
%[decode_out,demap_int] = stbc_decode(rec_code,channel_mul_noice);
compare_tempt = zeros(Time_length,2);
result_index = zeros(1,Time_length);
if Mod_type == 4
star_index_length = 16;
end
if Mod_type == 6
star_index_length = 64;
end
for n = 1:Ofdm_bits
decode_tempt = zeros(1,2); % Time_length = 2
decode_tempt_r = zeros(1,2);
decode_tempt_i = zeros(1,2);
m = reshape(ch_mul_noice(:,:,n),1,Tx_num*Rx_num); % 8 = Tx_num*Rx_num=2*4
ch_sum = norm(m)^2;
for r = 1:Rx_num
%decode_tempt(1,1) = decode_tempt(1,1) + rec_code(1,r,n)*conj(ch_mul_noice(1,r,n))+ conj(rec_code(2,r,n))*ch_mul_noice(2,r,n);
mult_tempt1 = rec_code_r(1,r,n)*ch_mul_noice_r(1,r,n);
mult_tempt2 = rec_code_i(1,r,n)*ch_mul_noice_i(1,r,n);
mult_tempt3 = rec_code_r(2,r,n)*ch_mul_noice_r(2,r,n);
mult_tempt4 = rec_code_i(2,r,n)*ch_mul_noice_i(2,r,n);
decode_tempt_r(1,1) = decode_tempt_r(1,1)...
+mult_tempt1 + mult_tempt2...
+mult_tempt3 +mult_tempt4;
mult_tempt1 = - rec_code_r(1,r,n)*ch_mul_noice_i(1,r,n);
mult_tempt2 = rec_code_i(1,r,n)*ch_mul_noice_r(1,r,n);
mult_tempt3 = rec_code_r(2,r,n)*ch_mul_noice_i(2,r,n);
mult_tempt4 = - rec_code_i(2,r,n)*ch_mul_noice_r(2,r,n);
decode_tempt_i(1,1) = decode_tempt_i(1,1)...
+mult_tempt1+mult_tempt2 ...
+mult_tempt3 +mult_tempt4;
%decode_tempt(1,2) = decode_tempt(1,2) + rec_code(1,r,n)*conj(ch_mul_noice(2,r,n))- conj(rec_code(2,r,n))*ch_mul_noice(1,r,n);
mult_tempt1 = rec_code_r(1,r,n)*ch_mul_noice_r(2,r,n);
mult_tempt2 = rec_code_i(1,r,n)*ch_mul_noice_i(2,r,n);
mult_tempt3 = - rec_code_r(2,r,n)*ch_mul_noice_r(1,r,n);
mult_tempt4 = - rec_code_i(2,r,n)*ch_mul_noice_i(1,r,n);
decode_tempt_r(1,2) = decode_tempt_r(1,2)...
+mult_tempt1 + mult_tempt2...
+mult_tempt3+mult_tempt4;
mult_tempt1 = -rec_code_r(1,r,n)*ch_mul_noice_i(2,r,n);
mult_tempt2 = rec_code_i(1,r,n)*ch_mul_noice_r(2,r,n);
mult_tempt3 = -rec_code_r(2,r,n)*ch_mul_noice_i(1,r,n);
mult_tempt4 = rec_code_i(2,r,n)*ch_mul_noice_r(1,r,n);
decode_tempt_i(1,2) = decode_tempt_i(1,2)...
+mult_tempt1 + mult_tempt2...
+mult_tempt3+ mult_tempt4;
end
decode_tempt(1,1) = decode_tempt_r(1,1)+j*decode_tempt_i(1,1);
decode_tempt(1,2) = decode_tempt_r(1,2)+j*decode_tempt_i(1,2);
if Mod_type == 4
for star_index = 1:star_index_length
compare_tempt(1,1) = abs(decode_tempt(1,1)-table16(star_index))^2+...
(-1+ch_sum)*abs(table16(star_index))^2;
compare_tempt(2,1) = abs(decode_tempt(1,2)-table16(star_index))^2+...
(-1+ch_sum)*abs(table16(star_index))^2;
if star_index==1
compare_tempt(1,2) = compare_tempt(1,1);
compare_tempt(2,2) = compare_tempt(2,1);
result_index(1) = star_index;
result_index(2) = star_index;
else
if compare_tempt(1,1) < compare_tempt(1,2)
compare_tempt(1,2) = compare_tempt(1,1);
result_index(1) = star_index;
end
if compare_tempt(2,1) < compare_tempt(2,2)
compare_tempt(2,2) = compare_tempt(2,1);
result_index(2) = star_index;
end
end
end % star_index = 1:16
decode_out(1,n) = table16(result_index(1));
decode_out(2,n) = table16(result_index(2));
demap_int(1,n) = result_index(1)-1;
demap_int(2,n) = result_index(2)-1;
end % Mod_type = 4
if Mod_type == 6
for star_index = 1:star_index_length
compare_tempt(1,1) = norm(decode_tempt(1,1)-table64(star_index))^2+...
(-1+ch_sum)*norm(table64(star_index))^2;
compare_tempt(2,1) = norm(decode_tempt(1,2)-table64(star_index))^2+...
(-1+ch_sum)*norm(table64(star_index))^2;
if star_index==1
compare_tempt(1,2) = compare_tempt(1,1);
compare_tempt(2,2) = compare_tempt(2,1);
result_index(1) = star_index;
result_index(2) = star_index;
end
if compare_tempt(1,1) < compare_tempt(1,2)
compare_tempt(1,2) = compare_tempt(1,1);
result_index(1) = star_index;
end
if compare_tempt(2,1) < compare_tempt(2,2)
compare_tempt(2,2) = compare_tempt(2,1);
result_index(2) = star_index;
end
end % star_index = 1:64
decode_out(1,n) = table64(result_index(1));
decode_out(2,n) = table64(result_index(2));
demap_int(1,n) = result_index(1)-1;
demap_int(2,n) = result_index(2)-1;
end % Mod_type = 6
end % n = 1:Ofdm_bits
%------------------------qam 解调-------------------------------------------%
demap_out = zeros(Tx_num,pqam_length);
%demap_out = qam_demap(demap_int);
for t = 1:Tx_num
tempt = dec2bin(demap_int(t,:),Mod_type);
for n = 1:Ofdm_bits
demap_out(t,(n-1)*Mod_type+1:n*Mod_type) = tempt(n,1:Mod_type)-48;
end
end
%------------------------统计误码率-----------------------------------------%
% pqam_length = Ofdm_bits*Mod_type;
error_ratio = 0;
error_num = 0;
sig_all_num = pqam_length*Tx_num;
error_matrix = zeros(Tx_num,pqam_length);
for t = 1:Tx_num
for n = 1:pqam_length
if demap_out(t,n)~=sig_code(t,n)
error_num = error_num+1;
error_matrix(t,n) = 1;
end
end
end
error_ratio = error_num/sig_all_num;
e_record(iterative_length) = error_ratio;
end % snr_db_step =snr_min:snr_max
xanxis = snr_min:stepsize:snr_max;
if Mod_type == 4
semilogy(xanxis,e_record,'bsquare-');
elseif Mod_type == 6
semilogy(xanxis,e_record,'r^-');
end
grid on;
hold on;
title('T2R4 系统');
legend('16qam','64qam');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -