V_LIN2PCMU Convert linear to Mu-law PCM P=(X,S) pcmu = v_lin2pcmu(lin) where lin contains a vector or matrix of signal values within a range determined by the scale factor s (see table below). Values outside this range will be clipped. The input values will be converted to integer Mu-law pcm vlues in the range 0 to 255. Input values are multiplied by the scale factor s: s Input Range 1 +-8159 4004.189931 +-2.03761563 (default) 8159 +-1 The default input scaling factor 4004.189931 is equal to sqrt((2207^2 + 5215^2)/2) and 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.
0001 function p=v_lin2pcmu(x,s) 0002 %V_LIN2PCMU Convert linear to Mu-law PCM P=(X,S) 0003 % pcmu = v_lin2pcmu(lin) where lin contains a vector 0004 % or matrix of signal values within a range determined by 0005 % the scale factor s (see table below). 0006 % Values outside this range will be clipped. 0007 % The input values will be converted to integer 0008 % Mu-law pcm vlues in the range 0 to 255. 0009 % 0010 % Input values are multiplied by the scale factor s: 0011 % 0012 % s Input Range 0013 % 0014 % 1 +-8159 0015 % 4004.189931 +-2.03761563 (default) 0016 % 8159 +-1 0017 % 0018 % The default input scaling factor 4004.189931 is equal to 0019 % sqrt((2207^2 + 5215^2)/2) and follows ITU standard G.711. 0020 % The sine wave with PCM-Mu values [158 139 139 158 30 11 11 30] 0021 % has a mean square value of unity corresponding to 0 dBm0. 0022 0023 0024 0025 % Copyright (C) Mike Brookes 1998 0026 % Version: $Id: v_lin2pcmu.m 10865 2018-09-21 17:22:45Z dmb $ 0027 % 0028 % VOICEBOX is a MATLAB toolbox for speech processing. 0029 % Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html 0030 % 0031 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0032 % This program is free software; you can redistribute it and/or modify 0033 % it under the terms of the GNU General Public License as published by 0034 % the Free Software Foundation; either version 2 of the License, or 0035 % (at your option) any later version. 0036 % 0037 % This program is distributed in the hope that it will be useful, 0038 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0039 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0040 % GNU General Public License for more details. 0041 % 0042 % You can obtain a copy of the GNU General Public License from 0043 % http://www.gnu.org/copyleft/gpl.html or by writing to 0044 % Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. 0045 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0046 0047 if nargin < 2 s=4004.189931; end 0048 y=x*s; 0049 y=(abs(y+8031)-abs(y-8031))/2; 0050 q=floor((y+8032)/8032); 0051 [m,e]=log2(abs(y)+33); 0052 p=175+128*q-8*(e+abs(e-6))-floor(32*m-16);