Bug #6009 fixed - conv2, convol2d and conv function added 01/5801/6
steer [Tue, 3 Jan 2012 15:03:41 +0000 (16:03 +0100)]
Change-Id: I060823d8318f35e1db4b0e30d49980e237279251

36 files changed:
SEP/INDEX
SEP/SEP_073_convolution_functions.odt [new file with mode: 0644]
scilab/CHANGES_5.4.X
scilab/modules/compatibility_functions/help/en_US/mtlb_conv.xml
scilab/modules/compatibility_functions/help/fr_FR/mtlb_conv.xml
scilab/modules/compatibility_functions/macros/mtlb_conv.sci
scilab/modules/m2sci/help/en_US/m2sci_equivalents/c/conv.xml
scilab/modules/m2sci/help/en_US/m2sci_equivalents/c/conv2.xml [new file with mode: 0644]
scilab/modules/m2sci/macros/sci_files/sci_conv.sci
scilab/modules/m2sci/macros/sci_files/sci_conv2.sci [new file with mode: 0644]
scilab/modules/signal_processing/Makefile.am
scilab/modules/signal_processing/Makefile.in
scilab/modules/signal_processing/demos/conv.dem.sce [new file with mode: 0644]
scilab/modules/signal_processing/demos/conv2.dem.sce [new file with mode: 0644]
scilab/modules/signal_processing/demos/image.dat [new file with mode: 0644]
scilab/modules/signal_processing/demos/signal_processing.dem.gateway.sce
scilab/modules/signal_processing/help/en_US/conv.xml [new file with mode: 0644]
scilab/modules/signal_processing/help/en_US/conv2.xml [new file with mode: 0644]
scilab/modules/signal_processing/help/en_US/convol2d.xml [new file with mode: 0644]
scilab/modules/signal_processing/includes/gw_signal.h
scilab/modules/signal_processing/macros/conv.sci [new file with mode: 0644]
scilab/modules/signal_processing/macros/convol2d.sci [new file with mode: 0644]
scilab/modules/signal_processing/sci_gateway/c/gw_signal.c
scilab/modules/signal_processing/sci_gateway/c/sci_conv2.c [new file with mode: 0644]
scilab/modules/signal_processing/sci_gateway/signal_processing_gateway.xml
scilab/modules/signal_processing/src/c/Libscilab_Import.def
scilab/modules/signal_processing/src/c/conv2.c [new file with mode: 0644]
scilab/modules/signal_processing/src/c/conv2.h [new file with mode: 0644]
scilab/modules/signal_processing/src/c/signal_processing.vcxproj
scilab/modules/signal_processing/src/c/signal_processing.vcxproj.filters
scilab/modules/signal_processing/tests/unit_tests/conv.dia.ref [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/conv.tst [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/conv2.dia.ref [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/conv2.tst [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/convol2d.dia.ref [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/convol2d.tst [new file with mode: 0644]

index d25e1d7..6d88e2b 100644 (file)
--- a/SEP/INDEX
+++ b/SEP/INDEX
@@ -68,4 +68,5 @@ SEP #068: Tempname
 SEP #069: Extend predef to get protected variable names
 SEP #070: Xcos validation functions
 SEP #071: Modify atomsRemove to delete tarball
-SEP #072: Extend “fullpath” to manage matrix of string as input argument
\ No newline at end of file
+SEP #072: Extend fullpath to manage matrix of string as input argument
+SEP #073: New convolution functions
\ No newline at end of file
diff --git a/SEP/SEP_073_convolution_functions.odt b/SEP/SEP_073_convolution_functions.odt
new file mode 100644 (file)
index 0000000..573a825
Binary files /dev/null and b/SEP/SEP_073_convolution_functions.odt differ
index 94564fe..8cd5fe0 100644 (file)
@@ -75,6 +75,23 @@ Xcos
                      format.
 
 
+Signal Processing
+=================
+
+* New functions:
+  - conv - discrete 1-D convolution.
+  - conv2 - discrete 2-D convolution.
+  - convol2d - discrete 2-D convolution, using fft.
+
+* Bug #6009 fixed - conv, conv2 and convol2d and conv functions were missing.
+
+
+Compatibility functions
+=======================
+
+* 'mtlb_conv' obsolete. Please use 'conv' instead.
+
+
 Bug fixes
 =========
 
index 3a6f1a8..7548e3c 100644 (file)
@@ -16,7 +16,7 @@
   </info>
   <refnamediv>
     <refname>mtlb_conv</refname>
-    <refpurpose>Matlab conv emulation function</refpurpose>
+    <refpurpose>Matlab conv emulation function. <emphasis role="bold">This function is obsolete.</emphasis></refpurpose>
   </refnamediv>
   <refsection>
     <title>Description</title>
     <para>Caution: <literal>mtlb_conv</literal> has not to be used for hand coded functions.</para>
   </refsection>
   <refsection role="see also">
-<title>See Also</title>
+    <title>See Also</title>
     <simplelist type="inline">
       <member>
         <link linkend="clean">clean</link>
       </member>
+      <member>
+        <link linkend="conv">conv</link>
+      </member>
     </simplelist>
   </refsection>
   <refsection>
       <member>V.C.</member>
     </simplelist>
   </refsection>
+  <refsection>
+    <title>History</title>
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+        <revremark>Function mtlb_conv is obsolete and will be removed in Scilab 5.4.1, use <link linkend="conv">conv</link> instead.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
 </refentry>
index abcb151..b7789d7 100644 (file)
@@ -16,7 +16,7 @@
   </info>
   <refnamediv>
     <refname>mtlb_conv</refname>
-    <refpurpose>Fonction d'émulation de la fonction Matlab conv</refpurpose>
+    <refpurpose>Fonction d'émulation de la fonction Matlab conv. <emphasis role="bold">Cette fonction est obsolète.</emphasis></refpurpose>
   </refnamediv>
   <refsection>
     <title>Description</title>
     <para>Attention : <literal>mtlb_conv</literal> ne doit pas être utilisée pour une programmation manuelle.</para>
   </refsection>
   <refsection role="see also">
-<title>Voir aussi</title>
+    <title>Voir aussi</title>
     <simplelist type="inline">
       <member>
         <link linkend="clean">clean</link>
       </member>
+      <member>
+        <link linkend="conv">conv</link>
+      </member>
     </simplelist>
   </refsection>
   <refsection>
       <member>V.C.</member>
     </simplelist>
   </refsection>
+  <refsection>
+    <title>Historique</title>
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+        <revremark>La fonction mtlb_conv est obsolète et sera supprimée dans Scilab 5.4.1, utiliser <link linkend="conv">conv</link> en remplacement.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
 </refentry>
index 96c361d..8763cc0 100644 (file)
@@ -9,11 +9,6 @@
 
 function [w]=mtlb_conv(u,v)
 // Emulation function for Matlab conv()
-
-w=clean(convol(u,v))
-if size(u,1)>1 | size(v,1)>1 then
-  w=w.'
-end
+warnobsolete("conv", "5.4.1");
+w = conv(u,v);
 endfunction
-
-
index 57259c7..4d79a91 100644 (file)
@@ -13,7 +13,7 @@
 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="m2sci_conv">
   <refnamediv>
     <refname>conv (Matlab function)</refname>
-    <refpurpose>Convolution</refpurpose>
+    <refpurpose>1-D Convolution</refpurpose>
   </refnamediv>
   <refsection>
     <title>Matlab/Scilab equivalent</title>
@@ -34,19 +34,10 @@ conv
         </td>
         <td>
           <programlisting role="example"><![CDATA[
-convol
+conv
 ]]></programlisting>
         </td>
       </tr>
     </informaltable>
   </refsection>
-  <refsection>
-    <title>Particular cases</title>
-    <para>
-Scilab <emphasis role="bold">convol</emphasis> output value is always a row vector while Matlab <emphasis role="bold">conv</emphasis> output value is a column vector if at least one input is a column vector.
-</para>
-    <para>
-To have a closer result, replace Matlab <emphasis role="bold">conv(A)</emphasis> by <emphasis role="bold">clean(convol(A))</emphasis> in Scilab.
-</para>
-  </refsection>
 </refentry>
diff --git a/scilab/modules/m2sci/help/en_US/m2sci_equivalents/c/conv2.xml b/scilab/modules/m2sci/help/en_US/m2sci_equivalents/c/conv2.xml
new file mode 100644 (file)
index 0000000..8c16b7b
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ * 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
+ *
+ -->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="m2sci_conv2">
+  <refnamediv>
+    <refname>conv2 (Matlab function)</refname>
+    <refpurpose>2-D Convolution</refpurpose>
+  </refnamediv>
+  <refsection>
+    <title>Matlab/Scilab equivalent</title>
+    <informaltable border="1" width="100%">
+      <tr>
+        <td align="center">
+          <emphasis role="bold">Matlab</emphasis>
+        </td>
+        <td align="center">
+          <emphasis role="bold">Scilab</emphasis>
+        </td>
+      </tr>
+      <tr>
+        <td>
+          <programlisting role="example"><![CDATA[
+conv2
+]]></programlisting>
+        </td>
+        <td>
+          <programlisting role="example"><![CDATA[
+conv2
+]]></programlisting>
+        </td>
+      </tr>
+    </informaltable>
+  </refsection>
+</refentry>
index cbd3e2c..63ffd55 100644 (file)
@@ -14,24 +14,23 @@ function [tree]=sci_conv(tree)
 // Ouput: tree = Scilab equivalent for tree
 // Emulation function: mtlb_conv()
 
-[A,B]=getrhs(tree)
-
-if and([A.dims(1),B.dims(1)]==1) | and([A.dims(2),B.dims(2)]>1) then // A and B row vectors
-  conv=tree
-  conv.name="convol"
-  tree.name="clean"
-  tree.rhs=list(conv)
-  tree.lhs(1).type=Type(Double,Unknown)
-elseif A.dims(1)>1 | A.dims(2)==1 | B.dims(1)>1 | B.dims(2)==1 then // A and/or B is a column vector
-  conv=tree
-  conv.name="convol"
-  tree.name="clean"
-  tree.rhs=list(conv)
-  tree=Operation(".''",list(tree),tree.lhs)
-  tree.out(1).type=Type(Double,Unknown)
-else
-  tree.name="mtlb_conv"
-  tree.lhs(1).type=Type(Double,Unknown)
-end
-
+  if rhs==2 then // conv(u,v)
+    [A,B]=getrhs(tree) // conv(u,v)
+  elseif rhs==3 then 
+    [A,B,shape]=getrhs(tree)
+  end
+  if is_real(A)&is_real(B) then 
+    tree.lhs(1).type=Type(Double,Real)
+  elseif is_complex(A)|is_complex(B) then 
+    tree.lhs(1).type=Type(Double,Complex)
+  else
+    tree.lhs(1).type=Type(Double,Unknown)
+  end
+  if and([A.dims(1),B.dims(1)]==1)|(A.dims(2)==SupToOne&B.dims(2)==SupToOne)|(A.dims(2)>1&B.dims(2)>1) then  //A and B row vectors
+    tree.lhs(1).dims=list(1,Unknown)
+  elseif and([A.dims(2),B.dims(2)]==1)|(A.dims(1)==SupToOne&B.dims(1)==SupToOne)|(A.dims(1)>1&B.dims(1)>1) then // A and B column vectors
+    tree.lhs(1).dims=list(Unknown,1)
+  else
+    tree.lhs(1).dims=list(Unknown,Unknown)
+  end
 endfunction
diff --git a/scilab/modules/m2sci/macros/sci_files/sci_conv2.sci b/scilab/modules/m2sci/macros/sci_files/sci_conv2.sci
new file mode 100644 (file)
index 0000000..62f336a
--- /dev/null
@@ -0,0 +1,65 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2002-2004 - INRIA - Vincent COUVERT 
+// 
+// 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 [tree]=sci_conv2(tree)
+// M2SCI function
+// Conversion function for Matlab conv2()
+// Input: tree = Matlab funcall tree
+// Ouput: tree = Scilab equivalent for tree
+
+  if rhs==2 then // conv2(A,B)
+    [A,B]=getrhs(tree) 
+    A=convert2double(A) 
+    B=convert2double(B) 
+    if is_real(A)&is_real(B) then 
+      tree.lhs(1).type=Type(Double,Real)
+    elseif is_complex(A)|is_complex(B) then 
+      tree.lhs(1).type=Type(Double,Complex)
+    else
+      tree.lhs(1).type=Type(Double,Unknown)
+    end
+  elseif rhs==3 then 
+    [A,B,C]=getrhs(tree)
+    if C.type==String then // conv(A,B,frame)
+      A=convert2double(A) 
+      B=convert2double(B) 
+      if is_real(A)&is_real(B) then 
+        tree.lhs(1).type=Type(Double,Real)
+      elseif  is_complex(A)|is_complex(B) then 
+        tree.lhs(1).type=Type(Double,Complex)
+      else
+        tree.lhs(1).type=Type(Double,Unknown)
+      end
+    else // conv(u,v,B)
+      A=convert2double(A) 
+      B=convert2double(B) 
+      C=convert2double(C) 
+      if is_real(A)&is_real(B)&is_real(C) then 
+        tree.lhs(1).type=Type(Double,Real)
+      elseif is_complex(A)|is_complex(B)|is_complex(C) then 
+        tree.lhs(1).type=Type(Double,Complex)
+      else
+        tree.lhs(1).type=Type(Double,Unknown)
+      end
+    end
+  elseif rhs==4 then  // conv(u,v,B, frame)
+    [A,B,C,D]=getrhs(tree)
+    A=convert2double(A) 
+    B=convert2double(B) 
+    C=convert2double(C) 
+    if is_real(A)&is_real(B)&is_real(C) then 
+      tree.lhs(1).type=Type(Double,Real)
+    elseif is_complex(A)|is_complex(B)|is_complex(C) then 
+      tree.lhs(1).type=Type(Double,Complex)
+    else
+      tree.lhs(1).type=Type(Double,Unknown)
+    end
+  end
+  tree.lhs(1).dims=list(Unknown,Unknown);
+endfunction
index adf83ee..35d39ba 100644 (file)
@@ -3,7 +3,8 @@
 #
 # This file is distributed under the same license as the Scilab package.
 
-SIGNAL_PROCESSING_C_SOURCES = src/c/corrtable.c
+SIGNAL_PROCESSING_C_SOURCES = src/c/corrtable.c \
+src/c/conv2.c
 
 SIGNAL_PROCESSING_FORTRAN_SOURCES = src/fortran/degree.f \
 src/fortran/parcha.f \
@@ -77,7 +78,8 @@ sci_gateway/c/sci_amell.c \
 sci_gateway/c/gw_signal.c \
 sci_gateway/c/sci_delip.c \
 sci_gateway/c/sci_fft.c \
-sci_gateway/c/sci_syredi.c
+sci_gateway/c/sci_syredi.c \
+sci_gateway/c/sci_conv2.c
 
 GATEWAY_FORTRAN_SOURCES =  sci_gateway/fortran/sci_f_delip.f \
 sci_gateway/fortran/sci_f_fft.f \
@@ -92,6 +94,7 @@ sci_gateway/fortran/bgety.f \
 sci_gateway/fortran/Ex-corr.f
 
 libscisignal_processing_la_CFLAGS = -I$(srcdir)/includes/ \
+-I$(srcdir)/src/c/ \
 -I$(top_srcdir)/modules/api_scilab/includes \
 -I$(top_srcdir)/modules/output_stream/includes \
 -I$(top_srcdir)/modules/dynamic_link/includes
index 6966fe6..964c96e 100644 (file)
@@ -121,7 +121,8 @@ am__objects_1 = degree.lo parcha.lo ouch.lo dfftbi.lo dsqrtc.lo \
        trbipo.lo rpem.lo dfft2.lo dgee01.lo romeg.lo snell.lo \
        fft842.lo tg02ad.lo remez.lo poles.lo desi00.lo desi21.lo \
        dfftmx.lo
-am__objects_2 = libscisignal_processing_algo_la-corrtable.lo
+am__objects_2 = libscisignal_processing_algo_la-corrtable.lo \
+       libscisignal_processing_algo_la-conv2.lo
 am_libscisignal_processing_algo_la_OBJECTS = $(am__objects_1) \
        $(am__objects_2)
 libscisignal_processing_algo_la_OBJECTS =  \
@@ -137,7 +138,8 @@ am__objects_3 = libscisignal_processing_la-sci_remez.lo \
        libscisignal_processing_la-gw_signal.lo \
        libscisignal_processing_la-sci_delip.lo \
        libscisignal_processing_la-sci_fft.lo \
-       libscisignal_processing_la-sci_syredi.lo
+       libscisignal_processing_la-sci_syredi.lo \
+       libscisignal_processing_la-sci_conv2.lo
 am__objects_4 = sci_f_delip.lo sci_f_fft.lo sci_f_syredi.lo \
        sci_f_remez.lo sci_f_rpem.lo sci_f_corr.lo sci_f_fiir.lo \
        sci_f_amell.lo bgetx.lo bgety.lo Ex-corr.lo
@@ -429,7 +431,9 @@ target_alias = @target_alias@
 top_build_prefix = @top_build_prefix@
 top_builddir = @top_builddir@
 top_srcdir = @top_srcdir@
-SIGNAL_PROCESSING_C_SOURCES = src/c/corrtable.c
+SIGNAL_PROCESSING_C_SOURCES = src/c/corrtable.c \
+src/c/conv2.c
+
 SIGNAL_PROCESSING_FORTRAN_SOURCES = src/fortran/degree.f \
 src/fortran/parcha.f \
 src/fortran/ouch.f \
@@ -502,7 +506,8 @@ sci_gateway/c/sci_amell.c \
 sci_gateway/c/gw_signal.c \
 sci_gateway/c/sci_delip.c \
 sci_gateway/c/sci_fft.c \
-sci_gateway/c/sci_syredi.c
+sci_gateway/c/sci_syredi.c \
+sci_gateway/c/sci_conv2.c
 
 GATEWAY_FORTRAN_SOURCES = sci_gateway/fortran/sci_f_delip.f \
 sci_gateway/fortran/sci_f_fft.f \
@@ -517,6 +522,7 @@ sci_gateway/fortran/bgety.f \
 sci_gateway/fortran/Ex-corr.f
 
 libscisignal_processing_la_CFLAGS = -I$(srcdir)/includes/ \
+-I$(srcdir)/src/c/ \
 -I$(top_srcdir)/modules/api_scilab/includes \
 -I$(top_srcdir)/modules/output_stream/includes \
 -I$(top_srcdir)/modules/dynamic_link/includes
@@ -695,9 +701,11 @@ mostlyclean-compile:
 distclean-compile:
        -rm -f *.tab.c
 
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscisignal_processing_algo_la-conv2.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscisignal_processing_algo_la-corrtable.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscisignal_processing_la-gw_signal.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscisignal_processing_la-sci_amell.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscisignal_processing_la-sci_conv2.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscisignal_processing_la-sci_corr.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscisignal_processing_la-sci_delip.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libscisignal_processing_la-sci_ffir.Plo@am__quote@
@@ -735,6 +743,13 @@ libscisignal_processing_algo_la-corrtable.lo: src/c/corrtable.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscisignal_processing_algo_la_CFLAGS) $(CFLAGS) -c -o libscisignal_processing_algo_la-corrtable.lo `test -f 'src/c/corrtable.c' || echo '$(srcdir)/'`src/c/corrtable.c
 
+libscisignal_processing_algo_la-conv2.lo: src/c/conv2.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscisignal_processing_algo_la_CFLAGS) $(CFLAGS) -MT libscisignal_processing_algo_la-conv2.lo -MD -MP -MF $(DEPDIR)/libscisignal_processing_algo_la-conv2.Tpo -c -o libscisignal_processing_algo_la-conv2.lo `test -f 'src/c/conv2.c' || echo '$(srcdir)/'`src/c/conv2.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscisignal_processing_algo_la-conv2.Tpo $(DEPDIR)/libscisignal_processing_algo_la-conv2.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='src/c/conv2.c' object='libscisignal_processing_algo_la-conv2.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscisignal_processing_algo_la_CFLAGS) $(CFLAGS) -c -o libscisignal_processing_algo_la-conv2.lo `test -f 'src/c/conv2.c' || echo '$(srcdir)/'`src/c/conv2.c
+
 libscisignal_processing_la-sci_remez.lo: sci_gateway/c/sci_remez.c
 @am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscisignal_processing_la_CFLAGS) $(CFLAGS) -MT libscisignal_processing_la-sci_remez.lo -MD -MP -MF $(DEPDIR)/libscisignal_processing_la-sci_remez.Tpo -c -o libscisignal_processing_la-sci_remez.lo `test -f 'sci_gateway/c/sci_remez.c' || echo '$(srcdir)/'`sci_gateway/c/sci_remez.c
 @am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscisignal_processing_la-sci_remez.Tpo $(DEPDIR)/libscisignal_processing_la-sci_remez.Plo
@@ -805,6 +820,13 @@ libscisignal_processing_la-sci_syredi.lo: sci_gateway/c/sci_syredi.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscisignal_processing_la_CFLAGS) $(CFLAGS) -c -o libscisignal_processing_la-sci_syredi.lo `test -f 'sci_gateway/c/sci_syredi.c' || echo '$(srcdir)/'`sci_gateway/c/sci_syredi.c
 
+libscisignal_processing_la-sci_conv2.lo: sci_gateway/c/sci_conv2.c
+@am__fastdepCC_TRUE@   $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscisignal_processing_la_CFLAGS) $(CFLAGS) -MT libscisignal_processing_la-sci_conv2.lo -MD -MP -MF $(DEPDIR)/libscisignal_processing_la-sci_conv2.Tpo -c -o libscisignal_processing_la-sci_conv2.lo `test -f 'sci_gateway/c/sci_conv2.c' || echo '$(srcdir)/'`sci_gateway/c/sci_conv2.c
+@am__fastdepCC_TRUE@   $(am__mv) $(DEPDIR)/libscisignal_processing_la-sci_conv2.Tpo $(DEPDIR)/libscisignal_processing_la-sci_conv2.Plo
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='sci_gateway/c/sci_conv2.c' object='libscisignal_processing_la-sci_conv2.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL)  --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libscisignal_processing_la_CFLAGS) $(CFLAGS) -c -o libscisignal_processing_la-sci_conv2.lo `test -f 'sci_gateway/c/sci_conv2.c' || echo '$(srcdir)/'`sci_gateway/c/sci_conv2.c
+
 .f.o:
        $(F77COMPILE) -c -o $@ $<
 
diff --git a/scilab/modules/signal_processing/demos/conv.dem.sce b/scilab/modules/signal_processing/demos/conv.dem.sce
new file mode 100644 (file)
index 0000000..3075996
--- /dev/null
@@ -0,0 +1,40 @@
+// 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 demo_conv()
+
+//create a signal
+  dt=0.02;
+  t=0:dt:1;
+  f=1;// frequency in Hertz
+  y=sin(2*%pi*f*t)+0.1*rand(t);
+  scf(1000);clf;
+  demo_viewCode('conv.dem.sce');
+  drawlater()
+  
+  subplot(211)
+  plot(t,y) //given signal
+  //low pass 8 points wfir filter
+  smooth=[0.1197912,0.1242239,0.1272323,0.1287527,0.1287527,0.1272323,0.1242239,0.1197912];
+  ys=conv(y,smooth,'same');
+  plot(t,ys,'r')// filtered signal
+  legend([_("given noisy signal"),_("filtered signal")])
+  title(_("Signal"))
+  
+  subplot(212)
+  //2 points derivative using convolution
+  plot(t(1:$-1),conv(ys,[1,-1],'valid')/dt,'r')
+  //3 points derivative  using convolution
+  plot(t(1:$-2),conv(ys,[1, 0,-1]/2,'valid')/dt,'g')
+  legend([_("2 points convolution"),_("3 points convolution")])
+  title(_("Signal derivative estimate"))
+  drawnow()
+endfunction
+demo_conv()
+clear demo_conv
diff --git a/scilab/modules/signal_processing/demos/conv2.dem.sce b/scilab/modules/signal_processing/demos/conv2.dem.sce
new file mode 100644 (file)
index 0000000..cc18bf0
--- /dev/null
@@ -0,0 +1,43 @@
+// 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 demo_conv2()
+  //blur filter example
+  function H=gaussian2d(radius,sigma)
+    x=linspace(-1,1,10)*radius
+    H=exp(-(ones(x')*x^2+(x')^2*ones(x))/(2*sigma^2))/(2*%pi*sigma^2);
+  endfunction
+
+  load(get_absolute_file_path("conv2.dem.sce")+"image.dat")
+
+  f=scf(1000);clf;
+  f.axes_size=[800 400];
+  demo_viewCode('conv2.dem.sce');
+
+  f.color_map=graycolormap(128);
+  drawlater()
+  subplot(121)
+  Matplot(I*128);
+  a=gca();a.margins=[0 0 0.125 0];
+  a.tight_limits='on';
+  a.axes_visible='off';
+  title('Original image')
+
+  subplot(122)
+  I1=conv2(I,gaussian2d(3,0.84),"same");
+  I1=I1*128/max(I1);
+   Matplot(I1);
+  a=gca();a.margins=[0 0 0.125 0]
+  a.tight_limits='on';
+  a.axes_visible='off';
+  title('Blured  image')
+  drawnow()
+endfunction
+demo_conv2()
+clear demo_conv2
diff --git a/scilab/modules/signal_processing/demos/image.dat b/scilab/modules/signal_processing/demos/image.dat
new file mode 100644 (file)
index 0000000..b730a30
Binary files /dev/null and b/scilab/modules/signal_processing/demos/image.dat differ
index c06974a..72f0ecf 100644 (file)
@@ -10,19 +10,21 @@ function subdemolist = demo_gateway()
   add_demo(gettext("Signal Processing"), demopath + "signal_processing.dem.gateway.sce");
 
   subdemolist = [_("Spectral Estimation")               , "spect.dem.sce"
-               _("IIR filter design")                 , "iir.dem.sce"
-               _("Minimax FIR filter design")         , "remezfilt.dem.sce"
-               _("Discrete IIR filter")               , "iirfilt.dem.sce"
-               _("Wiegner filter")                    , "wiener.dem.sce"
-               _("Bode plots")                        , "bode.dem.sce"
-               _("Window FIR filters")                , "winfilt.dem.sce"
-               _("Arma simulation and identification"), "arma/arma1.dem.sce"
-               _("Arma, bidimensional version")       , "arma/arma2.dem.sce"
-               _("Arma, Spectral power estimation")   , "arma/arma3.dem.sce"];
+                 _("IIR filter design")                 , "iir.dem.sce"
+                 _("Minimax FIR filter design")         , "remezfilt.dem.sce"
+                 _("Discrete IIR filter")               , "iirfilt.dem.sce"
+                 _("Wiegner filter")                    , "wiener.dem.sce"
+                 _("Bode plots")                        , "bode.dem.sce"
+                 _("Window FIR filters")                , "winfilt.dem.sce"
+                 _("1-D convolution")                   , "conv.dem.sce"
+                 _("2-D convolution")                   , "conv2.dem.sce"
+                 _("Arma simulation and identification"), "arma/arma1.dem.sce"
+                 _("Arma, bidimensional version")       , "arma/arma2.dem.sce"
+                 _("Arma, Spectral power estimation")   , "arma/arma3.dem.sce"];
 
   subdemolist(:,2) = demopath + subdemolist(:,2);
 
 endfunction
 
 subdemolist = demo_gateway();
-clear demo_gateway;
\ No newline at end of file
+clear demo_gateway;
diff --git a/scilab/modules/signal_processing/help/en_US/conv.xml b/scilab/modules/signal_processing/help/en_US/conv.xml
new file mode 100644 (file)
index 0000000..3f1c924
--- /dev/null
@@ -0,0 +1,140 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Add some comments about XML file
+-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en_US" xml:id="conv">
+  <info>
+    <pubdate>$LastChangedDate: 30-12-2011 $</pubdate>
+  </info>
+  <refnamediv>
+    <refname>conv</refname>
+    <refpurpose>discrete 1-D convolution. </refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>C = conv(A,B [,shape])</synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Parameters</title>
+    <variablelist>
+      <varlistentry>
+        <term>A</term>
+        <listitem>
+          <para>
+            a real or complex vector.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>B</term>
+        <listitem>
+          <para>
+            a real or complex vector.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>shape</term>
+        <listitem>
+          <para>
+            an optional character string with possible values:
+          </para>
+          <itemizedlist>
+            <listitem><literal>"full"</literal>, <literal>conv</literal>
+              computes the full convolution. It is the
+              default value.
+            </listitem>
+            <listitem><literal>"same"</literal>, <literal>conv</literal>
+              computes the central part of the convolution of the same
+              size as <literal>A</literal>.
+            </listitem>
+            <listitem><literal>"valid"</literal>, <literal>conv</literal>
+              computes the convolution parts without the zero-padding
+              of <literal>A</literal>.
+            </listitem>
+          </itemizedlist>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>C</term>
+        <listitem>
+          <para>
+            a real or complex vector.
+          </para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Description</title>
+    <para><literal>conv</literal> uses a straightforward formal
+       implementation of the one-dimensional convolution equation in
+       spatial form.
+    </para>
+    <para><literal>C=conv(A,B [,shape])</literal> computes the
+      one-dimensional convolution of the vectors <literal>A</literal>
+    and <literal>B</literal>:</para>
+    <itemizedlist>
+      <listitem> With <literal>shape=="full"</literal> the
+      dimensions of the result<literal>C</literal> are given by
+      <literal>size(A,'*')+size(B,'*')+1</literal>. The indices of the
+      center element of <literal>B</literal> are defined as
+      <literal>floor((size(B,'*')+1)/2)</literal>.
+      </listitem>
+      <listitem> With <literal>shape=="same"</literal> the
+      dimensions of the result<literal>C</literal> are given by
+      <literal>size(A)</literal>. The indices of the
+      center element of <literal>B</literal> are defined as
+      <literal>floor((size(B,'*')+1)/2)</literal>.
+      </listitem>
+      <listitem> With <literal>shape=="valid"</literal> the dimensions
+      of the result <literal>C</literal> are given by
+      <literal>size(A,'*')-size(B,'*')+1)</literal> if
+      <literal>and(size(A,'*')-size(B,'*'))&gt;=0</literal> else
+      <literal>C</literal> is empty . The indices of the center
+      element of <literal>B</literal> are defined as
+      <literal>1</literal>.
+      </listitem>
+    </itemizedlist>
+  </refsection>
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+        A=1:10;
+        B=[1 -1];
+        conv(A,B)
+    ]]></programlisting>
+  </refsection>
+  <refsection>
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="convol">convol</link>
+      </member>
+      <member>
+        <link linkend="conv2">conv2</link>
+      </member>
+    </simplelist>
+  </refsection>
+  <refsection>
+    <title>Authors</title>
+    <simplelist type="vert">
+      <member>Serge Steer, INRIA</member>
+    </simplelist>
+  </refsection>
+  <refsection>
+    <title>Used Functions</title>
+    <para>
+         The conv function is based on the  <link linkend="conv2">conv2</link> builtin.
+       </para>
+  </refsection>
+  <refsection>
+    <title>History</title>
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+        <revremark>Function conv introduced.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/signal_processing/help/en_US/conv2.xml b/scilab/modules/signal_processing/help/en_US/conv2.xml
new file mode 100644 (file)
index 0000000..3962809
--- /dev/null
@@ -0,0 +1,149 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Add some comments about XML file
+-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en_US" xml:id="conv2">
+  <info>
+    <pubdate>$LastChangedDate: 29-12-2011 $</pubdate>
+  </info>
+  <refnamediv>
+    <refname>conv2</refname>
+    <refpurpose>discrete 2-D convolution. </refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>
+    C = conv2(A,B [,shape])
+    C = conv2(hrow,hcol,B [,shape])
+    </synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Parameters</title>
+    <variablelist>
+      <varlistentry>
+        <term>hrow</term>
+        <listitem>
+          <para>
+            a real or complex vector.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>hcol</term>
+        <listitem>
+          <para>
+            a real or complex vector.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>A</term>
+        <listitem>
+          <para>
+            a real or complex 2-D array.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>B</term>
+        <listitem>
+          <para>
+            a real or complex 2-D array.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>shape</term>
+        <listitem>
+          <para>
+            an optional character string with possible values:
+          </para>
+          <itemizedlist>
+            <listitem><literal>"full"</literal>, <literal>conv2</literal>
+              computes the full two-dimensional convolution. It is the
+              default value.
+            </listitem>
+            <listitem><literal>"same"</literal>, <literal>conv2</literal>
+              computes the central part of the convolution of the same
+              size as <literal>A</literal>.
+            </listitem>
+            <listitem><literal>"valid"</literal>, <literal>conv2</literal>
+              computes the convolution parts without the zero-padding of <literal>A</literal>. 
+            </listitem>
+          </itemizedlist>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>C</term>
+        <listitem>
+          <para>
+            a real or complex 2-D array.
+          </para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection><title>Description</title><para><literal>conv2</literal> uses a straightforward formal
+       implementation of the two-dimensional convolution equation in
+       spatial form.
+    </para><para><literal>C=conv2(A,B [,shape])</literal> computes the
+      two-dimensional convolution of the arrays <literal>A</literal>
+    and <literal>B</literal>:</para><itemizedlist><listitem> With <literal>shape=="full"</literal> the
+      dimensions of the result<literal>C</literal> are given by
+      <literal>size(A)+size(B)+1</literal>. The indices of the
+      center element of <literal>B</literal> are defined as
+      <literal>floor((size(B)+1)/2)</literal>.
+      </listitem><listitem> With <literal>shape=="same"</literal> the
+      dimensions of the result<literal>C</literal> are given by
+      <literal>size(A)</literal>. The indices of the
+      center element of <literal>B</literal> are defined as
+      <literal>floor((size(B)+1)/2)</literal>.
+      </listitem><listitem> With <literal>shape=="valid"</literal> the dimensions
+      of the result <literal>C</literal> are given by
+      <literal>size(A)-size(B)+1)</literal> if
+      <literal>and(size(A)-size(B))&gt;=0</literal> else
+      <literal>C</literal> is empty . The indices of the center
+      element of <literal>B</literal> are defined as
+      <literal>[1 1]</literal>.
+      </listitem></itemizedlist><para>
+      The separable form <literal>C=conv2(hrow,hcol,B [,shape])</literal>is equivalent to <literal>C=conv2(hrow(:)*hcol(:).',B [,shape])</literal></para>.
+  </refsection>
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    s = [1 2 1; 0 0 0; -1 -2 -1];//Sobel horizontal edge kernel
+    A = zeros(10,10);A(3:7,3:7) = 1;
+    conv2(s,A);
+
+    //separable form 
+    u=[1;0;-1];v=[1 2 1];// u*v=s
+    conv2(u,v,A)
+    ]]></programlisting>
+  </refsection>
+  <refsection>
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="convol2d">convol2d</link>
+      </member>
+      <member>
+        <link linkend="conv">conv</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>Function conv2 introduced.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
diff --git a/scilab/modules/signal_processing/help/en_US/convol2d.xml b/scilab/modules/signal_processing/help/en_US/convol2d.xml
new file mode 100644 (file)
index 0000000..0e0dd09
--- /dev/null
@@ -0,0 +1,96 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Add some comments about XML file
+-->
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:lang="en_US" xml:id="convol2d">
+  <info>
+    <pubdate>$LastChangedDate: 30-12-2011 $</pubdate>
+  </info>
+  <refnamediv>
+    <refname>convol2d</refname>
+    <refpurpose>discrete 2-D convolution, using fft. </refpurpose>
+  </refnamediv>
+  <refsynopsisdiv>
+    <title>Calling Sequence</title>
+    <synopsis>C = convol2d(A,B)</synopsis>
+  </refsynopsisdiv>
+  <refsection>
+    <title>Parameters</title>
+    <variablelist>
+      <varlistentry>
+        <term>A</term>
+        <listitem>
+          <para>
+            a real or complex 2-D array.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>B</term>
+        <listitem>
+          <para>
+            a real or complex 2-D array.
+          </para>
+        </listitem>
+      </varlistentry>
+      <varlistentry>
+        <term>C</term>
+        <listitem>
+          <para>
+            a real or complex 2-D array.
+          </para>
+        </listitem>
+      </varlistentry>
+    </variablelist>
+  </refsection>
+  <refsection>
+    <title>Description</title>
+    <para><literal>convol2d</literal> uses fft to compute the full
+       two-dimensional discrete convolution. The
+      dimensions of the result<literal>C</literal> are given by
+      <literal>size(A)+size(B)+1</literal>. The indices of the
+      center element of <literal>B</literal> are defined as
+      <literal>floor((size(B)+1)/2)</literal>.
+    </para>
+  </refsection>
+  <refsection>
+    <title>Examples</title>
+    <programlisting role="example"><![CDATA[
+    s = [1 2 1; 0 0 0; -1 -2 -1];//Sobel horizontal edge kernel
+    A = zeros(10,10);A(3:7,3:7) = 1;
+    convol2d(s,A);
+    ]]></programlisting>
+  </refsection>
+  <refsection>
+    <title>See Also</title>
+    <simplelist type="inline">
+      <member>
+        <link linkend="conv2">conv2</link>
+      </member>
+      <member>
+        <link linkend="convol">convol</link>
+      </member>
+    </simplelist>
+  </refsection>
+  <refsection>
+    <title>Authors</title>
+    <simplelist type="vert">
+      <member>Serge Steer, INRIA</member>
+    </simplelist>
+  </refsection>
+  <refsection>
+    <title>Used Functions</title>
+    <para>
+         The  <literal>convol2d</literal> function is based on the <link linkend="fft">fft</link> builtin.
+       </para>
+  </refsection>
+  <refsection>
+    <title>History</title>
+    <revhistory>
+      <revision>
+        <revnumber>5.4.0</revnumber>
+        <revremark>Function convol2d introduced.</revremark>
+      </revision>
+    </revhistory>
+  </refsection>
+</refentry>
index 56d1ad7..0c1298d 100644 (file)
@@ -27,6 +27,7 @@ SIGNAL_PROCESSING_IMPEXP int C2F(sci_amell)(char *fname,unsigned long fname_len)
 SIGNAL_PROCESSING_IMPEXP int C2F(sci_delip)(char *fname,unsigned long fname_len);
 SIGNAL_PROCESSING_IMPEXP int C2F(sci_remez)(char *fname,unsigned long fname_len);
 SIGNAL_PROCESSING_IMPEXP int C2F(sci_syredi)(char *fname,unsigned long fname_len);
