# v_pcmu2lin

## PURPOSE

V_PCMU2LIN Convert Mu-law PCM to linear X=(P,S)

## SYNOPSIS

function x=v_pcmu2lin(p,s)

## DESCRIPTION

    V_PCMU2LIN Convert Mu-law PCM to linear X=(P,S)
        lin = v_pcmu2lin(pcmu) where pcmu contains a vector
        of mu-law values in the range 0 to 255.
        No checking is performed to see that numbers are in this range.

        Output values are divided by the scale factor s:

               s        Output Range

               1        +-8031    (integer values)
            4004.2    +-2.005649 (default)
            8031        +-1
            8159        +-0.9843118 (+-1 nominal full scale)

        The default scaling factor 4004.189931 is equal to
        sqrt((2207^2 + 5215^2)/2) this follows ITU standard G.711.
        The sine wave with PCM-Mu values [158 139 139 158 30 11 11 30]
        has a mean square value of unity corresponding to 0 dBm0.

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- v_readau V_READAU Read a SUN .AU format sound file [Y,FS,H]=(FILENAME)
- v_readsph V_READSPH Read a SPHERE/TIMIT format sound file [Y,FS,WRD,PHN,FFX]=(FILENAME,MODE,NMAX,NSKIP)
- v_readwav V_READWAV Read a .WAV format sound file [Y,FS,WMODE,FIDX]=(FILENAME,MODE,NMAX,NSKIP)

## SOURCE CODE

    0001 function x=v_pcmu2lin(p,s)
    0002 %V_PCMU2LIN Convert Mu-law PCM to linear X=(P,S)
    0003 %    lin = v_pcmu2lin(pcmu) where pcmu contains a vector
    0004 %    of mu-law values in the range 0 to 255.
    0005 %    No checking is performed to see that numbers are in this range.
    0006 %
    0007 %    Output values are divided by the scale factor s:
    0008 %
    0009 %           s        Output Range
    0010 %
    0011 %           1        +-8031    (integer values)
    0012 %        4004.2    +-2.005649 (default)
    0013 %        8031        +-1
    0014 %        8159        +-0.9843118 (+-1 nominal full scale)
    0015 %
    0016 %    The default scaling factor 4004.189931 is equal to
    0017 %    sqrt((2207^2 + 5215^2)/2) this follows ITU standard G.711.
    0018 %    The sine wave with PCM-Mu values [158 139 139 158 30 11 11 30]
    0019 %    has a mean square value of unity corresponding to 0 dBm0.
    0020
    0021
    0022
    0023 %      Copyright (C) Mike Brookes 1998
    0024 %      Version: $Id: v_pcmu2lin.m 10865 2018-09-21 17:22:45Z dmb $
    0025 %
    0026 %   VOICEBOX is a MATLAB toolbox for speech processing.
    0027 %   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
    0028 %
    0029 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0030 %   This program is free software; you can redistribute it and/or modify
    0031 %   it under the terms of the GNU Lesser General Public License as published by
    0032 %   the Free Software Foundation; either version 3 of the License, or
    0033 %   (at your option) any later version.
    0034 %
    0035 %   This program is distributed in the hope that it will be useful,
    0036 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
    0037 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    0038 %   GNU Lesser General Public License for more details.
    0039 %
    0040 %   You can obtain a copy of the GNU Lesser General Public License from
    0041 %   https://www.gnu.org/licenses/ .
    0042 %
    0043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    0044
    0045 if nargin<2
    0046   t=9.98953613E-4;
    0047 else
    0048   t=4/s;
    0049 end
    0050
    0051 m=15-rem(p,16);
    0052 q=floor(p/128);
    0053 e=(127-p-m+128*q)/16;
    0054 x=(q-0.5).*(pow2(m+16.5,e)-16.5)*t;