Explicitly convert powers to reals (they should have no imaginary portion.)
authorW. Trevor King <wking@drexel.edu>
Tue, 4 Oct 2011 14:57:04 +0000 (10:57 -0400)
committerW. Trevor King <wking@drexel.edu>
Tue, 4 Oct 2011 14:57:04 +0000 (10:57 -0400)
FFT_tools.py

index 3772a112f34044d8e046b718b7a93eaaa9963d88..12580c288bc930c2d241d8a3c6309fa553dafc7f 100644 (file)
@@ -273,7 +273,7 @@ def power_spectrum(data, freq=1.0) :
     # >>> help(numpy.fft.fftpack.rfft) for Numpy's explaination.
     # See Numerical Recipies for a details.
     trans = rfft(data[0:nsamps])
     # >>> help(numpy.fft.fftpack.rfft) for Numpy's explaination.
     # See Numerical Recipies for a details.
     trans = rfft(data[0:nsamps])
-    power = trans * trans.conj() # We want the square of the amplitude.
+    power = (trans * trans.conj()).real # We want the square of the amplitude.
     return (freq_axis, power)
 
 def unitary_power_spectrum(data, freq=1.0) :
     return (freq_axis, power)
 
 def unitary_power_spectrum(data, freq=1.0) :
@@ -507,7 +507,7 @@ def avg_power_spectrum(data, freq=1.0, chunk_size=2048,
         starti = i*chunk_step
         stopi = starti+chunk_size
         fft_chunk = rfft(data[starti:stopi]*win)
         starti = i*chunk_step
         stopi = starti+chunk_size
         fft_chunk = rfft(data[starti:stopi]*win)
-        p_chunk = fft_chunk * fft_chunk.conj() 
+        p_chunk = (fft_chunk * fft_chunk.conj()).real
         power += p_chunk.astype(float)
     power /= float(nchunks)
     return (freq_axis, power)
         power += p_chunk.astype(float)
     power /= float(nchunks)
     return (freq_axis, power)