def series_nfft(series,
oversample=4):
"""
note that output period units are [days] (so is frequency)
"""
M = len(series)
if not is_power_of_2(M):
raise ValueError('series length {} is not a power of 2'.format(len(series)))
N = M
if N % 2 == 1:
# number of frequency samples must be even
N += 1
N *= oversample
# re-grid time the interval [-1/2, 1/2) as required by nfft
time = series.index.astype(NP.int64) / 1e9
time -= time[0]
b = -0.5
a = (M - 1) / (M * time[-1])
x = a * time + b
# setup for nfft computation
plan = NFFT(N, M)
plan.x = x
plan.f = series.values
plan.precompute()
# compute nfft (note that conjugation is necessary because of the
# difference in transform sign convention)
x_nfft = NP.conj(plan.adjoint())
# calculate frequencies and periods
dt = ((series.index[-1] - series.index[0]) / M).total_seconds() / DAYS_TO_SECONDS
f_range = NP.fft.fftshift(NP.fft.fftfreq(N, dt))
T_range = 1 / f_range
return x_nfft, f_range, T_range
评论列表
文章目录