📄 bit_to_symbol_prob.m
字号:
function [ Output ] = bit_to_symbol_prob( Input )
%
% TX = 2;
% M = 16;% 16QAM
[m,n] = size(Input);
for i = 1:m
for j = 1:n
Input(i,j) = exp(Input(i,j));
end
end
out = zeros(((length(Input)-1)/4),16);
if Input(length(Input))==1
for i = 1:((length(Input)-1)/8)
out((2*(i-1)+1):(2*(i-1)+2),:) = [0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625;
0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625 0.0625];
end
else
for i = 1:((length(Input)-1)/8)
prob = [Input(8*(i-1)+1)/(1+Input(8*(i-1)+1)),1/(1+Input(8*(i-1)+1)),Input(8*(i-1)+2)/(1+Input(8*(i-1)+2)),1/(1+Input(8*(i-1)+2)),Input(8*(i-1)+3)/(1+Input(8*(i-1)+3)),1/(1+Input(8*(i-1)+3)),Input(8*(i-1)+4)/(1+Input(8*(i-1)+4)),1/(1+Input(8*(i-1)+4)); % 天线1上第1bit为1的概率,第1bit为0的概率,第2bit为1的概率,第2bit为0的概率...;
Input(8*(i-1)+5)/(1+Input(8*(i-1)+5)),1/(1+Input(8*(i-1)+5)),Input(8*(i-1)+6)/(1+Input(8*(i-1)+6)),1/(1+Input(8*(i-1)+6)),Input(8*(i-1)+7)/(1+Input(8*(i-1)+7)),1/(1+Input(8*(i-1)+7)),Input(8*(i-1)+8)/(1+Input(8*(i-1)+8)),1/(1+Input(8*(i-1)+8))]; % 天线2上第1bit为1的概率,第1bit为0的概率,第2bit为1的概率,第2bit为0的概率...。
out((2*(i-1)+1):(2*(i-1)+2),:) = [prob(:,2).*prob(:,4).*prob(:,6).*prob(:,8),prob(:,2).*prob(:,4).*prob(:,6).*prob(:,7),prob(:,2).*prob(:,4).*prob(:,5).*prob(:,8),prob(:,2).*prob(:,4).*prob(:,5).*prob(:,7),prob(:,2).*prob(:,3).*prob(:,6).*prob(:,8),prob(:,2).*prob(:,3).*prob(:,6).*prob(:,7),prob(:,2).*prob(:,3).*prob(:,5).*prob(:,8),prob(:,2).*prob(:,3).*prob(:,5).*prob(:,7),...% 符号0000,0001,0010,0011,0100,0101,0110,0111的概率
prob(:,1).*prob(:,4).*prob(:,6).*prob(:,8),prob(:,1).*prob(:,4).*prob(:,6).*prob(:,7),prob(:,1).*prob(:,4).*prob(:,5).*prob(:,8),prob(:,1).*prob(:,4).*prob(:,5).*prob(:,7),prob(:,1).*prob(:,3).*prob(:,6).*prob(:,8),prob(:,1).*prob(:,3).*prob(:,6).*prob(:,7),prob(:,1).*prob(:,3).*prob(:,5).*prob(:,8),prob(:,1).*prob(:,3).*prob(:,5).*prob(:,7)]; % 符号1000,1001,1010,1011,1100,1101,1110,1111的概率
end
end
[m,n] = size(out);
for i = 1:m
for j = 1:n
if isinf(out(i,j)) == 1 % 输出限幅
out(i,j) = 1;
elseif isnan(out(i,j)) == 1
out(i,j) = 0;
elseif out(i,j) > 1
out(i,j) = 1;
elseif out(i,j) < 0
out(i,j) = 0;
end
end
end
Output = out;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -