# v_lin2pcma

## PURPOSE

V_LIN2PCMA Convert linear PCM to A-law P=(X,M,S)

## SYNOPSIS

function p=v_lin2pcma(x,m,s)

## DESCRIPTION

```V_LIN2PCMA Convert linear PCM to A-law P=(X,M,S)
pcma = v_lin2pcma(lin) where lin contains a vector
or matrix of signal values.
The input values will be converted to integer
A-law pcm vlues in the range 0 to 255 and the XORed with m
(default m=85).

Input values are multiplied by the scale factor s:

s        Input Range

1        +-4096
2017.396342    +-2.03033976 (default)
4096        +-1

Input values outside the selected range will be clipped.

The default value of the scale factor is 2017.396342 which equals
sqrt((1120^2 + 2624^2)/2). This factor follows ITU standard G.711 and
the sine wave with PCM-A values [225 244 244 225 97 116 116 97]
has a mean square value of unity corresponding to 0 dBm0.

## CROSS-REFERENCE INFORMATION

This function calls:
This function is called by:

## SOURCE CODE

```0001 function p=v_lin2pcma(x,m,s)
0002 %V_LIN2PCMA Convert linear PCM to A-law P=(X,M,S)
0003 %    pcma = v_lin2pcma(lin) where lin contains a vector
0004 %    or matrix of signal values.
0005 %    The input values will be converted to integer
0006 %    A-law pcm vlues in the range 0 to 255 and the XORed with m
0007 %    (default m=85).
0008 %
0009 %    Input values are multiplied by the scale factor s:
0010 %
0011 %           s        Input Range
0012 %
0013 %           1        +-4096
0014 %        2017.396342    +-2.03033976 (default)
0015 %        4096        +-1
0016 %
0017 %    Input values outside the selected range will be clipped.
0018 %
0019 %    The default value of the scale factor is 2017.396342 which equals
0020 %    sqrt((1120^2 + 2624^2)/2). This factor follows ITU standard G.711 and
0021 %    the sine wave with PCM-A values [225 244 244 225 97 116 116 97]
0022 %    has a mean square value of unity corresponding to 0 dBm0.
0023 %
0025
0026
0027
0028 %      Copyright (C) Mike Brookes 1998
0029 %      Version: \$Id: v_lin2pcma.m 10865 2018-09-21 17:22:45Z dmb \$
0030 %
0031 %   VOICEBOX is a MATLAB toolbox for speech processing.
0033 %
0034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0035 %   This program is free software; you can redistribute it and/or modify
0037 %   the Free Software Foundation; either version 2 of the License, or
0038 %   (at your option) any later version.
0039 %
0040 %   This program is distributed in the hope that it will be useful,
0041 %   but WITHOUT ANY WARRANTY; without even the implied warranty of
0042 %   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0043 %   GNU General Public License for more details.
0044 %
0045 %   You can obtain a copy of the GNU General Public License from
0046 %   http://www.gnu.org/copyleft/gpl.html or by writing to
0047 %   Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA.
0048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0049
0050 if nargin<3
0051   s=2017.396342;
0052   if nargin<2 m=85; end
0053 end
0054
0055 y=x*pow2(s,-6);
0056 y=(abs(y+63)-abs(y-63))/2;
0057 q=floor((y+64)/64);
0058 [a,e]=log2(abs(y));
0059 d = (e+abs(e))/2;
0060 p=128*q+16*d+floor(pow2(a,e-d+5));
0061 if m p=bitxor(p,m); end;```