* Bug #10221 fixed - Signal_processing: ifftshift function 19/13319/2
Paul Bignier [Thu, 5 Dec 2013 11:52:50 +0000 (12:52 +0100)]
Introducing the ifftshift function to shift matrices.

Change-Id: I8b34793f0e303ec3cdcfc61435c50b1682b30b0f

12 files changed:
SEP/INDEX
SEP/SEP_118_ifftshift.odt [new file with mode: 0644]
scilab/CHANGES_5.5.X
scilab/modules/m2sci/help/en_US/m2sci_equivalents/i/ifftshift.xml [new file with mode: 0644]
scilab/modules/m2sci/macros/kernel/not_yet_converted.sci
scilab/modules/signal_processing/help/en_US/fftshift.xml
scilab/modules/signal_processing/help/en_US/ifftshift.xml [new file with mode: 0644]
scilab/modules/signal_processing/help/fr_FR/ifftshift.xml [new file with mode: 0644]
scilab/modules/signal_processing/help/ja_JP/fftshift.xml
scilab/modules/signal_processing/macros/ifftshift.sci [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/ifftshift.dia.ref [new file with mode: 0644]
scilab/modules/signal_processing/tests/unit_tests/ifftshift.tst [new file with mode: 0644]

index 5066132..af1824f 100644 (file)
--- a/SEP/INDEX
+++ b/SEP/INDEX
@@ -113,3 +113,4 @@ SEP #114: New function jcreatejar.
 SEP #115: New function bode_asymp.
 SEP #116: conjgrad function, to regroup the Conjugate Gradient solvers. pcg obsolete as it is.
 SEP #117: New function ilib_build_jar
+SEP #118: New function ifftshift
diff --git a/SEP/SEP_118_ifftshift.odt b/SEP/SEP_118_ifftshift.odt
new file mode 100644 (file)
index 0000000..396bfb6
Binary files /dev/null and b/SEP/SEP_118_ifftshift.odt differ
index 0203d80..e6a1937 100644 (file)
@@ -10,6 +10,7 @@ New Features
 * New functions introduced:
  - jcreatejar - Creates a Java archive (JAR) from a set of files / directories
  - ilib_build_jar - Builds Java packages from sources into a JAR file
+ - ifftshift - inverse FFT shift
 
 * modulo() and pmodulo() now support integers & hypermatrices (See bug #13002).
 
@@ -121,6 +122,8 @@ Scilab Bug Fixes
 
 * Bug #10175 fixed - Clearer example added for sp2adj to adj2sp conversion (and backwards conversion).
 
+* Bug #10221 fixed - ifftshift function did not exist in Scilab.
+
 * Bug #10234 fixed - reglin function moved from CACSD to Statistics module.
 
 * Bug #10243 fixed - fun2string(X) called X before returning its code.
diff --git a/scilab/modules/m2sci/help/en_US/m2sci_equivalents/i/ifftshift.xml b/scilab/modules/m2sci/help/en_US/m2sci_equivalents/i/ifftshift.xml
new file mode 100644 (file)
index 0000000..365a06b
--- /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) 2013 - Scilab Enterprises - Paul Bignier
+ *
+ * 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.1-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" xmlns:scilab="http://www.scilab.org" xml:id="m2sci_ifft">
+    <refnamediv>
+        <refname>ifftshift (Matlab function)</refname>
+        <refpurpose>Inverse FFT function</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[
+ifftshift(x)
+]]></programlisting>
+                </td>
+                <td>
+                    <programlisting role="example"><![CDATA[
+ifftshift(x)
+]]></programlisting>
+                </td>
+            </tr>
+        </informaltable>
+    </refsection>
+</refentry>
index 4f95b78..98ef705 100644 (file)
@@ -534,7 +534,6 @@ function allnames=not_yet_converted()
     "icondisp";
     "ifft2";
     "ifftn";
-    "ifftshift";
     "ihb1dae";
     "im2frame";
     "im2java";
index b553f26..163ff4a 100644 (file)
     <refsection>
         <title>Description</title>
         <para>
-            if <literal>x</literal> results of an fft computation <literal>y= fftshift(x)</literal> or <literal>y= fftshift(x,"all")</literal> moves the zero frequency component to the center
+            If <literal>x</literal> results of an fft computation <literal>y=fftshift(x)</literal> or <literal>y=fftshift(x,"all")</literal> moves the zero frequency component to the center
             of the spectrum, which is sometimes a more convenient form.
         </para>
         <para>
             If <literal>x</literal> is a vector of size n, y is the vector <literal>x([n/2+1:n,1:n/2])</literal>
         </para>
         <para>
-            If <literal>x</literal> is an <literal>m</literal> by <literal>n</literal>  matrix <literal>y</literal> is the matrix
+            If <literal>x</literal> is an <literal>m</literal> by <literal>n</literal> matrix <literal>y</literal> is the matrix
             <literal>x([m/2+1:n,1:m/2],[n/2+1:n,1:n/2])</literal>.
         </para>
-        <programlisting role="no-scilab-exec"><![CDATA[ 
+        <programlisting role="no-scilab-exec"><![CDATA[
   [x11 x12]                  [x22 x21]
 x=[       ]        gives   y=[       ]
   [x21 x22]                  [x12 x11]
  ]]></programlisting>
         <para>
-            <literal>y= fftshift(x,n)</literal>  make the swap only along the <literal>n</literal>th dimension
+            <literal>y=fftshift(x,n)</literal> makes the swap only along the <literal>n</literal>th dimension
         </para>
     </refsection>
     <refsection>
         <title>Examples</title>
-        <programlisting role="example"><![CDATA[ 
-//make a signal
+        <programlisting role="example"><![CDATA[
+// Make a signal
 t=0:0.1:1000;
 x=3*sin(t)+8*sin(3*t)+0.5*sin(5*t)+3*rand(t);
-//compute the fft
+// Compute the fft
 y=fft(x,-1);
 
-//display 
+// Display
 clf();
 subplot(2,1,1);plot2d(abs(y))
 subplot(2,1,2);plot2d(fftshift(abs(y)))
@@ -74,16 +74,15 @@ subplot(2,1,2);plot2d(fftshift(abs(y)))
             subplot(2,1,1);plot2d(abs(y))
             subplot(2,1,2);plot2d(fftshift(abs(y)))
         </scilab:image>
-        
-        <programlisting role="example"><![CDATA[ 
-//make a 2D image
+        <programlisting role="example"><![CDATA[
+// Make a 2D image
 t=0:0.1:30;
 x=3*sin(t')*cos(2*t)+8*sin(3*t')*sin(5*t)+..
   0.5*sin(5*t')*sin(5*t)+3*rand(t')*rand(t);
-//compute the fft
+// Compute the fft
 y=fft(x,-1);
 
-//display 
+// Display
 clf();
 xset('colormap',hotcolormap(256))
 subplot(2,1,1);Matplot(abs(y))
@@ -98,7 +97,6 @@ subplot(2,1,2);Matplot(fftshift(abs(y)))
             subplot(2,1,1);Matplot(abs(y))
             subplot(2,1,2);Matplot(fftshift(abs(y)))
         </scilab:image>
-        
     </refsection>
     <refsection role="see also">
         <title>See Also</title>
@@ -106,6 +104,9 @@ subplot(2,1,2);Matplot(fftshift(abs(y)))
             <member>
                 <link linkend="fft">fft</link>
             </member>
+            <member>
+                <link linkend="ifftshift">ifftshift</link>
+            </member>
         </simplelist>
     </refsection>
 </refentry>
diff --git a/scilab/modules/signal_processing/help/en_US/ifftshift.xml b/scilab/modules/signal_processing/help/en_US/ifftshift.xml
new file mode 100644 (file)
index 0000000..22745a0
--- /dev/null
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+ *
+ * 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.1-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" xmlns:scilab="http://www.scilab.org" xml:lang="en" xml:id="fftshift">
+    <refnamediv>
+        <refname>ifftshift</refname>
+        <refpurpose>inverse of fftshift</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Calling Sequence</title>
+        <synopsis>y=ifftshift(x)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Arguments</title>
+        <variablelist>
+            <varlistentry>
+                <term>x, y</term>
+                <listitem>
+                    <para>real or complex vector or matrix.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            <literal>ifftshift(x)</literal> swaps the left and right halves of the vector <literal>x</literal>.
+        </para>
+        <para>
+            For matrices, <literal>ifftshift(x)</literal> swaps the first quadrant with the third and the second quadrant with the fourth.
+        </para>
+        <para>
+            If <literal>x</literal> is a multidimensional array,
+            <literal>ifftshift(x)</literal> swaps "half-spaces" of <literal>x</literal> along each dimension.
+        </para>
+    </refsection>
+    <refsection>
+        <title>Examples</title>
+        <para>
+            Example #1:
+        </para>
+        <programlisting role="example"><![CDATA[
+// Make a signal
+t = 0:0.1:1000;
+x = 3*sin(t)+8*sin(3*t)+0.5*sin(5*t)+3*rand(t);
+// Compute the fft
+y = fft(x, -1);
+// Invert the result
+shift = fftshift(y);
+// Invert the inverted result
+invShift = ifftshift(shift);
+// Check that we recreated the original result
+and(y == invShift)
+ ]]></programlisting>
+        <para>
+            Example #2:
+        </para>
+        <programlisting role="example"><![CDATA[
+// Make a 2D image
+t = 0:0.1:30;
+x = 3*sin(t')*cos(2*t)+8*sin(3*t')*sin(5*t)+..
+  0.5*sin(5*t')*sin(5*t)+3*rand(t')*rand(t);
+// Compute the fft
+y = fft(x,-1);
+
+// Invert the result
+shift = fftshift(y);
+// Invert the inverted result
+invShift = ifftshift(shift);
+// Check that we recreated the original result
+and(y == invShift)
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>See Also</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="fftshift">fftshift</link>
+            </member>
+            <member>
+                <link linkend="fft">fft</link>
+            </member>
+        </simplelist>
+    </refsection>
+</refentry>
diff --git a/scilab/modules/signal_processing/help/fr_FR/ifftshift.xml b/scilab/modules/signal_processing/help/fr_FR/ifftshift.xml
new file mode 100644 (file)
index 0000000..1ef39f3
--- /dev/null
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+ *
+ * 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.1-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" xmlns:scilab="http://www.scilab.org" xml:lang="fr" xml:id="fftshift">
+    <refnamediv>
+        <refname>ifftshift</refname>
+        <refpurpose>inverse de fftshift</refpurpose>
+    </refnamediv>
+    <refsynopsisdiv>
+        <title>Séquence d'appel</title>
+        <synopsis>y=ifftshift(x)</synopsis>
+    </refsynopsisdiv>
+    <refsection>
+        <title>Paramètres</title>
+        <variablelist>
+            <varlistentry>
+                <term>x, y</term>
+                <listitem>
+                    <para>vecteurs ou matrices réel(le)s ou complexes.</para>
+                </listitem>
+            </varlistentry>
+        </variablelist>
+    </refsection>
+    <refsection>
+        <title>Description</title>
+        <para>
+            <literal>ifftshift(x)</literal> échange les moitiés gauche et droite du vecteur <literal>x</literal>.
+        </para>
+        <para>
+            Pour les matrices, <literal>ifftshift(x)</literal> échange le premier quadrant avec le troisième et le second avec le quatrième.
+        </para>
+        <para>
+            Si <literal>x</literal> est un tableau multidimensionnel,
+            <literal>ifftshift(x)</literal> échange les "mi-espaces" de <literal>x</literal> selon chaque dimension.
+        </para>
+    </refsection>
+    <refsection>
+        <title>Exemples</title>
+        <para>
+            Exemple #1:
+        </para>
+        <programlisting role="example"><![CDATA[
+// Création d'un signal
+t = 0:0.1:1000;
+x = 3*sin(t)+8*sin(3*t)+0.5*sin(5*t)+3*rand(t);
+// Calcul de sa fft
+y = fft(x, -1);
+// Inversion du résultat
+shift = fftshift(y);
+// Inversion du résultat inversé
+invShift = ifftshift(shift);
+// On vérifie qu'on a bien recréé le résultat de départ
+and(y == invShift)
+ ]]></programlisting>
+        <para>
+            Example #2:
+        </para>
+        <programlisting role="example"><![CDATA[
+// Création d'une image 2D
+t = 0:0.1:30;
+x = 3*sin(t')*cos(2*t)+8*sin(3*t')*sin(5*t)+..
+  0.5*sin(5*t')*sin(5*t)+3*rand(t')*rand(t);
+// Calcul de la fft
+y = fft(x,-1);
+
+// Inversion du résultat
+shift = fftshift(y);
+// Inversion du résultat inversé
+invShift = ifftshift(shift);
+// On vérifie qu'on a bien recréé le résultat de départ
+and(y == invShift)
+ ]]></programlisting>
+    </refsection>
+    <refsection role="see also">
+        <title>Voir aussi</title>
+        <simplelist type="inline">
+            <member>
+                <link linkend="fftshift">fftshift</link>
+            </member>
+            <member>
+                <link linkend="fft">fft</link>
+            </member>
+        </simplelist>
+    </refsection>
+</refentry>
index c388624..4166179 100644 (file)
@@ -47,7 +47,7 @@
             <literal>y</literal> は行列
             <literal>x([m/2+1:n,1:m/2],[n/2+1:n,1:n/2])</literal>となります.
         </para>
-        <programlisting role=""><![CDATA[ 
+        <programlisting role=""><![CDATA[
   [x11 x12]                  [x22 x21]
 x=[       ]        gives   y=[       ]
   [x21 x22]                  [x12 x11]
@@ -59,7 +59,7 @@ x=[       ]        gives   y=[       ]
     </refsection>
     <refsection>
         <title>例</title>
-        <programlisting role="example"><![CDATA[ 
+        <programlisting role="example"><![CDATA[
 //信号を作成
 t=0:0.1:1000;
 x=3*sin(t)+8*sin(3*t)+0.5*sin(5*t)+3*rand(t);
@@ -91,6 +91,9 @@ subplot(2,1,2);Matplot(fftshift(abs(y)))
             <member>
                 <link linkend="fft">fft</link>
             </member>
+            <member>
+                <link linkend="ifftshift">ifftshift</link>
+            </member>
         </simplelist>
     </refsection>
 </refentry>
diff --git a/scilab/modules/signal_processing/macros/ifftshift.sci b/scilab/modules/signal_processing/macros/ifftshift.sci
new file mode 100644 (file)
index 0000000..8d030ac
--- /dev/null
@@ -0,0 +1,27 @@
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2011 - Scilab Enterprises - Allan Cornet
+//
+// 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.1-en.txt
+
+function y = ifftshift(x)
+
+    if argn(2) < 1 then
+        error(sprintf(_("%s: Wrong number of input argument(s): %d expected.\n"), "ifftshift", 1));
+    end
+
+    numDims = ndims(x);
+    idx = list(1, numDims);
+
+    for k = 1:numDims
+        m = size(x, k);
+        p = floor(m/2);
+        idx(k) = [p+1:m 1:p];
+    end
+
+    y = x(idx(:));
+
+endfunction
diff --git a/scilab/modules/signal_processing/tests/unit_tests/ifftshift.dia.ref b/scilab/modules/signal_processing/tests/unit_tests/ifftshift.dia.ref
new file mode 100644 (file)
index 0000000..82e4f23
--- /dev/null
@@ -0,0 +1,30 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLLI SHELL MODE -->
+vec = 1:60;
+res = ifftshift(vec);
+assert_checkequal(res(1:30), 31:60);
+assert_checkequal(res(31:60), 1:30);
+mat = matrix(vec, [10 6]);
+refRES = (1:5)';
+refRES = [refRES refRES+10 refRES+20];
+res = ifftshift(mat);
+assert_checkequal(res(1:5, 1:3), refRES+35);
+assert_checkequal(res(1:5, 4:6), refRES+5);
+assert_checkequal(res(6:10, 1:3), refRES+30);
+assert_checkequal(res(6:10, 4:6), refRES);
+// Check that ifftshift(fftshift(x)) = x
+// Make a signal
+t = 0:0.1:1000;
+x = 3*sin(t)+8*sin(3*t)+0.5*sin(5*t)+3*rand(t);
+// Compute the fft
+y = fft(x, -1);
+// Invert the result
+invShift = ifftshift(fftshift(y));
+// Check that we recreated the original result
+assert_checkequal(invShift, y);
diff --git a/scilab/modules/signal_processing/tests/unit_tests/ifftshift.tst b/scilab/modules/signal_processing/tests/unit_tests/ifftshift.tst
new file mode 100644 (file)
index 0000000..a9f3c0f
--- /dev/null
@@ -0,0 +1,39 @@
+// =============================================================================
+// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+// Copyright (C) 2013 - Scilab Enterprises - Paul Bignier
+//
+//  This file is distributed under the same license as the Scilab package.
+// =============================================================================
+//
+// <-- CLLI SHELL MODE -->
+
+vec = 1:60;
+
+res = ifftshift(vec);
+
+assert_checkequal(res(1:30), 31:60);
+assert_checkequal(res(31:60), 1:30);
+
+mat = matrix(vec, [10 6]);
+refRES = (1:5)';
+refRES = [refRES refRES+10 refRES+20];
+
+res = ifftshift(mat);
+
+assert_checkequal(res(1:5, 1:3), refRES+35);
+assert_checkequal(res(1:5, 4:6), refRES+5);
+assert_checkequal(res(6:10, 1:3), refRES+30);
+assert_checkequal(res(6:10, 4:6), refRES);
+
+
+// Check that ifftshift(fftshift(x)) = x
+
+// Make a signal
+t = 0:0.1:1000;
+x = 3*sin(t)+8*sin(3*t)+0.5*sin(5*t)+3*rand(t);
+// Compute the fft
+y = fft(x, -1);
+// Invert the result
+invShift = ifftshift(fftshift(y));
+// Check that we recreated the original result
+assert_checkequal(invShift, y);