xcorr xcov arma2ss function added 60/7060/6
steer [Wed, 25 Apr 2012 13:06:37 +0000 (15:06 +0200)]
Change-Id: Ife6e07bafc68e6027c01eaf454ee1f787c2be18d

15 files changed:
SEP/SEP_079_arma2ss.odt [new file with mode: 0644]
SEP/SEP_080_xcorr_xcov.odt [new file with mode: 0644]
scilab/CHANGES_5.4.X
scilab/modules/cacsd/help/en_US/arma2ss.xml [new file with mode: 0644]
scilab/modules/cacsd/macros/arma2ss.sci [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/arma2ss.dia.ref [new file with mode: 0644]
scilab/modules/cacsd/tests/unit_tests/arma2ss.tst [new file with mode: 0644]
scilab/modules/signal_processing/help/en_US/xcorr.xml [new file with mode: 0644]
scilab/modules/signal_processing/help/en_US/xcov.xml [new file with mode: 0644]
scilab/modules/signal_processing/macros/xcorr.sci [new file with mode: 0644]
scilab/modules/signal_processing/macros/xcov.sci [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/xcorr.dia.ref [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/xcorr.tst [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/xcov.dia.ref [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/xcov.tst [new file with mode: 0644]

diff --git a/SEP/SEP_079_arma2ss.odt b/SEP/SEP_079_arma2ss.odt
new file mode 100644 (file)
index 0000000..aa2d64b
Binary files /dev/null and b/SEP/SEP_079_arma2ss.odt differ
diff --git a/SEP/SEP_080_xcorr_xcov.odt b/SEP/SEP_080_xcorr_xcov.odt
new file mode 100644 (file)
index 0000000..618a84f
Binary files /dev/null and b/SEP/SEP_080_xcorr_xcov.odt differ
index 8d9f635..8547687 100644 (file)
@@ -437,6 +437,9 @@ CACSD & Signal Processing
   - conv2 - discrete 2-D convolution.
   - convol2d - discrete 2-D convolution, using fft.
   - phaseplot - frequency phase plot.
+  - xcorr - auto and cross correlation of signals (superseeds corr).
+  - xcov - auto and cross correlationvariance of signals (superseeds corr).
+  - arma2ss - conversion of an arma data structure into a state space one.
 
 * 'mtlb_conv' compatibility function is now obsolete. Please use 'conv' instead.
 
diff --git a/scilab/modules/cacsd/help/en_US/arma2ss.xml b/scilab/modules/cacsd/help/en_US/arma2ss.xml
new file mode 100644 (file)
index 0000000..2b7144c
--- /dev/null
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+Copyright (C) 2012 - INRIA - Serge Steer
+
+This file must be used under the terms of the CeCILL.
+This source file is licensed as described in the file COPYING, which
+you should have received as part of this distribution.  The terms
+are also available at
+http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ * Add some comments about XML file
+-->
+<refentry version="5.0-subset Scilab" xml:id="arma2ss" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns3="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+  <info>
+    <pubdate>$LastChangedDate: 20-04-2012 $</pubdate>
+  </info>
+
+  <refnamediv>
+    <refname>arma2ss</refname>
+
+    <refpurpose>transform an armax data structure into state space
+    representation.</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+
+    <synopsis>[S,Sn] = arma2ss(Ar)
+S = arma2ss(Ar)</synopsis>
+  </refsynopsisdiv>
+
+  <refsection>
+    <title>Parameters</title>
+
+    <variablelist>
+      <varlistentry>
+        <term>Ar</term>
+
+        <listitem>
+          <para>an armax data structure (see <link
+          linkend="armac">armac</link>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>S</term>
+
+        <listitem>
+          <para>a discrete time state space data structure (see <link
+          linkend="syslin">syslin</link>. The regular input to ouput
+          transfer.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>Sn</term>
+
+        <listitem>
+          <para>a discrete time state space data structure (see <link
+          linkend="syslin">syslin</link>. The noise input to ouput
+          transfer.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+
+  <refsection>
+    <title>Description</title>
+
+    <para><literal>[S,Sn] = arma2ss(Ar) </literal>transform an armax data
+    structure into a state space representation. The full armax transfer
+    <literal>F</literal>can be obtained by <literal>F=[S,Sn]</literal>.</para>
+  </refsection>
+
+  <refsection>
+    <title>Examples</title>
+
+    <programlisting role="example">A = [eye(2,2),[-1.5 0.1;-0.2 1.5],[0.7 -0.3;0.1 0.7]];
+B = [[0;0] [1;-1] [0.5;1.2]];
+Ar = armac(A, B, zeros(2, 2), 2, 1, 0)
+[S, Sn] = arma2ss(Ar)    </programlisting>
+  </refsection>
+
+  <refsection>
+    <title>See Also</title>
+
+    <simplelist type="inline">
+      <member><link linkend="armac">armac</link></member>
+
+      <member><link linkend="arma">arma</link></member>
+
+      <member><link linkend="syslin">syslin</link></member>
+    </simplelist>
+  </refsection>
+
+  <refsection>
+    <title>Authors</title>
+
+    <simplelist type="vert">
+      <member>Serge Steer, INRIA</member>
+    </simplelist>
+  </refsection>
+
+  <refsection>
+    <title>History</title>
+
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+
+        <revremark>arma2ss added.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/cacsd/macros/arma2ss.sci b/scilab/modules/cacsd/macros/arma2ss.sci
new file mode 100644 (file)
index 0000000..f40acdb
--- /dev/null
@@ -0,0 +1,69 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - INRIA - Serge Steer
+// 
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at    
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+function [S,Sn]=arma2ss(Ar)
+//Ar : an armax data structure
+//S  : a discrete state space data structure (syslin) the regular input to
+//     output transfer
+//Sn  : a discrete state space data structure (syslin) the noise input to
+//     output transfer
+  if typeof(Ar)<>"ar" then
+    error(msprintf(_("%s : Wrong type for input argument #%d: An armax system expected.\n"),"arma2ss",1))
+  end
+  a=Ar.a;
+  b=Ar.b;
+  d=Ar.d;
+  nu=Ar.nu;
+  sig=Ar.sig;
+  [ma,na]=size(a);
+  nb=size(b,2);
+  nd=size(d,2);
+  
+  a1=a(:,ma+1:$) //a(:,1:ma) supposed to be the identity
+  if a1==[] then a1=zeros(ma,ma);na=2*ma;end
+
+  //the input to output transfer
+  A=[-a1, b(:,nu+1:$)];
+  N=size(A,2);
+  A=[A
+     eye(na-2*ma,N)];
+  B=[b(:,1:nu);
+     zeros(na-2*ma,nu)]
+
+  M=size(A,1)
+  if nb-nu>0 then
+    A=[A 
+       zeros(nu,N)
+       zeros(N-M-nu,na-ma) eye(N-M-nu,nb-nu)]
+    B=[B
+       eye(nu,nu)
+       zeros(N-M-nu,nu)]
+  end
+  C=eye(ma,N)
+  S=syslin('d',A,B,C)
+   
+  //the noise to output transfer
+  A=[-a1, d(:,ma+1:$)];
+  N=size(A,2);
+  A=[A
+     eye(na-2*ma,N)];
+  M=size(A,1)
+  B=[d(:,1:ma)
+     zeros(na-2*ma,ma)]
+  if nd-ma>0 then
+      A=[A 
+       zeros(ma,N)
+       zeros(N-M-ma,na-ma) eye(N-M-ma,nd-ma)]
+    B=[B
+       eye(ma,ma)
+       zeros(N-M-ma,ma)]
+  end
+  C=eye(ma,N)
+  Sn=syslin('d',A,B*sig,C)
+endfunction
diff --git a/scilab/modules/cacsd/tests/unit_tests/arma2ss.dia.ref b/scilab/modules/cacsd/tests/unit_tests/arma2ss.dia.ref
new file mode 100644 (file)
index 0000000..acd870f
--- /dev/null
@@ -0,0 +1,83 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+ny=1,nu=1,sig=0.01;
+ ny  =
+    1.  
+ nu  =
+    1.  
+ar=armac(1,[0,0.2],[0,1],ny,nu,sig);
+[S,Sn]=arma2ss(ar);
+A=[0,0.2;0,0];B=[0;1];C=[1,0];D=0;
+assert_checkequal(S.A,A);
+assert_checkequal(S.B,B);
+assert_checkequal(S.C,C);
+assert_checkequal(S.D,D);
+A=[0,1;0,0];B=[0;0.01];C=[1,0];D=0;
+assert_checkequal(Sn.A,A);
+assert_checkequal(Sn.B,B);
+assert_checkequal(Sn.C,C);
+assert_checkequal(Sn.D,D);
+//
+ny=1,nu=1;
+ ny  =
+    1.  
+ar=armac([1,-0.8,0.2],0.001,0,ny,nu,0);
+[S,Sn]=arma2ss(ar);
+A=[0.8,-0.2;1,0];B=[0.001;0];C=[1,0];D=0;
+assert_checkequal(S.A,A);
+assert_checkequal(S.B,B);
+assert_checkequal(S.C,C);
+assert_checkequal(S.D,D);
+A=[0.8,-0.2;1,0];B=[0;0];C=[1,0];D=0;
+assert_checkequal(Sn.A,A);
+assert_checkequal(Sn.B,B);
+assert_checkequal(Sn.C,C);
+assert_checkequal(Sn.D,D);
+a=[1,-2.851,2.717,-0.865].*.eye(2,2);
+b=[0,1,1,1].*.[1;1];
+d=[1,0.7,0.2].*.eye(2,2);
+sig=eye(2,2);
+ar=armac(a,b,d,2,1,sig);
+[S,Sn]=arma2ss(ar);
+A=[2.851,0,    -2.717,0,     0.865,0,    1,1,1;
+   0,    2.851,0,     -2.717,0,    0.865,1,1,1;
+   1,    0,    0,      0,    0,    0,    0,0,0;
+   0,    1,    0,      0,    0,    0,    0,0,0;
+   0,    0,    1,      0,    0,    0,    0,0,0;
+   0,    0,    0,      1,    0,    0,    0,0,0;
+   0,    0,    0,      0,    0,    0,    0,0,0;
+   0,    0,    0,      0,    0,    0,    1,0,0;
+   0,    0,    0,      0,    0,    0,    0,1,0];
+B=[0;0;0;0;0;0;1;0;0];
+C=[1,0,0,0,0,0,0,0,0;
+   0,1,0,0,0,0,0,0,0];
+D=[0;0];
+assert_checkequal(S.A,A);
+assert_checkequal(S.B,B);
+assert_checkequal(S.C,C);
+assert_checkequal(S.D,D);
+A=[2.851,0,-2.717,0,0.865,0,0.7,0,0.2,0;
+   0,2.851,0,-2.717,0,0.865,0,0.7,0,0.2;
+   1,0,0,0,0,0,0,0,0,0;
+   0,1,0,0,0,0,0,0,0,0;
+   0,0,1,0,0,0,0,0,0,0;
+   0,0,0,1,0,0,0,0,0,0;
+   0,0,0,0,0,0,0,0,0,0;
+   0,0,0,0,0,0,0,0,0,0;
+   0,0,0,0,0,0,1,0,0,0;
+   0,0,0,0,0,0,0,1,0,0];
+B=[1,0;0,1;0,0;0,0;0,0;0,0;1,0;0,1;0,0;0,0];
+C=[1,0,0,0,0,0,0,0,0,0;0,1,0,0,0,0,0,0,0,0];
+D=[0,0;0,0];
+assert_checkequal(Sn.A,A);
+assert_checkequal(Sn.B,B);
+assert_checkequal(Sn.C,C);
+assert_checkequal(Sn.D,D);
diff --git a/scilab/modules/cacsd/tests/unit_tests/arma2ss.tst b/scilab/modules/cacsd/tests/unit_tests/arma2ss.tst
new file mode 100644 (file)
index 0000000..e41261e
--- /dev/null
@@ -0,0 +1,80 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2012 - INRIA - Serge Steer
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+ny=1,nu=1,sig=0.01;
+ar=armac(1,[0,0.2],[0,1],ny,nu,sig);
+[S,Sn]=arma2ss(ar);
+A=[0,0.2;0,0];B=[0;1];C=[1,0];D=0;
+assert_checkequal(S.A,A);
+assert_checkequal(S.B,B);
+assert_checkequal(S.C,C);
+assert_checkequal(S.D,D);
+A=[0,1;0,0];B=[0;0.01];C=[1,0];D=0;
+assert_checkequal(Sn.A,A);
+assert_checkequal(Sn.B,B);
+assert_checkequal(Sn.C,C);
+assert_checkequal(Sn.D,D);
+//
+ny=1,nu=1;
+ar=armac([1,-0.8,0.2],0.001,0,ny,nu,0);
+[S,Sn]=arma2ss(ar);
+A=[0.8,-0.2;1,0];B=[0.001;0];C=[1,0];D=0;
+assert_checkequal(S.A,A);
+assert_checkequal(S.B,B);
+assert_checkequal(S.C,C);
+assert_checkequal(S.D,D);
+A=[0.8,-0.2;1,0];B=[0;0];C=[1,0];D=0;
+assert_checkequal(Sn.A,A);
+assert_checkequal(Sn.B,B);
+assert_checkequal(Sn.C,C);
+assert_checkequal(Sn.D,D);
+
+
+
+a=[1,-2.851,2.717,-0.865].*.eye(2,2);
+b=[0,1,1,1].*.[1;1];
+d=[1,0.7,0.2].*.eye(2,2);
+sig=eye(2,2);
+ar=armac(a,b,d,2,1,sig);
+
+[S,Sn]=arma2ss(ar);
+
+A=[2.851,0,    -2.717,0,     0.865,0,    1,1,1;
+   0,    2.851,0,     -2.717,0,    0.865,1,1,1;
+   1,    0,    0,      0,    0,    0,    0,0,0;
+   0,    1,    0,      0,    0,    0,    0,0,0;
+   0,    0,    1,      0,    0,    0,    0,0,0;
+   0,    0,    0,      1,    0,    0,    0,0,0;
+   0,    0,    0,      0,    0,    0,    0,0,0;
+   0,    0,    0,      0,    0,    0,    1,0,0;
+   0,    0,    0,      0,    0,    0,    0,1,0];
+B=[0;0;0;0;0;0;1;0;0];
+C=[1,0,0,0,0,0,0,0,0;
+   0,1,0,0,0,0,0,0,0];
+D=[0;0];
+assert_checkequal(S.A,A);
+assert_checkequal(S.B,B);
+assert_checkequal(S.C,C);
+assert_checkequal(S.D,D);
+
+A=[2.851,0,-2.717,0,0.865,0,0.7,0,0.2,0;
+   0,2.851,0,-2.717,0,0.865,0,0.7,0,0.2;
+   1,0,0,0,0,0,0,0,0,0;
+   0,1,0,0,0,0,0,0,0,0;
+   0,0,1,0,0,0,0,0,0,0;
+   0,0,0,1,0,0,0,0,0,0;
+   0,0,0,0,0,0,0,0,0,0;
+   0,0,0,0,0,0,0,0,0,0;
+   0,0,0,0,0,0,1,0,0,0;
+   0,0,0,0,0,0,0,1,0,0];
+B=[1,0;0,1;0,0;0,0;0,0;0,0;1,0;0,1;0,0;0,0];
+C=[1,0,0,0,0,0,0,0,0,0;0,1,0,0,0,0,0,0,0,0];
+D=[0,0;0,0];
+assert_checkequal(Sn.A,A);
+assert_checkequal(Sn.B,B);
+assert_checkequal(Sn.C,C);
+assert_checkequal(Sn.D,D);
diff --git a/scilab/modules/signal_processing/help/en_US/xcorr.xml b/scilab/modules/signal_processing/help/en_US/xcorr.xml
new file mode 100644 (file)
index 0000000..4010c9c
--- /dev/null
@@ -0,0 +1,270 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+This file is part Scilab
+Copyright (C) 2012 - INRIA - Serge Steer
+This file must be used under the terms of the CeCILL.
+This source file is licensed as described in the file COPYING, which
+you should have received as part of this distribution.  The terms
+are also available at
+http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+-->
+<refentry version="5.0-subset Scilab" xml:id="xcorr" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns3="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+  <info>
+    <pubdate>$LastChangedDate: 24-04-2012 $</pubdate>
+  </info>
+
+  <refnamediv>
+    <refname>xcorr</refname>
+
+    <refpurpose>Computes discrete auto or cross correlation</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+
+    <synopsis>[c [,lagindex]] = xcorr(x [,maxlags [,scaling]])
+[c [,lagindex]] = xcorr(x,y [,maxlags [,scaling]])</synopsis>
+  </refsynopsisdiv>
+
+  <refsection>
+    <title>Parameters</title>
+
+    <variablelist>
+      <varlistentry>
+        <term>x</term>
+
+        <listitem>
+          <para>a vector of real or complex floating point numbers.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>y</term>
+
+        <listitem>
+          <para>a vector of real or complex floating point numbers. The
+          default value is <literal>x</literal>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>maxlags</term>
+
+        <listitem>
+          <para>a scalar with integer value greater than 1. The default value
+          is <literal>n</literal>. Where <literal>n</literal> is the maximum
+          of the <literal>x</literal> and <literal>y</literal> vector
+          length.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>scaling</term>
+
+        <listitem>
+          <para>a character string with possible value:
+          <literal>"biased"</literal>, <literal>"unbiased"</literal>,
+          <literal>"coeff"</literal>, <literal>"none"</literal>. The default
+          value is <literal>"none"</literal>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>c</term>
+
+        <listitem>
+          <para>a vector of real or complex floating point numbers with same
+          orientation as <literal>x</literal>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>lagindex</term>
+
+        <listitem>
+          <para>a row vector, containing the lags index corresponding to the
+          <literal>c</literal> values.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+
+  <refsection>
+    <title>Description</title>
+
+    <itemizedlist>
+      <listitem>
+
+
+        <literal>c=xcorr(x)</literal>
+
+         computes the un-normalized discrete auto correlation:
+
+        <latex>{\begin{matrix}C_k = \sum_{i=1}^{n-k}
+        {x_{i+k}*x^{*}_i}, k \geq 0 \\ C_k = C^{*}_{-k}, k \leq
+        -1\end{matrix}.$</latex>
+
+         and return in
+
+        <literal>c</literal>
+
+         the sequence of auto correlation lags
+
+        <latex>$C_k,k=-n:n$</latex>
+
+         with
+
+        <literal>n</literal>
+
+         is the length of
+
+        <literal>x</literal>
+
+
+      </listitem>
+
+      <listitem>
+
+
+        <literal>xcorr(x,y)</literal>
+
+         computes the un-normalized discrete cross correlation:
+
+        <latex>{\begin{matrix}C_k = \sum_{i=1}^{n-k}
+        {x_{i+k}*y^{*}_i}, k \geq 0 \\ C_k = C^{*}_{-k}, k \leq
+        -1\end{matrix}}.$</latex>
+
+         and return in
+
+        <literal>c</literal>
+
+         the sequence of auto correlation lags
+
+        <latex>$C_k,k=-n:n$</latex>
+
+         with
+
+        <literal>n</literal>
+
+         is the maximum of
+
+        <literal>x</literal>
+
+         and
+
+        <literal>y</literal>
+
+         length's.
+      </listitem>
+    </itemizedlist>
+
+    <para>If the <literal>maxlags</literal> argument is given
+    <literal>xcorr</literal> returns in <literal>c</literal> the sequence of
+    auto correlation lags <latex>$C_k,k=-maxlags:maxlags$</latex>. If
+    <literal>maxlags</literal> is greater than <literal>length(x)</literal>,
+    the first and last values of <literal>c</literal> are zero.</para>
+
+    <para>The <literal>scaling</literal> argument decribes how
+    <latex>C(k)</latex> is normalized before being returned in
+    <literal>c</literal>: <itemizedlist>
+        <listitem><term>"biased"</term>:<literal>c=</literal><latex>$C$</latex><literal>/n</literal>.</listitem>
+
+        <listitem><term>"unbiased"</term>:<literal>c=</literal><latex>$C$</latex><literal>./(n-(-maxlags:maxlags))</literal>.</listitem>
+
+        <listitem><term>"coeff"</term>:<literal>c=</literal><latex>$C$</latex><literal>/(norm(x)*norm(y))</literal>.</listitem>
+      </itemizedlist></para>
+  </refsection>
+
+  <refsection>
+
+
+    <title>Remark</title>
+
+     The
+
+    <link linkend="corr">corr</link>
+
+     function computes the "biased" covariance of
+
+    <literal>x</literal>
+
+     and
+
+    <literal>y</literal>
+
+     and only return in
+
+    <literal>c</literal>
+
+     the sequence of auto correlation lags
+
+    <latex>$C_k,k \geq 0$</latex>
+
+    .
+  </refsection>
+
+  <refsection>
+    <refsection><title>Method</title> This function computes
+    <latex>$C$</latex> using
+    <literal>ifft(fft(x).*conj(fft(y)))</literal>.</refsection>
+
+    <refsection>
+      <title>Examples</title>
+
+      <programlisting role="example">t = linspace(0, 100, 2000);
+y = 0.8 * sin(t) + 0.8 * sin(2 * t);
+[c, ind] = xcorr(y, "biased");
+plot(ind, c)    </programlisting>
+    </refsection>
+
+    <refsection>
+      <title>See Also</title>
+
+      <simplelist type="inline">
+        <member>
+          <link linkend="xcov">xcov</link>
+        </member>
+
+        <member>
+          <link linkend="corr">corr</link>
+        </member>
+
+        <member>
+          <link linkend="fft">fft</link>
+        </member>
+      </simplelist>
+    </refsection>
+
+    <refsection>
+      <title>Authors</title>
+
+      <simplelist type="vert">
+        <member>Serge Steer, INRIA</member>
+      </simplelist>
+    </refsection>
+
+    <title>Used Functions</title>
+
+    <para>
+      <link linkend="fft">fft</link>
+    </para>
+  </refsection>
+
+  <refsection>
+    <title>History</title>
+
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+
+        <revremark>xcorr added.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/signal_processing/help/en_US/xcov.xml b/scilab/modules/signal_processing/help/en_US/xcov.xml
new file mode 100644 (file)
index 0000000..303b001
--- /dev/null
@@ -0,0 +1,272 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+This file is part Scilab
+Copyright (C) 2012 - INRIA - Serge Steer
+This file must be used under the terms of the CeCILL.
+This source file is licensed as described in the file COPYING, which
+you should have received as part of this distribution.  The terms
+are also available at
+http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+-->
+<refentry version="5.0-subset Scilab" xml:id="xcov" xml:lang="en"
+          xmlns="http://docbook.org/ns/docbook"
+          xmlns:xlink="http://www.w3.org/1999/xlink"
+          xmlns:svg="http://www.w3.org/2000/svg"
+          xmlns:ns3="http://www.w3.org/1999/xhtml"
+          xmlns:mml="http://www.w3.org/1998/Math/MathML"
+          xmlns:db="http://docbook.org/ns/docbook">
+  <info>
+    <pubdate>$LastChangedDate: 24-04-2012 $</pubdate>
+  </info>
+
+  <refnamediv>
+    <refname>xcov</refname>
+
+    <refpurpose>Computes discrete auto or cross covariance</refpurpose>
+  </refnamediv>
+
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+
+    <synopsis>[c [,lagindex]] = xcov(x [,maxlags [,scaling]])
+[c [,lagindex]] = xcov(x,y [,maxlags [,scaling]])</synopsis>
+  </refsynopsisdiv>
+
+  <refsection>
+    <title>Parameters</title>
+
+    <variablelist>
+      <varlistentry>
+        <term>x</term>
+
+        <listitem>
+          <para>a vector of real or complex floating point numbers.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>y</term>
+
+        <listitem>
+          <para>a vector of real or complex floating point numbers. The
+          default value is <literal>x</literal>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>maxlags</term>
+
+        <listitem>
+          <para>a scalar with integer value greater than 1. The default value
+          is <literal>n</literal>. Where <literal>n</literal> is the maximum
+          of the <literal>x</literal> and <literal>y</literal> vector
+          length.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>scaling</term>
+
+        <listitem>
+          <para>a character string with possible value:
+          <literal>"biased"</literal>, <literal>"unbiased"</literal>,
+          <literal>"coeff"</literal>, <literal>"none"</literal>. The default
+          value is <literal>"none"</literal>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>c</term>
+
+        <listitem>
+          <para>a vector of real or complex floating point numbers with same
+          orientation as <literal>x</literal>.</para>
+        </listitem>
+      </varlistentry>
+
+      <varlistentry>
+        <term>lagindex</term>
+
+        <listitem>
+          <para>a row vector, containing the lags index corresponding to the
+          <literal>c</literal> values.</para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+
+  <refsection>
+    <title>Description</title>
+
+    <itemizedlist>
+      <listitem>
+
+
+        <literal>c=xcov(x)</literal>
+
+         computes the un-normalized discrete covariance:
+
+        <latex>{\begin{matrix}C_k = \sum_{i=0}^{n-k-1}
+        {(x_{i+k}-\mu_x})({x_i-\mu_x})^{*} , k \geq 0 
+        \mu_x=\sum_{i=0}^{n-1}{x_i} C_k = C^{*}_{-k}, k \leq
+        -1\end{matrix}.}$</latex>
+
+         and return in
+
+        <literal>c</literal>
+
+         the sequence of covariance lags
+
+        <latex>$C_k,k=-n:n$</latex>
+
+         with
+
+        <literal>n</literal>
+
+         is the length of
+
+        <literal>x</literal>
+
+
+      </listitem>
+
+      <listitem>
+
+
+        <literal>xcov(x,y)</literal>
+
+         computes the un-normalized discrete cross covariance:
+
+        <latex>${\begin{matrix}C_k = \sum_{i=1}^{n-k}
+        {(x_{i+k}-\mu_x})*({y_i}-\mu_y)^{*}, k \geq 0
+        \mu_x=\sum_{i=0}^{n-1}{x_i} \mu_y=\sum_{i=0}^{n-1}{y_i} C_k =
+        C^{*}_{-k}, k \leq -1\end{matrix}.}$</latex>
+
+         and return in
+
+        <literal>c</literal>
+
+         the sequence of cross covariance lags
+
+        <latex>$C_k,k=-n:n$</latex>
+
+         with
+
+        <literal>n</literal>
+
+         is the maximum of
+
+        <literal>x</literal>
+
+         and
+
+        <literal>y</literal>
+
+         length's.
+      </listitem>
+    </itemizedlist>
+
+    <para>If the <literal>maxlags</literal> argument is given
+    <literal>xcov</literal> returns in <literal>c</literal> the sequence of
+    covariance lags <latex>$C_k,k=-maxlags:maxlags$</latex>. If
+    <literal>maxlags</literal> is greater than <literal>length(x)</literal>,
+    the first and last values of <literal>c</literal> are zero.</para>
+
+    <para>The <literal>scaling</literal> argument decribes how
+    <latex>C(k)</latex> is normalized before being returned in
+    <literal>c</literal>: <itemizedlist>
+        <listitem><term>"biased"</term>:<literal>c=</literal><latex>$C$</latex><literal>/n</literal>.</listitem>
+
+        <listitem><term>"unbiased"</term>:<literal>c=</literal><latex>$C$</latex><literal>./(n-(-maxlags:maxlags))</literal>.</listitem>
+
+        <listitem><term>"coeff"</term>:<literal>c=</literal><latex>$C$</latex><literal>/(norm(x)*norm(y))</literal>.</listitem>
+      </itemizedlist></para>
+  </refsection>
+
+  <refsection>
+
+
+    <title>Remark</title>
+
+     The
+
+    <link linkend="corr">corr</link>
+
+     function computes the "biased" covariance of
+
+    <literal>x</literal>
+
+     and
+
+    <literal>y</literal>
+
+     and only return in
+
+    <literal>c</literal>
+
+     the sequence of covariance lags
+
+    <latex>$C_k,k \geq 0$</latex>
+
+    .
+  </refsection>
+
+  <refsection>
+    <refsection><title>Method</title> This function computes
+    <latex>$C$</latex> using
+    <literal>xcorr(x-mean(x),y-mean(y),...)</literal>.</refsection>
+
+    <refsection>
+      <title>Examples</title>
+
+      <programlisting role="example">t = linspace(0, 100,2 000);
+y = 0.8 * sin(t) + 0.8 * sin(2 * t);
+[c, ind] = xcov(y, "biased");
+plot(ind, c)    </programlisting>
+    </refsection>
+
+    <refsection>
+      <title>See Also</title>
+
+      <simplelist type="inline">
+        <member>
+          <link linkend="xcorr">xcorr</link>
+        </member>
+
+        <member>
+          <link linkend="corr">corr</link>
+        </member>
+
+        <member>
+          <link linkend="fft">fft</link>
+        </member>
+      </simplelist>
+    </refsection>
+
+    <refsection>
+      <title>Authors</title>
+
+      <simplelist type="vert">
+        <member>Serge Steer, INRIA</member>
+      </simplelist>
+    </refsection>
+
+    <title>Used Functions</title>
+
+    <para>
+      <link linkend="xcorr">xcorr</link>
+    </para>
+  </refsection>
+
+  <refsection>
+    <title>History</title>
+
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+
+        <revremark>xcov added.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/signal_processing/macros/xcorr.sci b/scilab/modules/signal_processing/macros/xcorr.sci
new file mode 100644 (file)
index 0000000..326d222
--- /dev/null
@@ -0,0 +1,124 @@
+// This file is part Scilab
+// Copyright (C) 2012 - INRIA - Serge Steer
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+function [c,lagindex]=xcorr(x,varargin)
+  nv=size(varargin)
+  if nv>0&type(varargin(nv))==10 then
+    validemodes=["biased","unbiased","coeff","none"]
+    scalemode=varargin(nv)
+    if and(scalemode<>validemodes) then
+      error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),...
+                     "xcorr",nv+1,strcat(""""+validemodes+"""",",")))
+    end
+    nv=nv-1;
+  else
+    scalemode="none"
+  end
+  //test de validit√© de x
+  szx=size(x)
+  if type(x)<>1|and(szx>1) then
+    error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),...
+                   "xcorr",1))
+  end
+
+  autocorr=%t
+  maxlags=[]
+  if nv==1 then
+    if size(varargin(1),'*')==1 then //xcorr(x,maxlags)
+      autocorr=%t
+      maxlags=int(varargin(1))
+      if type( maxlags)<>1|size(maxlags,'*')>1|~isreal(maxlags)|maxlags<>int(maxlags) then
+        error(msprintf(_("%s: Wrong type for argument %d: an integer  expected.\n"),...
+                       "xcorr",2))
+      end
+      if maxlags<1 then
+        error(msprintf(_("%s: Wrong value for argument %d: the expected value must be greater than %s.\n"),...
+                       "xcorr",2,1))
+      end
+    else //xcorr(x,y)
+      autocorr=%f
+      y=varargin(1)
+      if type(y)<>1|and(size(y)>1) then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),...
+                       "xcorr",2))
+      end
+      maxlags=[]
+    end
+  elseif nv==2 then //xcorr(x,y,maxlag)
+    autocorr=%f
+    y=varargin(1)
+    if type(y)<>1|and(size(y)>1) then
+      error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),...
+                     "xcorr",2))
+    end
+    maxlags=int(varargin(2))
+    if type( maxlags)<>1|size(maxlags,'*')>1|~isreal(maxlags)|maxlags<>int(maxlags) then
+      error(msprintf(_("%s: Wrong type for argument %d: an integer  expected.\n"),...
+                       "xcorr",2))
+    end
+    if maxlags<1 then
+      error(msprintf(_("%s: Wrong value for argument %d: the expected value must be greater than %s.\n"),...
+                       "xcorr",2,1))
+    end
+  end
+  
+  if autocorr then //auto correlation
+    x=matrix(x,-1,1);n=size(x,'*')
+    if maxlags==[] then maxlags=n-1,end
+    npad=2^nextpow2(2*n-1)
+    x(npad)=0;
+    t=fft(x);
+    c=ifft(real(t.*conj(t)))
+    if isreal(x) then c=real(c);end
+  else //cross correlation
+    x=matrix(x,-1,1);nx=size(x,1)
+    xx=sum(abs(x)^2)
+    y=matrix(y,-1,1);ny=size(y,1)
+    yy=sum(abs(y)^2)
+    if nx<ny then 
+      x(ny)=0;
+    elseif ny<nx then
+      y(nx)=0;
+    end
+    n=max(nx,ny)
+    if maxlags==[] then maxlags=n-1,end
+    npad=2^nextpow2(2*n-1)
+    x(npad)=0;
+    y(npad)=0;
+    c=ifft(fft(x).*conj(fft(y)))
+    if isreal(x)&isreal(y) then c=real(c),end
+  end
+  //extract requested lags
+  padding=zeros(maxlags-n+1,1)
+  if maxlags<n then
+    c=[c($-maxlags+1:$);c(1:maxlags+1);]
+  else
+    padding=zeros(maxlags-n+1,1)
+    c = [padding;
+         c($-n+2:$);
+         c(1:n);
+         padding];
+  end
+  //normalization
+  select scalemode
+  case "biased" then
+    c=c/n
+  case "unbiased" then
+    scale=n-abs(-maxlags:maxlags)
+    scale(scale==0)=1;
+    c=c./scale'
+  case "coeff" then
+    if autocorr then
+      c=c/c(maxlags+1)
+    else
+      c=c/sqrt(xx*yy)
+    end
+  end
+  //give result same orientation as x
+  if szx(1)==1 then c=matrix(c,1,-1),end
+  if argn(1)==2 then lagindex=-maxlags:maxlags,end
+endfunction
diff --git a/scilab/modules/signal_processing/macros/xcov.sci b/scilab/modules/signal_processing/macros/xcov.sci
new file mode 100644 (file)
index 0000000..cab31e2
--- /dev/null
@@ -0,0 +1,76 @@
+// This file is part Scilab
+// Copyright (C) 2012 - INRIA - Serge Steer
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution.  The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+function [c,lagindex]=xcov(x,varargin)
+  nv=size(varargin)
+  if nv>0&type(varargin(nv))==10 then
+    validemodes=["biased","unbiased","coeff","none"]
+    scalemode=varargin(nv)
+    if and(scalemode<>validemodes) then
+      error(msprintf(_("%s: Wrong value for input argument #%d: Must be in the set {%s}.\n"),...
+                     "xcov",nv+1,strcat(""""+validemodes+"""",",")))
+    end
+    nv=nv-1;
+  else
+    scalemode="none"
+  end
+  //test de validit√© de x
+  szx=size(x)
+  if type(x)<>1|and(szx>1) then
+    error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),...
+                   "xcov",1))
+  end
+  x=x-mean(x)
+  autocorr=%t
+  maxlags=[]
+  if nv==1 then
+    if size(varargin(1),'*')==1 then //xcov(x,maxlags)
+      autocorr=%t
+      maxlags=int(varargin(1))
+      if type( maxlags)<>1|size(maxlags,'*')>1|~isreal(maxlags)|maxlags<>int(maxlags) then
+        error(msprintf(_("%s: Wrong type for argument %d: an integer  expected.\n"),...
+                       "xcov",2))
+      end
+      if maxlags<1 then
+        error(msprintf(_("%s: Wrong value for argument %d: the expected value must be greater than %s.\n"),...
+                       "xcov",2,1))
+      end
+    else //xcov(x,y)
+      autocorr=%f
+      y=varargin(1)
+      if type(y)<>1|and(size(y)>1) then
+        error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),...
+                       "xcov",2))
+      end
+      varargin(1)=y-mean(y)
+      maxlags=[]
+    end
+  elseif nv==2 then //xcov(x,y,maxlag)
+    autocorr=%f
+    y=varargin(1)
+    if type(y)<>1|and(size(y)>1) then
+      error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),...
+                     "xcov",2))
+    end
+    if type(y)<>1|and(size(y)>1) then
+      error(msprintf(_("%s: Wrong type for input argument #%d: Real or complex vector expected.\n"),...
+                     "xcov",2))
+    end
+    varargin(1)=y-mean(y)
+    maxlags=int(varargin(2))
+    if type( maxlags)<>1|size(maxlags,'*')>1|~isreal(maxlags)|maxlags<>int(maxlags) then
+      error(msprintf(_("%s: Wrong type for argument %d: an integer  expected.\n"),...
+                       "xcov",2))
+    end
+    if maxlags<1 then
+      error(msprintf(_("%s: Wrong value for argument %d: the expected value must be greater than %s.\n"),...
+                       "xcov",2,1))
+    end
+  end
+  [c,lagindex]=xcorr(x,varargin(:))
+endfunction
diff --git a/scilab/modules/signal_processing/tests/unit_tests/xcorr.dia.ref b/scilab/modules/signal_processing/tests/unit_tests/xcorr.dia.ref
new file mode 100644 (file)
index 0000000..d8074c7
--- /dev/null
@@ -0,0 +1,46 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+x=[1 2 3 4 3 2 1];
+c_ref=[1 4 10 20 31 40 44 40 31 20 10 4 1];
+assert_checkalmostequal(c_ref,xcorr(x));
+assert_checkalmostequal(c_ref,xcorr(x,"none"));
+assert_checkalmostequal(c_ref/7,xcorr(x,"biased"));
+assert_checkalmostequal(c_ref/44,xcorr(x,"coeff"));
+[c,ind]=xcorr(x);
+assert_checkalmostequal(c_ref./(7-abs(ind)),xcorr(x,"unbiased"));
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,3));
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,3,"none"));
+assert_checkalmostequal(c_ref(4:$-3)/7,xcorr(x,3,"biased"));
+assert_checkalmostequal(c_ref(4:$-3)/44,xcorr(x,3,"coeff"));
+[c,ind]=xcorr(x,3,"unbiased");
+assert_checkalmostequal(c_ref(4:$-3)./(7-abs(ind)),c);
+x=[1 2*%i 3 4 3 2 1];
+c_ref=[ 1,2+%i*2,6+%i*4,14+%i*6,23+%i*8,32+%i*4,44,...
+        32-%i*4,23-%i*8,14-%i*6,6-%i*4,2-%i*2,1];
+assert_checkalmostequal(c_ref,xcorr(x));
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,3));
+x=[1 2 3 4 3 2 1];
+y=[4 3 2 1];
+c_ref=[0,0,0, 1, 4, 10, 20, 28, 32, 30, 20, 11, 4];
+c=xcorr(x,y);
+assert_checktrue(isreal(c));
+assert_checkalmostequal(c_ref,c,sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref,xcorr(x,y,"none"),sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref/7,xcorr(x,y,"biased"),sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref/(norm(x)*norm(y)),xcorr(x,y,"coeff"),sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,y,3));
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,y,3,"none"));
+assert_checkalmostequal(c_ref(4:$-3)/7,xcorr(x,y,3,"biased"));
+assert_checkalmostequal(c_ref(4:$-3)/(norm(x)*norm(y)),xcorr(x,y,3,"coeff"));
+[c,ind]=xcorr(x,y,3,"unbiased");
+assert_checkalmostequal(c_ref(4:$-3)./(7-abs(ind)),c);
+x=[1 2 3 4 3 2 1];
+y=[4 3 2 1+%i];
+c_ref=[0,0,0, 1-%i, 4-%i*2, 10-%i*3, 20-%i*4, 28-%i*3, 32-%i*2, 30-%i, 20, 11, 4];
+c=xcorr(x,y);
+assert_checkalmostequal(c_ref,c,sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,y,3));
diff --git a/scilab/modules/signal_processing/tests/unit_tests/xcorr.tst b/scilab/modules/signal_processing/tests/unit_tests/xcorr.tst
new file mode 100644 (file)
index 0000000..ef2e1ad
--- /dev/null
@@ -0,0 +1,54 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+x=[1 2 3 4 3 2 1];
+c_ref=[1 4 10 20 31 40 44 40 31 20 10 4 1];
+assert_checkalmostequal(c_ref,xcorr(x));
+assert_checkalmostequal(c_ref,xcorr(x,"none"));
+assert_checkalmostequal(c_ref/7,xcorr(x,"biased"));
+assert_checkalmostequal(c_ref/44,xcorr(x,"coeff"));
+[c,ind]=xcorr(x);
+assert_checkalmostequal(c_ref./(7-abs(ind)),xcorr(x,"unbiased"));
+
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,3));
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,3,"none"));
+assert_checkalmostequal(c_ref(4:$-3)/7,xcorr(x,3,"biased"));
+assert_checkalmostequal(c_ref(4:$-3)/44,xcorr(x,3,"coeff"));
+[c,ind]=xcorr(x,3,"unbiased");
+assert_checkalmostequal(c_ref(4:$-3)./(7-abs(ind)),c);
+
+x=[1 2*%i 3 4 3 2 1];
+c_ref=[ 1,2+%i*2,6+%i*4,14+%i*6,23+%i*8,32+%i*4,44,...
+        32-%i*4,23-%i*8,14-%i*6,6-%i*4,2-%i*2,1];
+assert_checkalmostequal(c_ref,xcorr(x));
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,3));
+
+x=[1 2 3 4 3 2 1];
+y=[4 3 2 1];
+c_ref=[0,0,0, 1, 4, 10, 20, 28, 32, 30, 20, 11, 4];
+c=xcorr(x,y);
+assert_checktrue(isreal(c));
+assert_checkalmostequal(c_ref,c,sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref,xcorr(x,y,"none"),sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref/7,xcorr(x,y,"biased"),sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref/(norm(x)*norm(y)),xcorr(x,y,"coeff"),sqrt(%eps),20*%eps);
+
+
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,y,3));
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,y,3,"none"));
+assert_checkalmostequal(c_ref(4:$-3)/7,xcorr(x,y,3,"biased"));
+assert_checkalmostequal(c_ref(4:$-3)/(norm(x)*norm(y)),xcorr(x,y,3,"coeff"));
+[c,ind]=xcorr(x,y,3,"unbiased");
+assert_checkalmostequal(c_ref(4:$-3)./(7-abs(ind)),c);
+
+x=[1 2 3 4 3 2 1];
+y=[4 3 2 1+%i];
+c_ref=[0,0,0, 1-%i, 4-%i*2, 10-%i*3, 20-%i*4, 28-%i*3, 32-%i*2, 30-%i, 20, 11, 4];
+
+c=xcorr(x,y);
+assert_checkalmostequal(c_ref,c,sqrt(%eps),20*%eps);
+assert_checkalmostequal(c_ref(4:$-3),xcorr(x,y,3));
diff --git a/scilab/modules/signal_processing/tests/unit_tests/xcov.dia.ref b/scilab/modules/signal_processing/tests/unit_tests/xcov.dia.ref
new file mode 100644 (file)
index 0000000..6f34cfe
--- /dev/null
@@ -0,0 +1,16 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+x=[1 2 3 4 3 2 1];
+assert_checktrue(xcorr(x-mean(x))==xcov(x));
+x=[1 2*%i 3 4 3 2 1];
+assert_checktrue(xcorr(x-mean(x))==xcov(x));
+x=[1 2 3 4 3 2 1];
+y=[4 3 2 1];
+assert_checktrue(xcorr(x-mean(x),y-mean(y))==xcov(x,y));
+x=[1 2 3 4 3 2 1];
+y=[4 3 2 1+%i];
+assert_checktrue(xcorr(x-mean(x),y-mean(y))==xcov(x,y));
diff --git a/scilab/modules/signal_processing/tests/unit_tests/xcov.tst b/scilab/modules/signal_processing/tests/unit_tests/xcov.tst
new file mode 100644 (file)
index 0000000..be086df
--- /dev/null
@@ -0,0 +1,22 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2008 - DIGITEO
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+
+x=[1 2 3 4 3 2 1];
+assert_checktrue(xcorr(x-mean(x))==xcov(x));
+
+x=[1 2*%i 3 4 3 2 1];
+assert_checktrue(xcorr(x-mean(x))==xcov(x));
+
+
+x=[1 2 3 4 3 2 1];
+y=[4 3 2 1];
+assert_checktrue(xcorr(x-mean(x),y-mean(y))==xcov(x,y));
+
+x=[1 2 3 4 3 2 1];
+y=[4 3 2 1+%i];
+
+assert_checktrue(xcorr(x-mean(x),y-mean(y))==xcov(x,y));