📄 bin2int.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 (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.
%
% ******************************************************************
% BIN2INT
%
% DEVELOPED TO SUPPORT BITWISE OPERATIONS WHEN PORTING C TO MATLAB
% 3-30-94
%
% REVISED TO SUPPORT n-BIT INTEGERS
% 6-17-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Obtain MATLAB scalar variable (integer) from a n-bit,
% 2's Compliment binary representation, as provided by int2bin().
% Input is an n-bit bit vector, output is a scalar integer.
%
% DESIGN NOTES
%
% Compute weighted sum of powers of two. Incorporate n-bit offset
% for negative values, assuming 2's Compliment input format.
%
% VARIABLES
%
% INPUTS
% v - n-bit, 2's Compliment bit vector, MSB first
%
% OUTPUTS
% i - Scalar integer output
%
% INTERNALS
% n - Vector length (bits)
% offset - Correction factor for negative input words
%
% ******************************************************************
function i = bin2int( v )
% DETERMINE VECTOR LENGTH
n = length(v);
% TEST FOR NEGATIVE INPUT VECTOR
if v(1) == 1
offset = 2^n;
else
offset = 0;
end
% COMPUTE WEIGHTED SUM, ADJUST FOR SIGN
i = sum( v .* (2 .^ (n-1:-1:0)) ) - offset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -