📄 mappingrx.m
字号:
function data_mapping = mappingRX( data_interleaving, n_mod_type)
% Now depending on the modulation, a constellation is defined.
% These constellations are defined in the standard.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
switch n_mod_type
case 1 % for BPSK
type_map = 'MPSK';
M = 2;
M1 = 0;
M2 = 0;
c = 1;
case 2 % for QPSK(or 4-QAM)
type_map = 'QAM';
c = 1/sqrt(2);
case 4 % for 16-QAM
type_map = 'QAM';
c = 1/sqrt(10);
case 6 % for 64-QAM
type_map = 'QAM';
c = 1/sqrt(42);
end
if n_mod_type~=1
M = 0;
M1 = sqrt(2^n_mod_type);
M2 = sqrt(2^n_mod_type);
end
type_mapping=type_map;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Block of initialization
%
if strcmp(type_mapping,'QAM')
k1 = ceil(log2(M1));
k2 = ceil(log2(M2));
M1 = 2^k1;
M2 = 2^k2;
M = M1*M2;
% Everything is initialized
% Aicd will be the values different from the coefficients in phase and
% Aisd the values different from the coefficients in quadrature
Aicd = zeros(1,k1);
Aisd = zeros(1,k2);
table1 = zeros(M1,2);
table2 = zeros(M2,2);
alphabet = zeros(M,3);
% In 'table1' and 'table2', every row contains the decimal value of
% the bits [b1 b2... Bk1] and the indices of the table Aicd and Aisd that encode them
d1 = 0:1:M1-1;
d1 = d1';
d2 = 0:1:M2-1;
d2 = d2';
ind1 = bi2de(fliplr(gray2bin(fliplr(de2bi(d1)),'QAM',4)));
table1 = [d1,ind1+1];
ind2 = bi2de(fliplr(gray2bin(fliplr(de2bi(d2)),'QAM',4)));
table2 = [d2,ind2+1];
else
k = ceil(log2(M));
M = 2^k;
% We initialize
Aicd = zeros(1,k); % The values different from the coefficients in phase
Aisd = zeros(1,k); % The values different from the coefficients in quadrature
table = zeros(M,2); % A table with indices
alphabet = zeros(M,3); % Alphabet
% In this case, every row of the table 'table' contains the decimal
% value of the bits [b1 b2 ... bk] and the index of the table Aicd and Aisd that encodes it
d = 0:1:M-1;
d = d';
ind=bi2de(fliplr(gray2bin(fliplr(de2bi(d)),'QAM',4)));
table = [d,ind+1];
end
% Block of computation
%
if strcmp(type_mapping,'PAM')
Aicd = -(M-1):2:M-1;
Aisd = [];
% We create alphabet
for i=1:M
index = find_index(i-1,table);
alphabet(i,:) = [i-1,Aicd(index),0];
end
elseif strcmp(type_mapping,'MPSK')
angle = 0:2*pi/M:2*pi*(M-1)/M;
Aicd = cos(angle);
Aisd = sin(angle);
% We create alphabet
for i=1:M
index = find_index(i-1,table);
alphabet(i,:) = [i-1,Aicd(index),Aisd(index)];
end
elseif strcmp(type_mapping,'QAM')
Aicd = -(M1-1):2:M1-1;
Aisd = (M2-1):-2:-(M2-1);
% We create alphabet
for i=1:M1
for j=1:M2
index1 = find_index(i-1,table1);
index2 = find_index(j-1,table2);
l = i+M1*(j-1);
alphabet(l,:) = [l-1,Aicd(index1),Aisd(index2)];
end
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if n_mod_type~=1
constellation_gray = alphabet(:,3) + j*alphabet(:,2);
else
constellation_gray = [0 1]';
end
l = length(data_interleaving);
% So that all the values are coherent, I must begin to divide the
% initial vector by the factor 'c' defined in the norm.
data_normalized = data_interleaving ./ c;
% Now the inverse of the mapping must be realized.
for i=1:l
v_data_mapping = data_normalized (i);
% I decode them and it transforms them of dn=an j*bn to binary
% numbers, according to my Gray constellation.
v_decode = genqamdemod(v_data_mapping,constellation_gray);
% I place them in the matrix where I am going to have all the symbols by columns
data_decimal(:,i) = v_decode;
data_mapping = de2bi(data_decimal,n_mod_type,'left-msb')';
data_mapping = data_mapping(:)';
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -