5

I have to calculate the bandpower of a signal for a certain vector of frequencies in python as a project. In MATLAB it can be done using p = bandpower(pxx,f,'psd') where pxx is Power spectral density vector and f, is a vector of frequencies corresponding to the PSD estimates in pxx. Is there any equivalent function in python that does the same?

tahsin314
  • 521
  • 1
  • 7
  • 22
  • This looks similar to https://stackoverflow.com/questions/44547669/python-numpy-equivalent-of-bandpower-from-matlab – Chris K8NVH Nov 25 '18 at 20:51

1 Answers1

0

from this answer

import scipy 

def bandpower(x, fs, fmin, fmax):
    f, Pxx = scipy.signal.periodogram(x, fs=fs)
    ind_min = scipy.argmax(f > fmin) - 1
    ind_max = scipy.argmax(f > fmax) - 1
    return scipy.trapz(Pxx[ind_min: ind_max], f[ind_min: ind_max])
random_dsp_guy
  • 246
  • 2
  • 13