📄 golaydecode.m
字号:
function [out]=golaydecode(demodata1)
B=[1 1 0 1 1 1 0 0 0 1 0 1;
1 0 1 1 1 0 0 0 1 0 1 1;
0 1 1 1 0 0 0 1 0 1 1 1;
1 1 1 0 0 0 1 0 1 1 0 1;
1 1 0 0 0 1 0 1 1 0 1 1;
1 0 0 0 1 0 1 1 0 1 1 1;
0 0 0 1 0 1 1 0 1 1 1 1;
0 0 1 0 1 1 0 1 1 1 0 1;
0 1 0 1 1 0 1 1 1 0 0 1;
1 0 1 1 0 1 1 1 0 0 0 1;
0 1 1 0 1 1 1 0 0 0 1 1;
1 1 1 1 1 1 1 1 1 1 1 0];
H=[eye(12);B];
s=demodata1*H-floor((demodata1*H)./2).*2; %矩阵乘中,是模2加。
u=zeros(1,24);
weight1=nnz(s); %s的汉明重量
if weight1<=3, %Case 1
u=[s,zeros(1,12)];
else
for ii=1:12,
weight2(ii)=nnz(B(ii,:)+s); %weight2(ii)记录 B(ii,:)+s 的重量
end
wnum=find(weight2<=2); % 重量<=2的下标值,wnum对应B的行标
if ~isempty(wnum), % Case 2
ematrix=[zeros(1,wnum(1)-1),1,zeros(1,12-wnum(1))];%取满足条件的第一个B的行数
u=[s+B(wnum(1),:),ematrix];
else
s2=s*B-floor((s*B)./2).*2;
weight3=nnz(s2);
if weight3<=3, % Case 3
u=[zeros(1,12),s2];
else
for ii1=1:12,
weight4(ii1)=nnz(B(ii1,:)+s2);
end
wnum2=find(weight4<=2);
if ~isempty(wnum2), % Case 4
ematrix2=[zeros(1,wnum2(1)-1),1,zeros(1,12-wnum2(1))];
u=[ematrix2,s2+B(wnum2(1),:)];
end
end
end
end
out=demodata1+u-floor((demodata1+u)./2).*2;% 模2加
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -