ons, 21 10 2009 kl. 13:12 +0200, skrev Jaroslav Hajek:
> > When calling
> >
> > function [R, lags] = xcorr (X, Y, maxlag, scale)
> >
> > In octave, having maxlag longer than X returns an error message.
> > In Matlab, that is perfectly OK and zeros are padded around of the
> > correlation "center" when that is the case (and which is true
> > mathematically-wise).

I think the attached patch fixes this, but since you didn't provide an
example I'm not sure. It would be nice if you could possibly test this.

Thanks,
Søren
Index: xcorr.m
===================================================================
--- xcorr.m	(revision 6347)
+++ xcorr.m	(working copy)
@@ -127,8 +127,12 @@
   if !isscalar(maxlag) && !isempty(maxlag) 
     error("xcorr: maxlag must be a scalar"); 
   endif
-  if maxlag>N-1, 
-    error("xcorr: maxlag must be less than length(X)"); 
+  if (maxlag > N-1)
+    pad_result = maxlag - (N - 1);
+    maxlag = N - 1;
+    %error("xcorr: maxlag must be less than length(X)"); 
+  else
+    pad_result = 0;
   endif
   if isvector(X) && isvector(Y) && length(X) != length(Y) && \
 	!strcmp(scale,'none')
@@ -204,8 +208,12 @@
     R = R.'; 
   endif
   
+  ## Pad result if necesary
+  R = [zeros(1, pad_result), R, zeros(1, pad_result)];
+  
   ## return the lag indices if desired
   if nargout == 2
+    maxlag += pad_result;
     lags = [-maxlag:maxlag];
   endif
 
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to