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

📄 decodham.m

📁 FS1016源代码
💻 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.
%
% ******************************************************************
% DECODHAM
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 7-29-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Decode hamming encoded codeword at receiver.  Correct single errors
% or detect multiple errors (2).
%
% 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.
%
% DECODHAM.M removes parity bits from the received codeword,
% checks for errors, and sends a smoothing flag to the calling routine
% if there is more than one error.
%
% REFERENCES
%
%   1. Lin and Costello:  Error Control Coding
%   2. Berlekamp:         Algebraic Coding Theory
%
% VARIABLES
%
% INPUTS
%   codelength1   -   Number of data bits
%   hmatrix       -   Vector to encode and decode by
%   syndrometable -   Error masks used to correct single errors
%   paritybit     -   Overall parity bit
%   codeword      -   Vector containing information bits to be decoded
%
% OUTPUTS
%   codeword      -   Vector containing error corrected output infobits
%   twoerror      -   Flag for detection of 2 errors
%   synflag       -   Parity test value, syndrome table offset
%
% INTERNAL
%   errorflag     -   Flag indicating overall parity error detected
%   i             -   Loop counter
%   j             -   Erroneous bit index
%
% CONSTANTS
%   TRUE          -   Boolean constant == 1
%   FALSE         -   Boolean constant == 0
%
% ******************************************************************

function [ codeword, twoerror, synflag ] = decodham( codelength1, hmatrix, ...
                                                     syndrometable, ...
                                                     paritybit, codeword )

% DECLARE GLOBAL CONSTANTS
global TRUE FALSE

% INIT LOCALS
parityflag = FALSE;
twoerror = FALSE;
errorflag = 0;

% THIS PART OF THE ROUTINE CHECKS THE OVERALL PARITY OF THE CODE WORD AND
% COMPARES IT WITH THE OVERALL PARITYBIT SENT.  IF THEY ARE NOT THE SAME
% THEN THERE IS AT LEAST ONE ERROR.  IF, LATER ON IN THE ROUTINE,
% THE SYNDROME CHECK INDICATES THAT THERE IS AN ERROR AND THE PARITY IS
% CORRECT IN THIS PART OF THE ROUTINE, THAT INDICATES THERE ARE TWO
% ERRORS.  ONE OF THE WEAKNESSES OF THIS METHOD IS THAT THERE IS NO WAY
% OF KNOWING IF WE HAVE 3,5,7,... ERRORS.  WE ALWAYS SMOOTH IF THERE ARE
% 2,4,6,... ERRORS.

% TEST OVERALL PARITY
if parityflag == TRUE
    synflag = rem( sum( codeword(1:codelength1) ), 2 );
    errorflag = errorflag + ( paritybit ~= synflag );
end

% GENERATE THE SYNDROME, WHICH WILL EQUAL ZERO IF THERE ARE NO ERRORS.
% SYNFLAG ACCUMULATES THE SYNDROME AND IS USED AS THE OFFSET IN THE
% SYNDROME TABLE, WHICH TELLS THE ROUTINE WHICH BIT IS IN ERROR.
synflag = 0;
for i = 1:codelength1
    if codeword(i) ~= 0
    %    synflag = bitxor( synflag, hmatrix(i), 16 );   changed by Johnson Peng
    synflag = bitxor( synflag, hmatrix(i));
    synflag = bitxor( synflag,  16 );
    end
end

% CHECK TO SEE IF THE PARITYFLAG IS SET AND IF IT IS THEN CHECK TO SEE
% IF THE PARITY BIT WAS IN ERROR. IF THE PARITYFLAG WAS SET AND THERE WAS
% AN ERROR IN THE SYNDROME, THE ERRORFLAG SHOULD EQUAL 1. IF IT DOESN'T,
% THEN THERE ARE MORE ERRORS THAN CAN BE CORRECTED AND THE INFOBITS ARE
% PASSED ON UNCHANGED.
        %if synflag ~= 0
        %   if ( errorflag ~= 1 ) & ( parityflag == TRUE )
        %       twoerror = TRUE;
        %       return                              **********Blinded by Johnson Peng*************
        %   end
        %   j = syndrometable( synflag );
        %   codeword( j ) = ~codeword( j );
        %end

% IF THE SYNDROME IS EQUAL TO ZERO AND THE ERRORFLAG IS SET (NOT
% LIKELY, BUT MUST BE CHECKED) THEN MORE THAN ONE ERROR HAS OCCURED,
% BUT IT CANNOT BE CORRECTED, SO PASS ON THE INFOBITS THE SAME AS IF
% THERE HAD BEEN NO ERRORS.






⌨️ 快捷键说明

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