📄 encodham.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.
%
% ******************************************************************
% ENCODHAM
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 7-22-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Calculate parity bits necessary to complete the code word for
% protecting selected bits out of the bitstream against bit errors.
%
% 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.
%
% ENCODHAM.M performs the hamming encode function. It calculates the
% necessary parity bits, depending on which code is requested, and
% adds the overall parity bit to the end of the code word generated.
%
% REFERENCES
%
% 1. Lin and Costello: Error Control Coding
% 2. Berlekamp: Algebraic Coding Theory
%
% VARIABLES
%
% INPUTS
% codelength1 - Number of data bits
% codelength2 - Number of information bits
% hmatrix - Vector to encode and decode by
% codeword - Vector containing information bits to be encoded
%
% OUTPUTS
% codeword - Vector containing output parity bits plus infobits
% paritybit - Overall parity bit (second parity bit)
%
% INTERNAL
% i - Counter index
% temp - Holder for parity bits
%
% ******************************************************************
function [ paritybit, codeword ] = encodham( codelength1, codelength2, ...
hmatrix, codeword )
% INITIALIZE LOCALS
temp = 0;
% GENERATE PARITY BITS FOR THE HAMMING CODE WORD
for i = 1:codelength2
if codeword(i) ~= 0
% temp = bitxor( temp, hmatrix(i), 16 ); changed by Johnson Peng
temp = bitxor( temp, hmatrix(i));
temp = bitxor( temp, 16 );
end
end
% PACK PARITY BITS ONTO END OF CODEWORD
codeword( codelength1:-1:codelength2+1 ) = int2bin( temp, 4 )';
% GENERATE OVERALL PARITY BIT
paritybit = 0;
if rem( sum( codeword ), 2 ) ~= 0
paritybit = 1;
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -