📄 sq32qam_gray_demap.m
字号:
function out=sq32QAM_Gray_demap(input)
K=length(input);
d=1/sqrt(24); %%% The minimum distance between constellations is 2*d
x=d*[5,3,1,-1,-3,-5]; %%% coordinate matrix
y=d*[5,3,1,-1,-3,-5];
for i=1:K
temp(i,:)=[real(input(i)),imag(input(i))]; %%% 复数矩阵变成实数矩阵,便于处理
end
max=d*[1,5 %%% coordinate matrixbase code, 8-QAM
1,3
1,1
3,1
5,1
5,3
5,5
3,5];
code=[0 0 0 %%% base code matrix, match with max
0 0 1
0 1 1
1 1 1
1 0 1
1 0 0
1 1 0
0 1 0];
for i=1:K
%%%--------Minimun Euclidean distance demodulation--------------------
if temp(i,1)>=0 & temp(i,2)>=0 %%% first field
max1=max; %%% coordinate matrix of first field
for k=1:8
dis(k)=(temp(i,1)-max1(k,1))^2+(temp(i,2)-max1(k,2))^2;
end
[di,num]=min(dis);
tb=code(num,:);
t_out(i,:)=[0 0 tb];
end
if temp(i,1)<0 & temp(i,2)>=0 %%% second field
max2=[-max(:,1),max(:,2)]; %%% coordinate matrix of second field
for k=1:8
dis(k)=(temp(i,1)-max2(k,1))^2+(temp(i,2)-max2(k,2))^2;
end
[di,num]=min(dis);
tb=code(num,:);
t_out(i,:)=[0 1 tb];
end
if temp(i,1)<0 & temp(i,2)<0 %%% third field
max3=(-1)*max; %%% coordinate matrix of third field
for k=1:8
dis(k)=(temp(i,1)-max3(k,1))^2+(temp(i,2)-max3(k,2))^2;
end
[di,num]=min(dis);
tb=code(num,:);
t_out(i,:)=[1 1 tb];
end
if temp(i,1)>0 & temp(i,2)<=0 %%% forth field
max4=[max(:,1),-max(:,2)]; %%% coordinate matrix of forth field
for k=1:8
dis(k)=(temp(i,1)-max4(k,1))^2+(temp(i,2)-max4(k,2))^2;
end
[di,num]=min(dis);
tb=code(num,:);
t_out(i,:)=[1 0 tb];
end
end
for i=1:K
for m=1:5
out(5*(i-1)+m)=t_out(i,m); %%% P/S transform, the out is a serial binary sequence
end
end
clear K x y max code temp t_out tb
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -