From: W. Trevor King Date: Tue, 4 Oct 2011 14:57:04 +0000 (-0400) Subject: Explicitly convert powers to reals (they should have no imaginary portion.) X-Git-Tag: 0.3~3 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c4683965540ad5e7594e9f64ce77c6c2fd439ae9;p=FFT-tools.git Explicitly convert powers to reals (they should have no imaginary portion.) --- 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)