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

📄 random.m

📁 fs1016w编码标准matlab源码
💻 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.
%
% ******************************************************************
% RANDOM
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 7-28-94
%
% ******************************************************************
%
% DESCRIPTION
%
% Generate a vector of random 16-bit integers, taken from a uniform
% distribution between -32768 and 32767.
%
% DESIGN NOTES
%
% See:  Knuth, The Art of Programming, Volume 2, page 27.
%
% VARIABLES
%
% INPUTS
%   nrand        -  Desired output vector length
%
% OUTPUTS
%   the_random   -  An nrand element vector of random 16-bit integers,
%                   sample values of a random variable uniformly
%                   distributed between -32768 and 32767.
%
% INTERNALS
%   i            -  Vector building loop index
%
% GLOBALS
%   y            -  Internal accumulator
%   j            -  Internal index
%   k            -  Internal index
%
% CONSTANTS
%   MAXTAP       -  Internal limit
%
% ******************************************************************

function [ the_random ] = random( nrand )

% DECLARE GLOBAL VARIABLES
global y j k;

% DECLARE GLOBAL CONSTANTS
global MAXTAP;

% INITIALIZE LOCALS
the_random = zeros( nrand, 1 );

% APPLY KNUTH RANDOM NUMBER GENERATOR NRAND TIMES TO BUILD RETURN VECTOR
for i = 1:nrand
    y(k) = y(k) + y(j);

    % SIMULATE 16-BIT TWO'S COMPLEMENT ADDITION
    if y(k) > 32767
        y(k) = y(k) - 65536;
    end
    if y(k) < -32768
        y(k) = y(k) + 65536;
    end

    % RETURN THE RESULT
    the_random(i) = y(k);

    % UPDATE ARRAY INDICIES
    k = k - 1;
    if k < 1
        k = MAXTAP;
    end
    j = j - 1;
    if j < 1
        j = MAXTAP;
    end
end




⌨️ 快捷键说明

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