Accept version 0.2 (and similar?) JPK files with channels (vs. channels.list).
[hooke.git] / hooke / util / fft.py
index 0c724695111f5d8b89a304f021cccc5ab400796d..0f7f7b00967f7c0b5fe42b5dc604a27a620ef37e 100644 (file)
@@ -2,15 +2,15 @@
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation, either
-# version 3 of the License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
 #
-# Hooke is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
+# Public License for more details.
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with Hooke.  If not, see
@@ -20,7 +20,7 @@
 
 Define some FFT wrappers to reduce clutter.
 Provides a unitary discrete FFT and a windowed version.
-Based on numpy.fft.rfft.
+Based on :func:`numpy.fft.rfft`.
 
 Main entry functions:
 
@@ -114,7 +114,6 @@ def unitary_rfft(data, freq=1.0):
 
     Notes
     -----
-    
     If the units on your data are Volts,
     and your sampling frequency is in Hz,
     then `freq_axis` will be in Hz,
@@ -307,7 +306,7 @@ def avg_power_spectrum(data, freq=1.0, chunk_size=2048,
 
 def unitary_avg_power_spectrum(data, freq=1.0, chunk_size=2048,
                                overlap=True, window=window_hann):
-    """Compute the unitary avgerage power spectrum of `data`.
+    """Compute the unitary average power spectrum of `data`.
 
     See Also
     --------
@@ -334,19 +333,18 @@ class TestRFFT (unittest.TestCase):
 
     Notes
     -----
+    The expected return values are [#dft]_:
 
-    The expected return values are [#numpybook]_:
-
-    .. math:: X_k = \sum_{m=0}^{n-1} x_m \exp^{-j 2\pi k_m/n}
+    .. math:: X_k = \sum_{m=0}^{n-1} x_m \exp^{-2\pi imk/n}
 
-    .. [#numpybook] http://www.tramy.us/numpybook.pdf
+    .. [#dft] See the *Background information* section of :mod:`numpy.fft`.
     """
     def run_rfft(self, xs, Xs):
-        j = complex(0,1)
+        i = complex(0,1)
         n = len(xs)
         Xa = []
         for k in range(n):
-            Xa.append(sum([x*exp(-j*2*pi*k*m/n) for x,m in zip(xs,range(n))]))
+            Xa.append(sum([x*exp(-2*pi*i*m*k/n) for x,m in zip(xs,range(n))]))
             if k < len(Xs):
                 assert (Xs[k]-Xa[k])/abs(Xa[k]) < 1e-6, \
                     "rfft mismatch on element %d: %g != %g, relative error %g" \
@@ -372,7 +370,6 @@ class TestUnitaryRFFT (unittest.TestCase):
 
         Notes
         -----
-
         Which is:
 
         .. math:: \sum_{m=0}^{n-1} |x_m|^2 dt = \sum_{k=0}^{n-1} |X_k|^2 df
@@ -421,7 +418,6 @@ class TestUnitaryRFFT (unittest.TestCase):
 
         Notes
         -----
-
         Analytic result:
 
         .. math:: \rfft(\rect(at)) = 1/|a|\cdot\sinc(f/a)
@@ -486,7 +482,6 @@ class TestUnitaryRFFT (unittest.TestCase):
 
         Notes
         -----
-
         Analytic result:
 
         .. math::