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

📄 hammgen.m

📁 数字通信第四版原书的例程
💻 M
字号:
function [h, g, n, k] = hammgen(m, p)
%HAMMGEN Produces both Hamming code generator matrix and parity-check matrix.
%       H = HAMMGEN(M) produces the parity-check matrix H for a given positive
%       integer M, M >= 3. The code length of a Hamming code is N=2^M-1. The
%       message length is K = 2^M - M - 1. The parity-check matrix is an 
%       M-by-N matrix.
%
%       H = HAMMGEN(M, P) produces the parity-check matrix using a given
%       GF(2) primitive polynomial P.
%
%       [H, G] = HAMMGEN(...) produces the generator matrix G as well as the 
%       generator matrix G. The parity-check matrix is an K-by-N matrix.
%
%       [H, G, N, K] = HAMMGEN(...) outputs the dimension information N and K.
%
%       Note: The input number M should be a larger than integer 3. Hamming
%       code is a single error-correction code defined in GF(2).
%
%       See also: ENCODE, DECODE, GEN2PAR.

%       Wes Wang 10/7/95
%       Copyright (c) 1995-96 by The MathWorks, Inc.
%       $Revision: 1.1 $  $Date: 1996/04/01 18:00:36 $

% routing test

m = floor(m);
%if m < 3
%    error('Input for function HAMMGEN is too small');
%end

% assign print threshold
prt = 9;

% dimension
n = 2^m - 1;
k = n - m;

% test if it needs to assign primitive polynomial
test = 0;
if nargin < 2
    test = 1;
elseif isempty(p)
    test = 1;
end;

if m >= prt
    fprintf('Executing hammgen..');
end;

% assign the primitive polynomial, assign the shortest primitive polynomial
if test
    p = gfprimdf(m);
else
    p = gfrepcov(p);
end;

% In case it is assigned primitive polynomial, primitive check.
if ~test
    if gfprimck(p) ~= 1
        error('The input polynomial must be primitive');
    end;
end;

% generate the parity-check matrix.
h = gftuple([0:n-1]', p, 2)';

% when needed, produce generator matrix
if nargout > 1
    g = gen2par(h);
end;

if m >= prt
    disp('...Done.')
end;
%--end of hammgen--

⌨️ 快捷键说明

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