/usr/share/octave/packages/communications-1.2.0/compand.m is in octave-communications-common 1.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | ## Copyright (C) 2001 Paul Kienzle
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {@var{y} =} compand (@var{x}, @var{mu}, @var{V}, "mu/compressor")
## @deftypefnx {Function File} {@var{y} =} compand (@var{x}, @var{mu}, @var{V}, "mu/expander")
## @deftypefnx {Function File} {@var{y} =} compand (@var{x}, @var{mu}, @var{V}, "A/compressor")
## @deftypefnx {Function File} {@var{y} =} compand (@var{x}, @var{mu}, @var{V}, "A/expander")
##
## Compresses and expanding the dynamic range of a signal using a mu-law or
## or A-law algorithm.
##
## The mu-law compressor/expander for reducing the dynamic range, is used
## if the fourth argument of @code{compand} starts with "mu/". Whereas the
## A-law compressor/expander is used if @code{compand} starts with "A/".
## The mu-law algorithm uses the formulation
##
## @tex
## $$
## y = {V log (1 + \\mu / V \\|x\\|) \\over log (1 + \\mu)} sgn(x)
## $$
## @end tex
## @ifnottex
## @example
## @group
##
## V log (1 + \mu/V |x|)
## y = -------------------- sgn(x)
## log (1 + \mu)
##
## @end group
## @end example
## @end ifnottex
##
## while the A-law algorithm used the formulation
##
## @tex
## $$
## y = { \\left\{ \\matrix{ {A / (1 + log A) x}, & 0 <= \\|x\\| <= V/A \\cr
## & \\cr
## {V log (1 + log(A/V \\|x\\|) ) \\over 1 + logA}, &
## V/A < \\|x\\| <= V} \\right. }
## $$
## @end tex
## @ifnottex
## @example
## @group
##
## / A / (1 + log A) x, 0 <= |x| <= V/A
## |
## y = < V ( 1 + log (A/V |x|) )
## | ----------------------- sgn(x), V/A < |x| <= V
## \ 1 + log A
## @end group
## @end example
## @end ifnottex
##
## Neither converts from or to audio file ulaw format. Use mu2lin or lin2mu
## instead.
##
## @seealso{m2ulin, lin2mu}
## @end deftypefn
function y = compand (x, mu, V, stype)
if (nargin != 3 && nargin != 4)
print_usage ();
endif
if (nargin < 4)
stype = "mu/compressor";
else
stype = tolower (stype);
endif
if (strcmp (stype, "mu/compressor"))
y = (V/log (1 + mu)) * log (1 + (mu/V)*abs (x)) .* sign (x);
elseif (strcmp (stype, "mu/expander"))
y = (V/mu) * (exp (abs (x) * (log (1 + mu)/V)) - 1) .* sign (x);
elseif (strcmp (stype, "a/compressor"))
y = zeros (size (x));
idx = find (abs (x) <= V/mu);
if (idx)
y(idx) = (mu / (1 + log (mu))) * abs (x(idx));
endif
idx = find (abs (x) > V/mu);
if (idx)
y(idx) = (V / (1 + log (mu))) * (1 + log ((mu/V) * abs (x(idx))));
endif
y = y .* sign (x);
elseif (strcmp (stype, "a/expander"))
y = zeros (size (x));
idx = find (abs (x) <= V / (1 + log (mu)));
if (idx)
y(idx) = ((1 + log (mu))/mu) * abs (x(idx));
endif
idx = find (abs (x) > V / (1 + log (mu)));
if (idx)
y(idx) = exp (((1 + log (mu))/V) * abs (x(idx)) - 1) * (V/mu);
endif
y = y .* sign (x);
endif
endfunction
%% Test input validation
%!error compand ()
%!error compand (1)
%!error compand (1, 2)
%!error compand (1, 2, 3, 4, 5)
|