Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16506

How to extract dominant frequency from NumPy array?

$
0
0

I am working with simulations of populations of neurons, and would like to extract the dominant frequency from their local field potential. This takes the form of just a single vector of values, which I have plotted here. Clearly, there is some oscillatory activity happening, and I am interested in what frequency the large scale oscillations are occurring at.

Plot of LFP for a simulation

I am not very familiar with Fourier transforms outside of the general idea of them, but I believe they are the tool needed here? The sampling distance in this simulation was 0.00006 seconds or the sampling rate is 1/0.00006 Hz. I tried using the numpy.fft.fft function, but I am a little unsure about how to interpret the results. I expected a large peak around 1, corresponding to what appears like 1 Hz oscillations. Here is the code I ran, and the resulting plot.

raw = np.loadtxt(r"./file.txt")#calculate the frequencies associated with our signalfreqs = fft.rfftfreq(len(raw),0.0006)sp = fft.rfft(raw)plt.plot(freqs, sp.real, freqs, sp.imag)

Entire FFT plot

I believe the high sampling rate is causing the calculation of such high frequencies, and I know I am just interested in those from ~0-4 Hz so I can plot those as:

0-4 Hz FFT plot

Or to make it easier to visualize, just ~1-4 Hz:

~1-4 Hz FFT plot

Note, I am not calculating the FFTs any differently, just plotting different regions of the results. My issue is I am unclear about how to interpret the results or also how to realize if I am making an error somewhere in my code. I can see some spikes in the results, but they are not where I expected them to be, nor am I sure on how to determine when they are significant.

Any help with this is appreciated. :^)


Viewing all articles
Browse latest Browse all 16506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>