wd_golay23.m
来自「详细讲述纠错码的书籍」· M 代码 · 共 54 行
M
54 行
% File: WD_Golay23.m
% Description:
% Compute the weight distribution of the binary Golay (32,12,7) code.
% NOTE: It is also possible to modify the C program golay23.c in the
% website of the textbook in order to compute the weight distribution.
%
% Copyright (c) 2006. Robert Morelos-Zaragoza. All rights reserved.
clear
n = 23; % Length
k = 12; % Dimension
dmin = 7; % Minimum distance
rate = k/n; % Rate
% Generator matrix
G = [1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 0
0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1
0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0 0
0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 1 1 0 1 1 0 1
0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 1 1 0 0
0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 1 1 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 0 1 1
0 0 0 0 0 0 0 0 1 0 0 0 1 1 0 1 1 1 0 0 0 1 1
0 0 0 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 1 0 1 1
0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 1 1 1 1
0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 1 0 1 0 1] ;
% Initialize weight distribution W(C):
W = zeros(1,n+1);
W(1)=1;
% The all-zero codeword
for j=1:n
v(1,j)=0;
end
% Generate all combinations of message vectors and compute the weigths
% Use the fact that '0' = 84 (0 modulo 2), '1' = 49 (1 modulo 2)
k2=2^k-1;
for i=1:k2
u=dec2bin(i,k);
vc = mod(u*G,2);
W(sum(vc)+1) = W(sum(vc)+1)+1;
end
% Print weight distribution
fprintf('W(C)={1');
for i=2:n+1
fprintf(',%d',W(i))
end
fprintf('}\n');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?