To calculate the frequencies in a time domain signal in Python, you can use the fast Fourier transform (FFT) in the numpy library.
Here's an example code snippet:
main.py691 chars27 lines
This code generates a 2 Hz sine wave, performs the FFT on the signal, and plots the power spectrum of the resulting FFT coefficients. The frequencies are calculated using np.fft.fftfreq()
and correspond to each FFT coefficient. We only keep the positive frequencies and corresponding FFT coefficients, and plot the power spectrum of the FFT coefficients squared.
gistlibby LogSnag