]> Creatis software - CreaPhase.git/blob - octave_packages/m/deprecated/autocov.m
update packages
[CreaPhase.git] / octave_packages / m / deprecated / autocov.m
1 ## Copyright (C) 1995-2012 Friedrich Leisch
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} autocov (@var{x}, @var{h})
21 ## Return the autocovariances from lag 0 to @var{h} of vector @var{x}.
22 ## If @var{h} is omitted, all autocovariances are computed.
23 ## If @var{x} is a matrix, the autocovariances of each column are
24 ## computed.
25 ## The particular algorithm used is from the field of statistics and
26 ## differs from the definition used in signal processing.
27 ## @end deftypefn
28
29 ## Author: FL <Friedrich.Leisch@ci.tuwien.ac.at>
30 ## Description: Compute autocovariances
31
32 ## Deprecated in version 3.4
33
34 function retval = autocov (X, h)
35   persistent warned = false;
36   if (! warned)
37     warned = true;
38     warning ("Octave:deprecated-function",
39              "autocov is obsolete and will be removed from a future version of Octave; See the Octave-Forge signal package and the function xcov for a replacement");
40   endif
41
42   [n, c] = size (X);
43
44   if (isvector (X))
45     n = length (X);
46     c = 1;
47     X = reshape (X, n, 1);
48   endif
49
50   X = center (X);
51
52   if (nargin == 1)
53     h = n - 1;
54   endif
55
56   retval = zeros (h + 1, c);
57
58   for i = 0 : h
59     retval(i+1, :) = diag (X(i+1:n, :).' * conj (X(1:n-i, :))).' / n;
60   endfor
61
62 endfunction