+SIGNAL_PROCESSING_IMPEXP int sci_conv2(char *fname,unsigned long fname_len);
 
 #endif /*  __GW_SIGNAL__ */
 /*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/signal_processing/macros/conv.sci b/scilab/modules/signal_processing/macros/conv.sci
new file mode 100644 (file)
index 0000000..ab6e612
--- /dev/null
@@ -0,0 +1,34 @@
+// 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 h=conv(u,v,shape)
+  if and(size(u)>1) then
+    error( msprintf(_("%s: Wrong size for argument #%d: Vector expected.\n"),"conv",1))
+  end
+  if and(size(v)>1) then
+        error( msprintf(_("%s: Wrong size for argument #%d: Vector expected.\n"),"conv",2))
+  end
+  if argn(2)==2 then 
+    shape='full',
+  elseif and(shape<>["full","same","valid"]) then
+    error(msprintf(_("%s: Wrong value for input argument #%d: ""%s"" or ""%s"" expected.\n"),"conv",3, """full"", ""same""","""valid"""));
+  end
+  h=conv2(u(:),v(:),shape);
+  //set result orientation
+  if shape=="full" then
+    if size(u,'*')>size(v,'*') then
+      if size(u,1)==1 then h=matrix(h,1,-1);end
+    else
+      if size(v,1)==1 then h=matrix(h,1,-1);end
+    end
+  else
+    if size(u,1)==1 then h=matrix(h,1,-1);end
+  end
+endfunction
+
diff --git a/scilab/modules/signal_processing/macros/convol2d.sci b/scilab/modules/signal_processing/macros/convol2d.sci
new file mode 100644 (file)
index 0000000..1cd5c43
--- /dev/null
@@ -0,0 +1,56 @@
+// 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 y=convol2d(h,x)
+//  convol2d - 2-D convolution 
+//%CALLING SEQUENCE
+//  y=convol2d(h,x)
+//%PARAMETERS
+//  x,h       :input matrices 
+//  y         : output of convolution
+//%DESCRIPTION
+//  calculates the 2-D convolution y= h*x of two discrete sequences by 
+//  using the fft. 
+  if argn(2)<2 then
+     error(msprintf(_("%s: Wrong number of input arguments: %d expected.\n"),"convol2d",2))
+  end
+  
+  if type(h)<>1 then
+    error(msprintf(_("%s: Wrong type for argument %d: Real or complex matrix expected.\n"),"convol2d",1))
+  end
+  if type(x)<>1 then
+    error(msprintf(_("%s: Wrong type for argument %d: Real or complex matrix expected.\n"),"convol2d",2))
+  end
+  if isempty(h) then
+    y=zeros(x);
+    return
+  end
+  if isempty(x) then
+    y=zeros(h);
+    return
+  end
+  //inline fft2d function definition (fft2 does not manage inverse fft)
+  function y=fft2d(x,d)
+    [mx,nx]=size(x)
+    y=fft(fft(x,d,mx,1),d,nx,mx)
+  endfunction
+  [mx,nx]=size(x);
+  [mh,nh]=size(h);
+  //use  power of 2 dimensions for efficiency
+  m1=2^(int(log(mx+mh-1)/log(2))+1);
+  n1=2^(int(log(nx+nh-1)/log(2))+1);
+  //m1=mx+mh-1;
+  //n1=nx+nh-1;
+  x(m1,n1)=0;
+  h(m1,n1)=0;
+  y=fft2d(fft2d(x,-1).*fft2d(h,-1),1);
+  if isreal(h,0)&isreal(x,0) then
+    y=real(y);
+  end
+  y=y(1:(mx+mh-1),1:(nx+nh-1)); 
+endfunction
index 5133929..53967ff 100644 (file)
@@ -24,7 +24,9 @@ static gw_generic_table Tab[]=
        {C2F(sci_amell),"amell"},
        {C2F(sci_delip),"delip"},
        {C2F(sci_remez),"remez"},
-       {C2F(sci_syredi),"syredi"}
+       {C2F(sci_syredi),"syredi"},
+       {sci_conv2,"conv2"}
+
 };
 /*--------------------------------------------------------------------------*/
 int gw_signal_processing(void)
