def periodogram(x, *args, detrend='diff', **kwargs):
"""
Return periodogram of signal `x`.
Parameters
----------
x: array_like
A 1D signal.
detrend: 'diff' or False or int
Remove trend from x. If int, fit and subtract a polynomial of this
order. See also: `statsmodels.tsa.detrend`.
args, kwargs:
As accepted by `scipy.signal.periodogram`.
Returns
-------
periods: array_like
The periods at which the spectral density is calculated.
pgram: array_like
Power spectral density of x.
"""
from scipy.signal import periodogram
x = _detrend(x, detrend)
freqs, pgram = periodogram(x, *args, detrend=False, **kwargs)
SKIP = len(x) // 1000 # HACK: For long series, the first few frequency/period values are "unstable".
freqs, pgram = freqs[SKIP:], pgram[SKIP:]
periods = 1 / freqs
periods, pgram = _significant_periods(periods, pgram)
return periods, pgram
评论列表
文章目录