octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

autocov and autocor


From: John W. Eaton
Subject: autocov and autocor
Date: Thu, 28 Oct 2010 03:09:35 -0400

Would someone with some signal processing expertise please take a look
at the following bug report and comment on the proposed changes?

  https://savannah.gnu.org/bugs/?31474

A google search shows that there have been a few other reports over
the years, but I'm surprised that there have not been more since these
functions have been in Octave for a dozen years and have not had any
changes that affect the numerical results.  So I'm wondering if there
is some other definition of autocor and autocov that matches the
Octave functions.

Also, these functions are not in Matlab.  Instead, the Matlab signal
processing toolbox has xcorr and xcov functions, which I believe do
the job that the person who reported the bug expects.  These functions
are also in the Octave Forge signal package.  So maybe we should
deprecate the autocov and autocor functions from Octave and eventually
remove them?  Or should they be fixed as proposed?  If they are, is it
possible that there is working code somewhere that depends on the
current behavior (i.e., there is an alternate useful definition of
autocor and autocov that Octave's current functions implement)?

I'm appending diffs below.

jwe


diff --git a/scripts/signal/autocor.m b/scripts/signal/autocor.m
--- a/scripts/signal/autocor.m
+++ b/scripts/signal/autocor.m
@@ -30,18 +30,24 @@
 
 function retval = autocor (X, h)
 
-  if (nargin == 1)
-    retval = autocov (X);
-  elseif (nargin == 2)
-    retval = autocov (X, h);
-  else
-    print_usage ();
+  [n, c] = size (X);
+
+  if (isvector (X))
+    n = length (X);
+    c = 1;
+    X = reshape (X, n, 1);
   endif
 
-  if (min (retval (1,:)) != 0)
-    retval = retval ./ (ones (rows (retval), 1) * retval(1,:));
+  if (nargin == 1)
+    h = n - 1;
   endif
 
+  retval = zeros (h + 1, c);
+
+  for i = 0 : h
+    retval(i+1, :) = diag (X(i+1:n, :).' * conj (X(1:n-i, :))).';
+  endfor
+
 endfunction
 
 
diff --git a/scripts/signal/autocov.m b/scripts/signal/autocov.m
--- a/scripts/signal/autocov.m
+++ b/scripts/signal/autocov.m
@@ -38,8 +38,6 @@
     X = reshape (X, n, 1);
   endif
 
-  X = center (X);
-
   if (nargin == 1)
     h = n - 1;
   endif
@@ -47,7 +45,11 @@
   retval = zeros (h + 1, c);
 
   for i = 0 : h
-    retval(i+1, :) = diag (X(i+1:n, :).' * conj (X(1:n-i, :))).' / n;
+    retval(i+1, :) = diag (X(i+1:n, :).' * conj (X(1:n-i, :))).';
+  endfor
+
+  for i = 1 : c
+    retval(:, i) = retval(:, i) - mean (X(:, i))^2;
   endfor
 
 endfunction



reply via email to

[Prev in Thread] Current Thread [Next in Thread]