How to extract highest power value in a PSD

Hi!
Does anyone know how can I extract the highest power value of gamma from a power spectral density calculation of an evoked object?
Thanks.

I think you want to extract the peaks within a given range:
You can use scipy 's find peak function to get the highest power value.

this code snippet might be helpful:
we assume the spectrum is on raw or evoked data (so a 2D shape).
Based on your defined frequency range, you need to find the index of the gamma frequency range, e.g.:

import scipy

# extract frequencies
freqs = spectrum.freqs

# freqs = array([8,16,32,48])

# define gamma range
gamma = [30,40]

# extract the gamma indices from the frequencies defined for the PSD
gamma_idx = np.where((freqs >= gamma[0]) & (freqs <= gamma[1]))[0]

# use gamma indices to restrict spectrum to gamma range and find peaks
peaks = scipy.signal.find_peaks(spectrum._data[:,gamma_idx[0]:gamma_idx[1])

# plot the spectrum with the peaks highlighted
plt.plot(spectrum.freqs, spectrum)
for p in peak[0]:
    plt.plot(spectrum.freqs[p], spectrump], 'ro')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Power Spectral Density (dB)')
plt.show()

Hope this helps,

Carina

Hi,

If looking for peaks in the PSD you might want to take into account the 1/f trend of your data. In a nutshell, consider if you need to adjust the peak for the slope in the PSD.

The FOOOF algorithm has its quirks and depending on your data may fail to give you a nice fit, but I think it’s something to keep in mind at least.

Cheers,

1 Like