diff --git a/scilab/modules/signal_processing/sci_gateway/c/sci_conv2.c b/scilab/modules/signal_processing/sci_gateway/c/sci_conv2.c
new file mode 100644 (file)
index 0000000..743632e
--- /dev/null
@@ -0,0 +1,496 @@
+/*
+ * 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
+ *
+ */
+/*--------------------------------------------------------------------------*/
+#include "core_math.h"
+#include "stack-c.h"
+#include "gw_signal.h"
+#include "MALLOC.h"
+#include "api_scilab.h"
+#include "localization.h"
+#include "Scierror.h"
+#include "conv2.h"
+/*--------------------------------------------------------------------------*/
+int sci_conv2(char *fname,unsigned long fname_len)
+{
+    SciErr sciErr;
+    int *piAddr = NULL;
+    char *option = NULL;
+    int iopt = 1;
+    double *Outr = NULL,*Outi = NULL;
+    int mOut = 0, nOut = 0;
+    int iType = 0;
+    int edgM = 0, edgN = 0;
+    int rhs = Rhs;
+
+    /* Check if last argument is one of the string "full", "same","valid" */
+    sciErr = getVarAddressFromPosition(pvApiCtx, Rhs, &piAddr);
+    if(sciErr.iErr)
+    {
+        printError(&sciErr, 0);
+        return 0;
+    }
+
+    if (isStringType(pvApiCtx, piAddr)) 
+    {
+        CheckRhs(3,4);
+        if(isScalar(pvApiCtx, piAddr)) 
+        {
+            if (getAllocatedSingleString(pvApiCtx, piAddr, &option)==0) 
+            {
+                if (strcmp("full", option) == 0) 
+                {
+                    iopt=1;
+                }
+                else if (strcmp("same", option) == 0) 
+                {
+                    iopt=2;
+                }
+                else if (strcmp("valid", option) == 0) 
+                {
+                    iopt=3;
+                }
+                else 
+                {
+                    Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), 
+                        fname, Rhs, "\"full\", \"same\"","\"valid\"");
+                    freeAllocatedSingleString(option);
+                    option = NULL;
+                    return 0;
+                }
+                freeAllocatedSingleString(option);
+                option = NULL;
+                rhs=Rhs-1;
+            }
+            else 
+            {
+                Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"), 
+                    fname, Rhs, "\"full\", \"same\"","\"valid\"");
+                return 0;
+            }
+        }
+    }
+    else 
+    {
+        CheckRhs(2,3); 
+    }
+
+    if (rhs==3) 
+    { 
+        /*separable conv2(C,R,A)*/
+        double *Cr = NULL,*Ci = NULL;
+        double *Rr = NULL,*Ri = NULL;
+        double *Ar = NULL,*Ai = NULL;
+        int mC = 0, nC = 0, mR = 0, nR = 0, mA = 0, nA = 0;
+
+        /* get and check C */
+        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        //check type
+        sciErr = getVarType(pvApiCtx, piAddr, &iType);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        if(iType != sci_matrix)
+        {
+            Scierror(999,_("%s: Wrong type for argument %d: Real vector expected.\n"), 
+                fname, 1);
+            return 0;
+        }
+
+        //get complexity
+        if (isVarComplex(pvApiCtx, piAddr)) 
+        {
+            sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mC, &nC, &Cr, &Ci);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+        else 
+        {
+            sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mC, &nC, &Cr);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+        if (mC>1 && nC>1) 
+        { 
+            /*check if vector*/
+            Scierror(999,_("%s: Wrong type for argument %d: Real or complex vector expected.\n"), 
+                fname, 1);
+            return 0;
+        }
+        mC = mC*nC;
+
+        /* get and check R */
+        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        //check type
+        sciErr = getVarType(pvApiCtx, piAddr, &iType);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        if(iType != sci_matrix)
+        {
+            Scierror(999,_("%s: Wrong type for argument %d: Real or complex vector expected.\n"), 
+                fname, 2);
+            return 0;
+        }
+
+        //get complexity
+        if (isVarComplex(pvApiCtx, piAddr)) 
+        {
+            sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mR, &nR, &Rr, &Ri);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+        else 
+        {
+            sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mR, &nR, &Rr);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+
+        if (mR>1 && nR>1) 
+        { 
+            /*check if vector*/
+            Scierror(999,_("%s: Wrong type for argument %d: Real vector expected.\n"), 
+                fname, 2);
+            return 0;
+        }
+
+        nR = nR*mR;
+        /* get and check A */
+        sciErr = getVarAddressFromPosition(pvApiCtx, 3, &piAddr);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        //check type
+        sciErr = getVarType(pvApiCtx, piAddr, &iType);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        if(iType != sci_matrix)
+        {
+            Scierror(999,_("%s: Wrong type for argument %d: Real or complex matrix expected.\n"), 
+                fname, 3);
+            return 0;
+        }
+
+        //get complexity
+        if (isVarComplex(pvApiCtx, piAddr)) 
+        {
+            sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mA, &nA, &Ar, &Ai);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+        else 
+        {
+            sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mA, &nA, &Ar);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+
+        //Compute result sizes
+        if (iopt == 1 ) 
+        {
+            if (mC==0||nR==0) 
+            {
+                mOut= mA;
+                nOut= nA;
+            }
+            else 
+            {
+                mOut= mA + mC - 1;
+                nOut= nA + nR - 1;
+            }
+            edgM= mC - 1;
+            edgN= nR - 1;
+        } 
+        else if ( iopt == 2 ) 
+        {
+            mOut= mA;
+            nOut= nA;
+            edgM= ( mC - 1) /2;
+            edgN= ( nR - 1) /2;
+        }
+        else if (iopt==3) 
+        {
+            if (mC==0||nR==0) 
+            {
+                mOut= mA;
+                nOut= nA;
+            }
+            else 
+            {
+                mOut= Max(0,mA - mC + 1);
+                nOut= Max(0,nA - nR + 1);
+            }
+            edgM = edgN= 0;
+        }
+
+        if (Ri==NULL&&Ci==NULL&&Ai==NULL)
+        { 
+            //real case
+            double *Tr = NULL;
+            //Allocate result
+            sciErr = allocMatrixOfDouble(pvApiCtx,Rhs+1,mOut,nOut,&Outr);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+            sciErr = allocMatrixOfDouble(pvApiCtx,Rhs+2,1,nA,&Tr);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+            conv2_separable_R(Rr,nR,Cr,mC,Ar,mA,nA,Outr,mOut,nOut,edgM,edgN,Tr);
+        }
+        else 
+        {
+            double *Tr = NULL,*Ti = NULL;
+            //Allocate result
+            sciErr = allocComplexMatrixOfDouble(pvApiCtx,Rhs+1,mOut,nOut,&Outr,&Outi);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+            sciErr = allocComplexMatrixOfDouble(pvApiCtx,Rhs+2,1,nA,&Tr,&Ti);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+            conv2_separable_C(Rr,Ri,nR,Cr,Ci,mC,Ar,Ai,mA,nA,Outr,Outi,mOut,nOut,edgM,edgN,Tr,Ti);
+        }
+    }
+    else 
+    {
+        /*conv2(A,B)*/
+        double *Ar = NULL,*Ai = NULL;
+        double *Br = NULL,*Bi = NULL;
+        int mA,nA,mB,nB;
+
+        /* get and check A */
+        sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        //check type
+        sciErr = getVarType(pvApiCtx, piAddr, &iType);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        if(iType != sci_matrix)
+        {
+            Scierror(999,_("%s: Wrong type for argument %d: Real or complex matrix expected.\n"), 
+                fname, 1);
+            return 0;
+        }
+
+        //get complexity
+        if (isVarComplex(pvApiCtx, piAddr)) 
+        {
+            sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mA, &nA, &Ar, &Ai);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+        else 
+        {
+            sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mA, &nA, &Ar);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+
+        /* get and check B */
+        sciErr = getVarAddressFromPosition(pvApiCtx, 2, &piAddr);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        //check type
+        sciErr = getVarType(pvApiCtx, piAddr, &iType);
+        if(sciErr.iErr)
+        {
+            printError(&sciErr, 0);
+            return 0;
+        }
+
+        if(iType != sci_matrix)
+        {
+            Scierror(999,_("%s: Wrong type for argument %d: Real or complex matrix expected.\n"), 
+                fname, 2);
+            return 0;
+        }
+
+        //get complexity
+        if (isVarComplex(pvApiCtx, piAddr)) 
+        {
+            sciErr = getComplexMatrixOfDouble(pvApiCtx, piAddr, &mB, &nB, &Br, &Bi);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+        else 
+        {
+            sciErr = getMatrixOfDouble(pvApiCtx, piAddr, &mB, &nB, &Br);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+        }
+
+        if (iopt==1) 
+        {
+            if (mA==0) 
+            {
+                mOut= mB;
+                nOut= nB;
+            }
+            else if (mB ==0) 
+            {
+                mOut= mA;
+                nOut= nA;
+            }
+            else  
+            { 
+                mOut= mA + Max(0,mB - 1);
+                nOut= nA +  Max(0,nB - 1);
+            }
+            edgM= mB - 1;
+            edgN= nB - 1;
+        } 
+        else if (iopt==2) 
+        {
+            mOut= mA;
+            nOut= nA;
+            edgM= ( mB - 1) /2;
+            edgN= ( nB - 1) /2;
+        } 
+        else if (iopt==3) 
+        {
+            if (mB ==0) 
+            {
+                mOut=mA;
+                nOut=nA;
+            }
+            else 
+            {
+                mOut= Max(0,mA - mB + 1);
+                nOut= Max(0,nA - nB + 1);
+            }
+            edgM= edgN= 0;
+        } 
+
+        if (Ai==NULL&&Bi==NULL)
+        { 
+            //real case
+            //Allocate result
+            sciErr = allocMatrixOfDouble(pvApiCtx, Rhs+1,mOut,nOut,&Outr);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+            conv2_R(Ar,mA,nA,Br,mB,nB,Outr,mOut,nOut,edgM,edgN);
+        }
+        else 
+        {
+            //Allocate result
+            sciErr = allocComplexMatrixOfDouble(pvApiCtx,Rhs+1,mOut,nOut,&Outr,&Outi);
+            if(sciErr.iErr)
+            {
+                printError(&sciErr, 0);
+                return 0;
+            }
+
+            conv2_C(Ar,Ai,mA,nA,Br,Bi,mB,nB,Outr,Outi,mOut,nOut,edgM,edgN);
+        }
+    }
+
+    LhsVar(1) = Rhs+1; 
+    PutLhsVar();
+    return 0;
+}
+/*--------------------------------------------------------------------------*/
index 3978a40..3c8e98f 100644 (file)
@@ -37,4 +37,5 @@
 <PRIMITIVE gatewayId="18" primitiveId="7" primitiveName="delip" />
 <PRIMITIVE gatewayId="18" primitiveId="8" primitiveName="remez" />
 <PRIMITIVE gatewayId="18" primitiveId="9" primitiveName="syredi" />
-</GATEWAY>
\ No newline at end of file
+<PRIMITIVE gatewayId="18" primitiveId="10" primitiveName="conv2" />
+</GATEWAY>
index c712ef3..021a12d 100644 (file)
@@ -6,3 +6,7 @@ EXPORTS
 ; Libscilab
 ; --------------------------------------- 
 callFunctionFromGateway
+putlhsvar_
+intersci_
+com_
+checkrhs_
\ No newline at end of file
diff --git a/scilab/modules/signal_processing/src/c/conv2.c b/scilab/modules/signal_processing/src/c/conv2.c
new file mode 100644 (file)
index 0000000..e645927
--- /dev/null
@@ -0,0 +1,285 @@
+/*
+ * 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
+ *
+ */
+/*--------------------------------------------------------------------------*/
+#include "machine.h"
+#include "core_math.h" 
+#include "MALLOC.h"
+/*--------------------------------------------------------------------------*/
+extern double C2F(ddot)(int *n, double *A, int *iA, double *B, int *iB);
+/*--------------------------------------------------------------------------*/                     
+void conv2_separable_R(double *R,int nR,double *C,int mC,double *A,int mA,int nA,double *Out,int mOut,int nOut,int edgM,int edgN,double *T)
+{
+    int ai = 0, tj = 0, ci = 0, rj = 0; /*current index over A,T,C and R */
+    int i = 0, j = 0; /* loop variables*/
+    int l = 0;
+    int one = 1, minusone = -1;
+
+    for(i = 0; i < mOut; i++ ) 
+    {
+        /*Compute  the 1-D conv A(i,:) and C  in T */ 
+        ai= Max(0,i-edgM) ;
+        ci= mC-1-Max(0,edgM-i);
+        l=Min(ci+1,mA-ai);
+        for(j=0; j < nA; j++ ) 
+        {
+            T[j]=C2F(ddot)(&l,A+ai+mA*j,&one,C+ci-l+1,&minusone);
+        } 
+        /*1-D convolution of T and  R */
+        for(j=0; j < nOut; j++ ) 
+        {
+            rj = nR-1-Max(0,edgN-j);
+            tj = Max(0, j-edgN) ;
+            l = Min(rj+1,nA-tj);
+            Out[i+j*mOut] = C2F(ddot)(&l,T+tj,&one,R+rj-l+1,&minusone);
+        } 
+    } 
+}
+/*--------------------------------------------------------------------------*/
+void conv2_separable_C(double *Rr,double *Ri,int nR,double *Cr,double *Ci,int mC,double *Ar,double *Ai,int mA,int nA,double *Outr,double *Outi,int mOut,int nOut,int edgM,int edgN,double *Tr,double *Ti)
+{
+    int ai = 0, tj = 0, ci = 0, rj = 0; /*current index over A,T,C and R */
+    int i = 0, j = 0; /* loop variables*/
+    int l = 0;
+    int one = 1, minusone = -1;
+
+    for(i = 0; i < mOut; i++ ) 
+    {
+        /*Compute  the 1-D conv A(i,:) and C  in T */ 
+        ai = Max(0,i-edgM) ;
+        ci = mC-1-Max(0,edgM-i);
+        l = Min(ci+1,mA-ai);
+        if (Ai != NULL && Ci != NULL)
+        {
+            for(j = 0; j < nA; j++ ) 
+            {
+                Tr[j] = C2F(ddot)(&l,Ar+ai+mA*j,&one,Cr+ci-l+1,&minusone)-
+                    C2F(ddot)(&l,Ai+ai+mA*j,&one,Ci+ci-l+1,&minusone);
+
+                Ti[j] = C2F(ddot)(&l,Ar+ai+mA*j,&one,Ci+ci-l+1,&minusone)+
+                    C2F(ddot)(&l,Ai+ai+mA*j,&one,Cr+ci-l+1,&minusone);
+            } 
+        }
+        else if (Ci != NULL) 
+        {
+            for(j = 0; j < nA; j++ ) 
+            {
+                Tr[j] = C2F(ddot)(&l,Ar+ai+mA*j,&one,Cr+ci-l+1,&minusone);
+                Ti[j] = C2F(ddot)(&l,Ar+ai+mA*j,&one,Ci+ci-l+1,&minusone);
+            }
+        }
+        else if (Ai != NULL) 
+        {
+            for(j = 0; j < nA; j++ ) 
+            {
+                Tr[j] = C2F(ddot)(&l,Ar+ai+mA*j,&one,Cr+ci-l+1,&minusone);
+                Ti[j] = C2F(ddot)(&l,Ai+ai+mA*j,&one,Cr+ci-l+1,&minusone);
+            }
+        }
+        else 
+        {
+            for(j = 0; j < nA; j++ ) 
+            {
+                Tr[j] = C2F(ddot)(&l,Ar+ai+mA*j,&one,Cr+ci-l+1,&minusone);
+                Ti[j] = 0.0;
+            }
+        }
+        /*1-D convolution of T and  R */
+        for(j = 0; j < nOut; j++ ) 
+        {
+            rj = nR-1-Max(0,edgN-j);
+            tj = Max(0, j-edgN) ;
+            l = Min(rj+1,nA-tj);
+            Outr[i+j*mOut] = C2F(ddot)(&l,Tr+tj,&one,Rr+rj-l+1,&minusone);
+            Outi[i+j*mOut] = C2F(ddot)(&l,Ti+tj,&one,Rr+rj-l+1,&minusone);
+            if (Ri != NULL)
+            {
+                Outr[i+j*mOut] -= C2F(ddot)(&l,Ti+tj,&one,Ri+rj-l+1,&minusone);
+                Outi[i+j*mOut] = C2F(ddot)(&l,Tr+tj,&one,Ri+rj-l+1,&minusone);
+            } 
+        }
+    }
+}
+/*--------------------------------------------------------------------------*/
+void conv2_R(double *A,int mA,int nA,double *B,int mB,int nB,double *Out,int mOut,int nOut,int edgM,int edgN)
+{
+    int ai = 0, aj = 0, bi = 0, bj = 0; /*current index over A and B */
+    int i = 0, j = 0; /* loop variables*/
+    int l = 0;
+    int one = 1, minusone = -1;
+    double sum = 0;
+    if (nOut == 1) 
+    {
+        /* A and B are column vectors nA=nB=nOut=1 */
+        for(i=0; i < mOut; i++ ) 
+        {
+            bi = mB-1-Max(0,edgM-i);
+            ai = Max(0,i-edgM);
+            l = Min(bi+1,mA-ai);
+            Out[i] = C2F(ddot)(&l,A+ai,&one,B+bi-l+1,&minusone);
+        } 
+    }
+    else if (mOut==1) 
+    {
+        /* A and B are row vectors mA=mB=mOut=1 */
+        for(j = 0; j < nOut; j++ ) 
+        {
+            bj = nB-1-Max(0,edgN-j);
+            aj = Max(0,j-edgN);
+            l = Min(bj+1,nA-aj);
+            Out[j] = C2F(ddot)(&l,A+aj,&one,B+bj-l+1,&minusone);
+        } 
+    }
+    else 
+    { 
+        /* general array case */
+        for(i = 0; i < mOut; i++ ) 
+        {
+            bi = mB-1-Max(0,edgM-i);
+            ai = Max(0,i-edgM);
+            for(j=0; j < nOut; j++ ) 
+            {
+                sum = 0;
+                for(bj= nB-1-Max(0,edgN-j),aj= Max(0,j-edgN);bj >= 0 && aj < nA;bj--, aj++) 
+                {
+                    l = Min(bi+1,mA-ai);
+                    sum += C2F(ddot)(&l,A+ai+mA*aj,&one,B+bi-l+1+mB*bj,&minusone);
+                } 
+                Out[i+j*mOut] = sum;
+            } 
+        } 
+    }
+}
+/*--------------------------------------------------------------------------*/
+void conv2_C(double *Ar,double *Ai,int mA,int nA,double *Br,double *Bi,int mB,int nB,double *Outr,double *Outi,int mOut,int nOut,int edgM,int edgN)
+{
+    int ai = 0, aj = 0, bi = 0, bj = 0; /*current index over A and B */
+    int i = 0, j = 0; /* loop variables*/
+    int l = 0;
+    int one = 1, minusone = -1;
+    double sumr = 0, sumi = 0;
+
+    if (Bi != NULL&& Ai != NULL)  
+    {
+        if (nOut==1) 
+        { 
+            /* fastest code */
+            for(i=0; i < mOut; i++ ) 
+            {
+                bi = mB-1-Max(0,edgM-i);
+                ai = Max(0,i-edgM);
+                l = Min(bi+1,mA-ai);
+                Outr[i] = C2F(ddot)(&l,Ar+ai,&one,Br+bi-l+1,&minusone)-
+                    C2F(ddot)(&l,Ai+ai,&one,Bi+bi-l+1,&minusone);
+
+                Outi[i] = C2F(ddot)(&l,Ar+ai,&one,Bi+bi-l+1,&minusone)+
+                    C2F(ddot)(&l,Ai+ai,&one,Br+bi-l+1,&minusone);
+            } 
+        }
+        else 
+        {
+            for(i = 0; i < mOut; i++ ) 
+            {
+                bi = mB-1-Max(0,edgM-i);
+                ai = Max(0,i-edgM);
+                for (j = 0; j < nOut; j++ ) 
+                {
+                    sumr = 0;
+                    sumi = 0;
+                    for(bj = nB-1-Max(0,edgN-j),aj= Max(0,j-edgN);bj >= 0 && aj < nA;bj--, aj++) 
+                    {
+                        l = Min(bi+1,mA-ai);
+                        sumr += C2F(ddot)(&l,Ar+ai+mA*aj,&one,Br+bi-l+1+mB*bj,&minusone)
+                            -C2F(ddot)(&l,Ai+ai+mA*aj,&one,Bi+bi-l+1+mB*bj,&minusone);
+
+                        sumi += C2F(ddot)(&l,Ar+ai+mA*aj,&one,Bi+bi-l+1+mB*bj,&minusone)+
+                            C2F(ddot)(&l,Ai+ai+mA*aj,&one,Br+bi-l+1+mB*bj,&minusone);
+                    }
+                    Outr[i+j*mOut] = sumr;
+                    Outi[i+j*mOut] = sumi;
+                } 
+            } 
+        }
+    }
+    else if (Ai != NULL) 
+    { 
+        if (nOut == 1) 
+        { 
+            /* fastest code */
+            for (i = 0; i < mOut; i++ ) 
+            {
+                bi = mB-1-Max(0,edgM-i);
+                ai = Max(0,i-edgM);
+                l = Min(bi+1,mA-ai);
+                Outr[i] = C2F(ddot)(&l,Ar+ai,&one,Br+bi-l+1,&minusone);
+                Outi[i] = C2F(ddot)(&l,Ai+ai,&one,Br+bi-l+1,&minusone);
+            }
+        }
+        else 
+        {
+            for(i = 0; i < mOut; i++ ) 
+            {
+                bi = mB-1-Max(0,edgM-i);
+                ai = Max(0,i-edgM);
+                for (j = 0; j < nOut; j++ ) 
+                {
+                    sumr = 0;
+                    sumi = 0;
+                    for(bj = nB-1-Max(0,edgN-j),aj= Max(0,j-edgN);bj >= 0 && aj < nA;bj--, aj++) 
+                    {
+                        l = Min(bi+1,mA-ai);
+                        sumr += C2F(ddot)(&l,Ar+ai+mA*aj,&one,Br+bi-l+1+mB*bj,&minusone);
+                        sumi += C2F(ddot)(&l,Ai+ai+mA*aj,&one,Br+bi-l+1+mB*bj,&minusone);
+                    }
+                    Outr[i+j*mOut] = sumr;
+                    Outi[i+j*mOut] = sumi;
+                } 
+            } 
+        }
+    }
+    else if (Bi != NULL) 
+    { 
+        if (nOut==1) 
+        { 
+            /* fastest code */
+            for(i=0; i < mOut; i++ ) 
+            {
+                bi = mB-1-Max(0,edgM-i);
+                ai = Max(0,i-edgM);
+                l = Min(bi+1,mA-ai);
+                Outr[i] = C2F(ddot)(&l,Ar+ai,&one,Br+bi-l+1,&minusone);
+                Outi[i] = C2F(ddot)(&l,Ar+ai,&one,Bi+bi-l+1,&minusone);
+            } 
+        }
+        else 
+        {
+            for(i = 0; i < mOut; i++ ) 
+            {
+                bi = mB-1-Max(0,edgM-i);
+                ai = Max(0,i-edgM);
+                for (j = 0; j < nOut; j++ ) 
+                {
+                    sumr = 0;
+                    sumi = 0;
+                    for (bj = nB-1-Max(0,edgN-j),aj= Max(0,j-edgN);bj >= 0 && aj < nA;bj--, aj++) 
+                    {
+                        l = Min(bi+1, mA-ai);
+                        sumr += C2F(ddot)(&l,Ar+ai+mA*aj,&one,Br+bi-l+1+mB*bj,&minusone);
+                        sumi += C2F(ddot)(&l,Ar+ai+mA*aj,&one,Bi+bi-l+1+mB*bj,&minusone);
+                    }
+                    Outr[i+j*mOut] = sumr;
+                    Outi[i+j*mOut] = sumi;
+                } 
+            } 
+        }
+    }
+}
+/*--------------------------------------------------------------------------*/
diff --git a/scilab/modules/signal_processing/src/c/conv2.h b/scilab/modules/signal_processing/src/c/conv2.h
new file mode 100644 (file)
index 0000000..583d72a
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * 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
+ *
+ */
+/*------------------------------------------------------------------------*/
+/* file: conv2.h                                                          */
+/* desc : Functions to compute 2-D convolutions                           */
+/*------------------------------------------------------------------------*/
+#ifndef __CONV2_H__
+#define __CONV2_H__
+
+
+/**
+ * computes 2-D convolution for separable kernel in real case
+ * R is a real vector of length nR
+ * C is a real vector of length nC
+ * A is a (mA,nA) real matrix
+ * Out is a (mOut,nOut) real matrix
+ * edgM is an integer
+ * edgN is an integer
+ * T is a real vector of length nA
+ */
+void conv2_separable_R(double *R,int nR,
+                       double *C,int nC,
+                       double *A,int mA,int nA,
+                       double *Out,int mOut,int nOut,
+                       int edgM,int edgN,double *T);
+
+/**
+ * computes 2-D convolution for separable kernel in complex case
+ * Rr and Ri are real vectors of length nR
+ * Cr and Ci are real vectors of length nC
+ * Ar and Ai are (mA,nA) real matrices
+ * Outr and Outii are  (mOut,nOut) real matrices
+ * edgM is an integer
+ * edgN is an integer
+ * Tr and Ti are real vectors of length nA
+ */
+void conv2_separable_C(double *Rr,double *Ri,int nR,
+                       double *Cr,double *Ci,int nC,
+                       double *Ar,double *Ai,int mA,int nA,
+                       double *Outr,double *Outi,int mOut,int nOut,
+                       int edgM,int edgN,double *Tr,double *Ti);
+
+/**
+ * computes 2-D convolution for matrix kernel in real case
+ * A is a (mA,nA) real matrix
+ * B is a (mB,nB) real matrix
+ * Out is a (mOut,nOut) real matrix
+ * edgM is an integer
+ * edgN is an integer
+ */
+void conv2_R(double *A,int mA,int nA,
+             double *B,int mB,int nB,
+             double *Out,int mOut,int nOut,
+             int edgM,int edgN);
+
+/**
+ * computes 2-D convolution for matrix kernel in complex case
+ * Ar and Ai are (mA,nA) real matrices
+ * Br and Bi are (mB,nB) real matrices
+ * Outr and Outi are (mOut,nOut) real matrices
+ * edgM is an integer
+ * edgN is an integer
+ */
+void conv2_C(double *Ar,double *Ai,int mA,int nA,
+             double *Br,double *Bi,int mB,int nB,
+             double *Outr,double *Outi,int mOut,int nOut,
+             int edgM,int edgN);
+#endif /* __CONV2_H__ */
+
index 815f0ea..b3e81fe 100644 (file)
@@ -190,6 +190,8 @@ lib /DEF:"$(ProjectDir)signal_processing_f_Import.def" /SUBSYSTEM:WINDOWS /MACHI
     </Link>
   </ItemDefinitionGroup>
   <ItemGroup>
