From c4683965540ad5e7594e9f64ce77c6c2fd439ae9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 4 Oct 2011 10:57:04 -0400 Subject: [PATCH] Explicitly convert powers to reals (they should have no imaginary portion.) --- FFT_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/FFT_tools.py b/FFT_tools.py index 3772a11..12580c2 100644 --- a/FFT_tools.py +++ b/FFT_tools.py @@ -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]) - 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) : @@ -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) - 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) -- 2.26.2