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

📄 celpsyn.m

📁 FS1016源代码
💻 M
📖 第 1 页 / 共 2 页
字号:
% 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.
%
% ******************************************************************
% CELPSYN
%
% NSA CELP 3.2a SYNTHESIS DRIVER
%
% PORTED TO MATLAB FROM CELP 3.2a C RELEASE
% 8-2-94
%
% ******************************************************************
%
% DESCRIPTION
%
% CELP 3.2a synthesis driver
%
% DESIGN NOTES
%
% This driver has been derived from the main loop of the NSA CELP 3.2a
% simulation.  CELP synthesis accepts a CELP analysis output bitstream
% (144 bits/frame or 4.8 kbps) as input and produces three (3) 16-bit
% PCM speech data files as output (binary):
%
%    1) *.NPF  -  Non-postfiltered synthetic output speech
%    2) *.SPO  -  Postfiltered synthetic output speech
%    3) *.HPF  -  Highpass filtered synthetic output speech
%
% This synthesis driver also includes bit error rate simulation
%
% VARIABLES
%
% INTERNALS
%   SimType       -    Simulation type - analysis/synthesis or synthesis only
%   pstream       -    Permuted version of CELP analysis output bitstream
%   bitperm       -    Bit stream permutation table
%   stream        -    CELP analysis output bitstream
%   line          -    Frame buffer, hex bitstream CELP analysis output,
%                      obtained from hex file 'ofile.cha'
%   pointer       -    CELP analysis output bitstream current bit pointer
%   ber           -    Simulated bit error rate
%   mask          -    Bitstream mask, used to protect specific bits from bit errors
%   errors        -    Cumulative sum over all frames of number of bit errors
%   total         -    Total number of bits processed
%   protect       -    Hamming bit protection enable/disable flag
%   codeword      -    Hamming (15,11) codeword, formed from protected bits
%   bitprotect    -    Bitstream indicies of bits protected by the hamming code
%   twoerror      -    Flag indicating two errors in current received frame
%   hmatrix       -    Hamming matrix, used during hamming codeword decoding
%   syndrometable -    Hamming syndrome table  "        "                 "
%   syndrome      -    Parity error flag, generated by hamming decoder
%   paritybit     -    Extraneous paritybit used for codeword parity overall
%   syndavg       -    Smoothed error rate
%   findex        -    LSP quantization table indicies, unpacked from bitstream
%   sbits         -    Bit allocation, LSP quantization
%   no            -    LPC synthesis filter order
%   newfreq       -    Decoded LSPs, derived from bitstream and quant table
%   lsp           -    Set of linearly interpolated lsps for nn subframes of current frame
%   nn            -    Number of subframes
%   bitpointer    -    Temporary copy of pointer, bitstream pointer
%   taus          -    Pitch lag values (nn) decoded from the bitstream
%   pgs           -    Pitch lag gain values (nn) decoded from the bitstream
%   cbi           -    Stochastic codebook indicies (nn) decoded from bitstream
%   cbg           -    Stochastic codebook gains (nn) decoded from bitstream
%   pbits         -    Bit allocation, adaptive codebook gain and index quantization
%   cbbits        -    Bit allocation, stochastic codebook index
%   cbgbits       -    Bit allocation, stochastic codebook gain
%   bitsum1       -    Bit allocation sum used during parameter decoding
%   bitsum2       -    Bit allocation sum used during parameter decoding
%   pddecode      -    Tau (pitch lag) permutation table
%   pdtabi        -    Tau delay table index
%   subframe      -    Current subframe under analysis (1:nn)
%   l             -    Subframe length, in samples
%   vl, vh        -    Subframe limits within current frame buffer
%   cbindex       -    Stochastic codebook index, current subframe
%   decodedgain   -    Stochastic codebook gain, current subframe
%   vdecoded      -    Synthesis excitation vector; combination of both codebook contributions
%   bb            -    Pitch lag (adaptive codebook) index and gain, current subframe
%   dps           -    Buffer used during adaptive codebook vector formation
%   idb           -    Dimension of buffer used in adaptive codebook vector formation (see PITCHVQ.M)
%   fci           -    LPC synthesis filter coefficients for current subframe
%   dss           -    LPC synthesis filter memory
%   descale       -    Output speech scale factor
%   minv          -    Minimum allowed output speech sample value
%   maxv          -    Maximum allowed output speech sample value
%   npf           -    Non-postfiltered output speech (1 frame)
%   pf            -    Postfiltered output speech (1 frame)
%   hppf          -    Highpass filtered output speech (1 frame)
%   fpo           -    Output file pointer, post-filtered
%   fpnpf         -    Output file pointer, non-post filtered
%   fphpf         -    Output file pointer, highpass filtered
%   junkbuf       -    Unused dummy variable buffer (diskio return)
%   status        -    Status returned by file write operation (diskio return)
%   sumsnr        -    SNR averaging summation, non-postfiltered output speech
%   framesnr      -    SNR averaging subframe count, non-postfiltered output speech
%   snrflag       -    SNR threshold flag, non-postfiltered output speech
%   sumsnrp       -    SNR averaging summation, postfiltered output speech
%   framesnrp     -    SNR averaging subframe count, postfiltered output speech
%   snrflagp      -    SNR threshold flag, postfiltered output speech
%   sumsnrh       -    SNR averaging summation, highpass filtered output speech
%   framesnrh     -    SNR averaging subframe count, highpass filtered output speech
%   snrflagh      -    SNR threshold flag, highpass filtered output speech
%   dummy1        -    Unused dummy variable 
%   dummy2        -    Unused dummy variable
%   dummy3        -    Unused dummy variable
%   framedm       -    Speech distortion averaging subframe count
%   sumdm         -    Speech distortion summation over framedm subframes
%   dm            -    Speech distortion measures, current subframe
%   ssub          -    Subframe analysis buffer (input speech, ll samples = 1/2 old, 1/2 new)
%   hamws         -    Hamming window, one full subframe in length
%   ip            -    Post filter estimate of input power
%   op            -    Post filter estimate of output power
%   dp1           -    Postfilter memory
%   dp2           -    Postfilter memory
%   dp3           -    Postfilter memory
%   dhpf1o        -    FIR (all zero) highpass filter memory
%   dhpf2o        -    IIR (all pole) highpass filter memory
%   ahpfo         -    Highpass filter H(Z) numerator coefficients
%   bhpfo         -    Highpass filter H(Z) denominator coefficients
%
%
% GLOBALS
%   FrameCnt      -    Current frame number
%   guiSin        -    Input speech signal
%   guiSout       -    Output speech signal
%   guiRCs        -    LPC synthesis filter coefficients
%   guiFDM        -    Speech distortion averaging frame count
%   guisdm        -    Speech distortion summation over guiFDM frames
%   guidm         -    Speech distortion measures, current frame
%   avgSnrNPF     -    Average SNR, non-postfiltered output speech
%   avgSnrPF      -    Average SNR, postfiltered output speech
%   avgSnrHPF     -    Average SNR, highpass filtered output speech
%   SnrNPF        -    Current frame SNR, non-postfiltered output speech
%   SnrPF         -    Current frame SNR, postfiltered output speech
%   SnrHPF        -    Current frame SNR, highpass filtered output speech
%   guiExcit      -    Synthesis filter excitation
%   guiState      -    Graphical output or status output mode
%                      0 = status mode (non-interactive), 1 = graphics mode
%
% CONSTANTS
%   LFRAME        -   Analysis frame size
%   READ          -   Read flag to control diskio
%   WRITE         -   Write flag to control diskio
%   EOF           -   Status flag for diskio
%   STREAMBITS    -   Bits per frame of CELP analysis output
%   SYNTHESIS     -   Synthesis only simulation control flag
%   CODELENGTH1   -   Hamming codeword overall length (in bits)
%   CODELENGTH2   -   Hamming codeword data length (in bits)
%   PARITYLENGTH  -   Hamming codeword error protection length (in bits)
%   SYNDRUN       -   Bit error rate averaging constant
%   ALPHA         -   Postfilter pole/zero bandwidth expansion parameter
%   BETA          -   Postfilter pole/zero bandwidth expansion parameter
%
% ******************************************************************