+    <ClCompile Include="..\..\sci_gateway\c\sci_conv2.c" />
+    <ClCompile Include="conv2.c" />
     <ClCompile Include="corrtable.c" />
     <ClCompile Include="DllmainSignal_processing.c" />
     <ClCompile Include="..\..\sci_gateway\c\gw_signal.c" />
@@ -206,6 +208,7 @@ lib /DEF:"$(ProjectDir)signal_processing_f_Import.def" /SUBSYSTEM:WINDOWS /MACHI
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_signal_processing.h" />
     <ClInclude Include="..\..\includes\gw_signal.h" />
+    <ClInclude Include="conv2.h" />
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\locales\en_US\signal_processing.pot" />
@@ -227,10 +230,19 @@ lib /DEF:"$(ProjectDir)signal_processing_f_Import.def" /SUBSYSTEM:WINDOWS /MACHI
       <Project>{3170e4c2-1173-4264-a222-7ee8ccb3ddf7}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\api_scilab\api_scilab.vcxproj">
+      <Project>{43c5bab1-1dca-4743-a183-77e0d42fe7d0}</Project>
+    </ProjectReference>
     <ProjectReference Include="..\..\..\dynamic_link\src\c\dynamic_link.vcxproj">
       <Project>{eab6c580-22b3-4359-ba1d-dd7499a96163}</Project>
       <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
     </ProjectReference>
+    <ProjectReference Include="..\..\..\output_stream\src\c\output_stream.vcxproj">
+      <Project>{a5911cd7-f8e8-440c-a23e-4843a0636f3a}</Project>
+    </ProjectReference>
+  </ItemGroup>
+  <ItemGroup>
+    <Library Include="..\..\..\..\bin\blasplus.lib" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 32043fa..b1f7e2d 100644 (file)
     <ClCompile Include="..\..\sci_gateway\c\sci_syredi.c">
       <Filter>Source Files</Filter>
     </ClCompile>
+    <ClCompile Include="conv2.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
+    <ClCompile Include="..\..\sci_gateway\c\sci_conv2.c">
+      <Filter>Source Files</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\..\includes\dynlib_signal_processing.h">
@@ -67,6 +73,9 @@
     <ClInclude Include="..\..\includes\gw_signal.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="conv2.h">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\locales\en_US\signal_processing.pot">
@@ -87,4 +96,7 @@
       <Filter>Resource Files</Filter>
     </ResourceCompile>
   </ItemGroup>
+  <ItemGroup>
+    <Library Include="..\..\..\..\bin\blasplus.lib" />
+  </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/scilab/modules/signal_processing/tests/unit_tests/conv.dia.ref b/scilab/modules/signal_processing/tests/unit_tests/conv.dia.ref
new file mode 100644 (file)
index 0000000..2603ff0
--- /dev/null
@@ -0,0 +1,17 @@
+// =============================================================================
+// 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.
+// =============================================================================
+u=1:10;v=[1 -1];
+assert_checkequal(conv(u,v),[ones(1,10) -10]);
+assert_checkequal(conv(u,v,"full"),[ones(1,10) -10]);
+assert_checkequal(conv(u,v'),[ones(1,10) -10]);
+assert_checkequal(conv(u',v),[ones(10,1); -10]);
+assert_checkequal(conv(u,v,"same"),[ones(1,9) -10]);
+assert_checkequal(conv(v,u,"same"),[1 1]);
+assert_checkequal(conv(u,v,"valid"),ones(1,9));
+assert_checkequal(conv(v,u,"valid"),[]);
+assert_checkequal(conv(u,v*%i),[ones(1,10) -10]*%i);
+assert_checkequal(conv(u*%i,v*%i),-[ones(1,10) -10]+0*%i);
diff --git a/scilab/modules/signal_processing/tests/unit_tests/conv.tst b/scilab/modules/signal_processing/tests/unit_tests/conv.tst
new file mode 100644 (file)
index 0000000..d71cb1a
--- /dev/null
@@ -0,0 +1,18 @@
+// =============================================================================
+// 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.
+// =============================================================================
+u=1:10;v=[1 -1];
+assert_checkequal(conv(u,v),[ones(1,10) -10]);
+assert_checkequal(conv(u,v,"full"),[ones(1,10) -10]);
+assert_checkequal(conv(u,v'),[ones(1,10) -10]);
+assert_checkequal(conv(u',v),[ones(10,1); -10]);
+
+assert_checkequal(conv(u,v,"same"),[ones(1,9) -10]);
+assert_checkequal(conv(v,u,"same"),[1 1]);
+assert_checkequal(conv(u,v,"valid"),ones(1,9));
+assert_checkequal(conv(v,u,"valid"),[]);
+assert_checkequal(conv(u,v*%i),[ones(1,10) -10]*%i);
+assert_checkequal(conv(u*%i,v*%i),-[ones(1,10) -10]+0*%i);
diff --git a/scilab/modules/signal_processing/tests/unit_tests/conv2.dia.ref b/scilab/modules/signal_processing/tests/unit_tests/conv2.dia.ref
new file mode 100644 (file)
index 0000000..b8fe6c0
--- /dev/null
@@ -0,0 +1,49 @@
+// =============================================================================
+// 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.
+// =============================================================================
+s = [1 2 1; 0 0 0; -1 -2 -1];
+A = zeros(10,10);
+A(3:7,3:7) = 1;
+reffull=zeros(12,12);
+reffull([3,4,8,9],3:9)=[1;1;-1;-1]*[1 3 4 4 4 3 1];
+assert_checkequal(conv2(s,A),reffull);
+assert_checkequal(conv2(A,s),reffull);
+assert_checkequal(conv2(s,A,'full'),reffull);
+assert_checkequal(conv2(A,s,'full'),reffull);
+assert_checkequal(conv2(s,A,'same'),[0,0,0;0,0,0;-4,-4,-3]);
+refsame=zeros(10,10);
+refsame([2,3,7,8],2:8)=[1;1;-1;-1]*[1 3 4 4 4 3 1];
+assert_checkequal(conv2(A,s,'same'),refsame);
+assert_checkequal(conv2(s,A,'valid'),[]);
+refvalid=zeros(8,8);
+refvalid([1,2,6,7],1:7)=[1;1;-1;-1]*[1 3 4 4 4 3 1];
+assert_checkequal(conv2(A,s,'valid'),refvalid);
+u=[1;0;-1];v=[1 2 1];
+assert_checkequal(conv2(u,v,A),reffull);
+assert_checkequal(conv2(u,v,A,'full'),reffull);
+assert_checkequal(conv2(u,v,A,'same'),refsame);
+assert_checkequal(conv2(u,v,A,'valid'),refvalid);
+a=[1 2 3;4 5 6;7 8 9];
+assert_checkequal(conv2(a,s,'same'),[13 20 17;18 24 18;-13 -20 -17]);
+assert_checkequal(conv2([3;4],[1;2]),[3;10;8]);
+assert_checkequal(conv2([1;2],1,[3;4]),[3;10;8]);
+assert_checkequal(conv2([1;2],%i,[3;4]),[3;10;8]*%i); 
+assert_checkequal(conv2([1;2]*%i,1,[3;4]),[3;10;8]*%i);
+assert_checkequal(conv2([1;2],1,[3;4]*%i),[3;10;8]*%i);
+assert_checkequal(conv2([1;2],%i,[3;4]*%i),-[3;10;8]+0*%i);
+assert_checkequal(conv2([1;2]*%i,%i,[3;4]),-[3;10;8]+0*%i);
+assert_checkequal(conv2([1;2]*%i,%i,[3;4]*%i),-[3;10;8]*%i);
+assert_checkequal(conv2([1 2;3 4],[]),zeros(2,2));
+assert_checkequal(conv2([],[1 2;3 4]),zeros(2,2));
+assert_checkequal(conv2([1 2;3 4],[],'same'),zeros(2,2));
+assert_checkequal(conv2([],[1 2;3 4],'same'),[]);
+assert_checkequal(conv2([1 2;3 4],[],'valid'),zeros(2,2));
+assert_checkequal(conv2([],[1 2;3 4],'valid'),[]);
+//here we do not follow matlab
+assert_checkequal(conv2([],[1,2],[1 2;3 4]),zeros(2,2));
+assert_checkequal(conv2([1,2],[],[1 2;3 4]),zeros(2,2));
+assert_checkequal(conv2([],[1;2],[1 2;3 4]),zeros(2,2));
+assert_checkequal(conv2([1;2],[],[1 2;3 4]),zeros(2,2));
diff --git a/scilab/modules/signal_processing/tests/unit_tests/conv2.tst b/scilab/modules/signal_processing/tests/unit_tests/conv2.tst
new file mode 100644 (file)
index 0000000..1d1dd91
--- /dev/null
@@ -0,0 +1,59 @@
+// =============================================================================
+// 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.
+// =============================================================================
+s = [1 2 1; 0 0 0; -1 -2 -1];
+A = zeros(10,10);
+A(3:7,3:7) = 1;
+reffull=zeros(12,12);
+reffull([3,4,8,9],3:9)=[1;1;-1;-1]*[1 3 4 4 4 3 1];
+assert_checkequal(conv2(s,A),reffull);
+assert_checkequal(conv2(A,s),reffull);
+
+assert_checkequal(conv2(s,A,'full'),reffull);
+assert_checkequal(conv2(A,s,'full'),reffull);
+
+assert_checkequal(conv2(s,A,'same'),[0,0,0;0,0,0;-4,-4,-3]);
+refsame=zeros(10,10);
+refsame([2,3,7,8],2:8)=[1;1;-1;-1]*[1 3 4 4 4 3 1];
+assert_checkequal(conv2(A,s,'same'),refsame);
+
+assert_checkequal(conv2(s,A,'valid'),[]);
+refvalid=zeros(8,8);
+refvalid([1,2,6,7],1:7)=[1;1;-1;-1]*[1 3 4 4 4 3 1];
+assert_checkequal(conv2(A,s,'valid'),refvalid);
+
+u=[1;0;-1];v=[1 2 1];
+assert_checkequal(conv2(u,v,A),reffull);
+assert_checkequal(conv2(u,v,A,'full'),reffull);
+assert_checkequal(conv2(u,v,A,'same'),refsame);
+assert_checkequal(conv2(u,v,A,'valid'),refvalid);
+
+a=[1 2 3;4 5 6;7 8 9];
+
+assert_checkequal(conv2(a,s,'same'),[13 20 17;18 24 18;-13 -20 -17]);
+
+assert_checkequal(conv2([3;4],[1;2]),[3;10;8]);
+
+assert_checkequal(conv2([1;2],1,[3;4]),[3;10;8]);
+assert_checkequal(conv2([1;2],%i,[3;4]),[3;10;8]*%i); 
+assert_checkequal(conv2([1;2]*%i,1,[3;4]),[3;10;8]*%i);
+assert_checkequal(conv2([1;2],1,[3;4]*%i),[3;10;8]*%i);
+assert_checkequal(conv2([1;2],%i,[3;4]*%i),-[3;10;8]+0*%i);
+assert_checkequal(conv2([1;2]*%i,%i,[3;4]),-[3;10;8]+0*%i);
+assert_checkequal(conv2([1;2]*%i,%i,[3;4]*%i),-[3;10;8]*%i);
+
+assert_checkequal(conv2([1 2;3 4],[]),zeros(2,2));
+assert_checkequal(conv2([],[1 2;3 4]),zeros(2,2));
+assert_checkequal(conv2([1 2;3 4],[],'same'),zeros(2,2));
+assert_checkequal(conv2([],[1 2;3 4],'same'),[]);
+assert_checkequal(conv2([1 2;3 4],[],'valid'),zeros(2,2));
+assert_checkequal(conv2([],[1 2;3 4],'valid'),[]);
+
+//here we do not follow matlab
+assert_checkequal(conv2([],[1,2],[1 2;3 4]),zeros(2,2));
+assert_checkequal(conv2([1,2],[],[1 2;3 4]),zeros(2,2));
+assert_checkequal(conv2([],[1;2],[1 2;3 4]),zeros(2,2));
+assert_checkequal(conv2([1;2],[],[1 2;3 4]),zeros(2,2));
diff --git a/scilab/modules/signal_processing/tests/unit_tests/convol2d.dia.ref b/scilab/modules/signal_processing/tests/unit_tests/convol2d.dia.ref
new file mode 100644 (file)
index 0000000..0f7e3d5
--- /dev/null
@@ -0,0 +1,18 @@
+// =============================================================================
+// 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.
+// =============================================================================
+s = [1 2 1; 0 0 0; -1 -2 -1];
+A = zeros(10,10);
+A(3:7,3:7) = 1;
+reffull=zeros(12,12);
+reffull([3,4,8,9],3:9)=[1;1;-1;-1]*[1 3 4 4 4 3 1];
+assert_checkalmostequal(convol2d(s,A),reffull,100*%eps,100*%eps);
+assert_checkalmostequal(convol2d(A,s),reffull,100*%eps,100*%eps);
+assert_checkequal(convol2d([3;4],[1;2]),[3;10;8]);
+assert_checkequal(convol2d([3;4],[1;2]*%i),[3;10;8]*%i);
+assert_checkequal(convol2d([3;4]*%i,[1;2]*%i),-[3;10;8]+0*%i);
+assert_checkequal(convol2d([1 2;3 4],[]),zeros(2,2));
+assert_checkequal(convol2d([],[1 2;3 4]),zeros(2,2));
diff --git a/scilab/modules/signal_processing/tests/unit_tests/convol2d.tst b/scilab/modules/signal_processing/tests/unit_tests/convol2d.tst
new file mode 100644 (file)
index 0000000..2320bce
--- /dev/null
@@ -0,0 +1,22 @@
+// =============================================================================
+// 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.
+// =============================================================================
+s = [1 2 1; 0 0 0; -1 -2 -1];
+A = zeros(10,10);
+A(3:7,3:7) = 1;
+reffull=zeros(12,12);
+reffull([3,4,8,9],3:9)=[1;1;-1;-1]*[1 3 4 4 4 3 1];
+assert_checkalmostequal(convol2d(s,A),reffull,100*%eps,100*%eps);
+assert_checkalmostequal(convol2d(A,s),reffull,100*%eps,100*%eps);
+
+
+assert_checkequal(convol2d([3;4],[1;2]),[3;10;8]);
+assert_checkequal(convol2d([3;4],[1;2]*%i),[3;10;8]*%i);
+assert_checkequal(convol2d([3;4]*%i,[1;2]*%i),-[3;10;8]+0*%i);
+
+
+assert_checkequal(convol2d([1 2;3 4],[]),zeros(2,2));
+assert_checkequal(convol2d([],[1 2;3 4]),zeros(2,2));