📄 mtrxgen.m
字号:
% MATLAB SIMULATION OF NSA FS-1016 CELP v3.2
% COPYRIGHT (C) 1995-99 ANDREAS SPANIAS AND TED PAINTER
%
% This Copyright applies only to this particular MATLAB implementation
% of the FS-1016 CELP coder. The MATLAB software is intended only for educational
% purposes. No other use is intended or authorized. This is not a public
% domain program and distribution to individuals or networks is strictly
% prohibited. Be aware that use of the standard in any form is goverened
% by rules of the US DoD. Therefore patents and royalties may apply to
% authors, companies, or committees associated with this standard, FS-1016. For
% questions regarding the MATLAB implementation please contact Andreas
% Spanias at (602) 965-1837. For questions on rules,
% royalties, or patents associated with the standard, please contact the DoD.
%
% ALL DERIVATIVE WORKS MUST INCLUDE THIS COPYRIGHT NOTICE.
%
% ******************************************************************
% MTRXGEN
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 6-7-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Generate H matrix and syndrome table necessary for Hamming enocde
% and decode.
%
% DESIGN NOTES
%
% Part of a set of subroutines which perform a Generalized Hamming Code.
% Hamming codes are perfect codes and can only detect and
% correct one error. We have added an overall parity checkbit,
% which allows detection of 2 errors. When 2 errors
% are detected, (in decodeham) no correction attempt is
% made. This would most likely result in more errors. Instead, a flag
% is sent to the calling program notifying it of multiple errors so
% that smoothing may be attempted. The Hamming codes presently
% supported by the routines are (63,57), (31,26), (15,11), and
% shortened variations thereof. It could be made even more general
% by making minor modifications to the decimal to binary output vector
% code in the encodeham procedure. This routine at present will
% calculate a maximum of 6 bits.
%
% CELP 3.2a Hamming routines include:
% matrixgen - generates the hmatrix and sydrometable.
% encodeham - generates the codeword and overall paritybit.
% decodeham - recovers infobits, checks for errors, corrects 1
% error, and sends out flag for smoothing.
%
% MATRIXGEN.M initializes all of the tables necessary to perform
% the Hamming code (G Matrix, Syndrome Table).
% Called once before calling encodeham and decodeham.
%
% REFERENCES
% Lin and Costello: Error Control Coding
% Berlekamp: Algebraic Coding Theory
%
% VARIABLES
%
% INPUTS
% codelength1 - Number of data bits
% codelength2 - Number of information bits
%
% OUTPUTS
% hmatrix - Vector to encode and decode by
% syndrometable - Table containing error masks
%
% INTERNAL
% i - Counter for table construction
% temp1 - Counter for table construction
% itemplate - Identity template data
% ptemplate - Parity template data
%
% ******************************************************************
function [ hmatrix, syndrometable ] = mtrxgen( codelength1, codelength2 )
% ALLOCATE RETURN VECTORS
hmatrix = zeros( codelength1, 1 );
syndrometable = zeros( codelength1, 1 );
% DEFINE DATA NECESSARY TO CONSTRUCT THE G MATRIX AND THE SYNDROME TABLE.
% IF A LARGER CODE IS DESIRED, THIS TABLE CAN BE EASILY ADDED TO.
% ALL OTHER ROUTINES, EXCEPT THE SYNDROME TABLE CONSTRUCTION,
% ARE GENERAL ENOUGH TO CALCULATE ANY SIZE HAMMING CODE.
itemplate = [ 1, 2, 4, 8, 16, 32 ]';
ptemplate = [ ...
3, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, ...
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, ...
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, ...
52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63 ...
]';
% CONSTRUCT THE PARITY PORTION OF THE HMATIX
hmatrix( 1:codelength2 ) = ptemplate( 1:codelength2 );
% CONSTRUCT THE IDENTITY PORTION OF THE MATRIX
hmatrix( 1+codelength2:codelength1 ) = itemplate( 1:codelength1-codelength2 );
% CONSTRUCT THE SYNDROME TABLE. THIS ROUTINE EMPLOYS THE BERLEKAMP METHOD.
temp1 = 1;
for i = 1:codelength1
if i == 1
syndrometable(i) = codelength2 + 1;
elseif i == 2
syndrometable(i) = codelength2 + 2;
elseif i == 4
syndrometable(i) = codelength2 + 3;
elseif i == 8
syndrometable(i) = codelength2 + 4;
elseif i == 16
syndrometable(i) = codelength2 + 5;
elseif i == 32
syndrometable(i) = codelength2 + 6;
else
syndrometable(i) = temp1;
temp1 = temp1 + 1;
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -