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

📄 biterror.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 (480) 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.
%
% ******************************************************************
% BITERROR
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 7-28-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Introduce random errors into the bitstream
%
% DESIGN NOTES
%
% Bit errors are introduced into the bit stream at a rate
% "ber".  Individual bits may be reversed while protecting others by
% setting bits of the mask array which is initialized at the beginning of
% execution.
%
% To protect a bit set mask(bit) = 1.  If this is
% left at 0, the bit is subjected to reversal at the rate specified
% by "ber".  (The protection scheme above is NOT a function of the
% Hamming error control coding.)
%
% VARIABLES
%
% INPUTS
%   ber         -     Bit error rate
%   mask        -     Error mask
%   stream      -     Uncorrupted bit stream
%   streambits  -     Length of bit stream
%   error       -     Number of bits corrupted so far
%   total       -     Total number of bits processed
%
% OUTPUTS
%   stream      -     Corrupted bit stream
%   error       -     Number of bits corrupted
%   total       -     Total number of bits through coder
%
% INTERNALS
%   rate        -     Scaled error rate
%   xx          -     Error decision vector (R.V., uniform dist)
%   berEnable   -     Error mask vector, inverted for logical combination
%   berInstance -     Unconditioned (unmasked) bit error vector
%   bitErrors   -     Masked bit errors
%
% ******************************************************************

function [ stream, error, total ] = biterror( ber, mask, stream, streambits, error, total )

% SCALE ERROR RATE
rate = ber / 100.0;

% GENERATE BIT ERRORS AT SPECIFIED BER (VECTORIZED)
xx = ( random(streambits) + 32768 ) / 65535;
berEnable = ( mask == 0 );
berInstance = ( xx < rate );

% GIVEN BER, TEST FOR ERRORS AT EACH BIT IN THE STREAM
% COMBINATION OF 0 MASK BIT AND XX < RATE GENERATES AN ERROR
bitErrors = berEnable & berInstance;

% APPLY ERROR VECTOR TO BIT STREAM
stream = xor( bitErrors, stream );

% UPDATE ERROR STATISTICS
total = total + sum( berEnable );
error = error + sum( bitErrors );

% TEST FOR VALID BIT STREAM (ONLY 1 AND 0 BITS)
if any( ( stream ~= 0 ) & ( stream ~= 1 ) )
    fprintf( 'biterror: bit stream not ones and zeros\n' );
end

⌨️ 快捷键说明

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