Spectral analysis¶
The methods listed below can be used to perform very rudimentary spectral (or frequency domain) analysis. They are most useful to make quick plots of the frequency content of a time series.
- datkit.amplitude_spectrum(times, values)¶
Calculates the amplitude spectrum of a regularly spaced time series
(times, current), returning a tuple(frequency, amplitude).Example:
t = np.linspace(0, 10, 1000) v = 3 * np.sin(t * (2 * np.pi * 2)) + 10 * np.cos(t * (2 * np.pi * 3)) f, a = amplitude_spectrum(t, v) fig = plt.figure() ax = fig.add_subplot(2, 1, 1) ax.plot(t, v) ax = fig.add_subplot(2, 1, 2) ax.set_xlim(0, 10) ax.stem(f, a) plt.show()
- datkit.power_spectral_density(times, values)¶
Estimates the power spectral density of a regularly spaced time series
(times, current), returning a tuple(frequency, density).For times in units “T” and values in units “V”, the returned frequencies will be in units “F=1/T” and the densities in “V^2/F”.
For a less noisy version, use
scipy.signal.welch(values, 1 / datkit.sampling_interval(times))instead.Example:
t = np.linspace(0, 10, 1000) v = 5 * np.sin(t * (2 * np.pi * 2)) + 10 * np.cos(t * (2 * np.pi * 3)) f, psd = power_spectral_density(t, v) fig = plt.figure() ax = fig.add_subplot(2, 1, 1) ax.plot(t, v) ax = fig.add_subplot(2, 1, 2) ax.set_yscale('log') ax.set_xlim(0, 10) ax.plot(f, psd) plt.show()