fix fft premature slicing away of 0 freq bin

also fixes:
- use rfft for better efficiency
- use rfftfreq to compute coords correctly
  - works for both odd/even lengths
- python3: integer division needed for numpy indexing
This commit is contained in:
KIU Shueng Chuan 2017-01-17 22:04:05 +08:00
parent f26b4ec3c7
commit 12f6bf916f

View File

@ -679,10 +679,9 @@ class PlotDataItem(GraphicsObject):
x2 = np.linspace(x[0], x[-1], len(x)) x2 = np.linspace(x[0], x[-1], len(x))
y = np.interp(x2, x, y) y = np.interp(x2, x, y)
x = x2 x = x2
f = np.fft.fft(y) / len(y) f = np.fft.rfft(y) / y.size
y = abs(f[1:len(f)/2]) x = np.fft.rfftfreq(y.size)
dt = x[-1] - x[0] y = np.abs(f)
x = np.linspace(0, 0.5*len(x)/dt, len(y))
return x, y return x, y
def dataType(obj): def dataType(obj):