⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 golaydecode.m

📁 比较hamming Golay 编码在BPSK条件下的优劣
💻 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];   
mat_s=demodata1*H-floor((demodata1*H)./2).*2; %矩阵乘中,是模2加。 
u=zeros(1,24); 
for num=1:2
    s=mat_s(num,:);
    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 
    out2(num,:)=demodata1(num,:)+u-floor((demodata1(num,:)+u)./2).*2;% 模2加 
end
out=out2(:,1:12);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -