def fourrier_spectrum(self, *args, **kwargs):
"""
Parameters
----------
*args, **kwargs
extra arguments provided to the periodogram function.
Returns
-------
tuple of numpy.ndarray: fourrier modes and power density obtained with the scipy.signal.periodogram function.
""" # noqa
freq, ampl = periodogram(self._template, fs=1 / self._dt)
return freq, ampl
python类periodogram()的实例源码
def plotperiodogram(t,x,fs,ax,ttxt):
fax,Pxx = periodogram(x,fs,'hanning')
ax[0].plot(fax,10*np.log10(abs(Pxx)))
ax[0].set_title(ttxt)
ax[1].plot(t,x)
ax[1].set_ylim(-1,1)
ax[1].set_xlabel('time [sec.]')
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
def getPowerSpectralDensity(X,fs=1.0):
assert fs > 0
f, Pxx_den = signal.periodogram(X, fs,scaling='density',window=None,detrend=False)
return (f,Pxx_den)