% DECLARE GLOBAL CONSTANTS
global EOF LFRAME READ WRITE;

% DECLARE GLOBAL VARIABLES
global guiSin         guiSout    guiRCs    guiState
global guidm          guisdm     guiFDM
global avgSnrNPF      avgSnrPF   avgSnrHPF guiExcit
global SnrNPF         SnrPF      SnrHPF

% READ CELP ANALYSIS OUTPUT FROM A HEX FILE FOR SYNTHESIS ONLY SIMULATIONS
if SimType == SYNTHESIS
    pstream = gethex( STREAMBITS, line );
end

% INVERT BIT STREAM PERMUTATION IMPLEMENTED AT TRANSMITTER
stream( bitperm ) = pstream;

% SET MASK BITS TO PROTECT SPECIFIC BITS FROM BIT ERRORS
% mask(1:2:144) = ones(72,1);

% SIMULATE TRANSMISSION OF CELP BIT STREAM AND INJECT ERRORS
% AT SPECIFIED BIT ERROR RATE (BER)
% SIMULATE LOSSY CHANNEL BY INJECTING BIT ERRORS
[ stream, errors, total ] = biterror( ber, mask, stream, STREAMBITS, errors, total );

% DECODE ERROR PROTECTION BITS
if protect == TRUE

    % ADJUST BIT STREAM POINTER AND UNPACK PARITY BITS
    if SimType == SYNTHESIS
        pointer = 139;
    else
        pointer = pointer - PARITYLENGTH - 2;

⌨️ 快捷键说明

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