can you help me to correct this code below?
Here I tried to do features extraction of ecg by calculating the mean frequency.
First, I read the audio with this code:
Fs, data = read('ecg_file.wav')
output from data: enter image description here
Then, doing FFT to the data
Y = np.abs(rfft(data))
output from the fft: enter image description here
Now, I want to apply this formula which is the formula of the mean frequency. enter image description here
From the reference that I have read, M is the length of the frequency bin. To find P, I use this code:
power_spectrum = Y**2
and I'm still confused to calculate the value of fj. Can you guys help to correct the code above?