paulvangentcom / heartrate_analysis_python

Python Heart Rate Analysis Package, for both PPG and ECG signals
MIT License
959 stars 322 forks source link

spectral.py user warning #31

Closed sedurCode closed 5 years ago

sedurCode commented 5 years ago

When using heartpy v1.2.4 with python v3.7.4 on Windows 64bit to analyse heart rate from PPG data with the hp.process_segmentwise method I get the following warning from scipy\signal:

..\spectral.py:1969: UserWarning: nperseg = 100000 is greater than input length = 38779, using nperseg = 38779 .format(nperseg, input_length))

Interestingly I get this warning on about 80% of the returns, not all of them. My data is roughly half an hour long, my sample rate is 204.8Hz and my function call is as follows: working_data, measures = hp.process_segmentwise(matlabdata, sample_rate=fs, segment_width = 40, segment_overlap = 0.25, calc_freq=True, reject_segmentwise=True, report_time=True)

paulvangentcom commented 5 years ago

Hi Simon,

Yes I saw that pop up from time to time. I'll look into exactly what's causing it. It's probably coming from the FFT or Periodogram computations in Scipy.

Your analysis should still finish normally, right?

sedurCode commented 5 years ago

Hi Paul, Output of your tool looks sensible for all the segments I have looked at using the visualisations exported using the plot_segment tool. However, I haven't attempted to prod the code further to see if I get the correct output behaviour.

Would be nice to use power-of-2 sized arrays for spectral analysis by default though! Great tool by the way, lets see if you do a much better job that the thing packaged with the shimmer matlab tools I have been using.

paulvangentcom commented 5 years ago

If the warning has any effect on output measures (I don't suspect it has), it should only be on frequency domain measures. HR and HRV measures are unaffected.

Thanks, I started developing this because I couldn't find a good open source toolkit myself : ). If you are missing some functionality feel free to let me know.

paulvangentcom commented 5 years ago

The spectral warning resulted from me setting an incorrect window size for Welch's method in the frequency spectrum computation. It is fixed in a6c4732954a78aee24839a71a63e00c4abecd806

You now get the PSD back as a power of two array as requested. This is common practice so making it the default option makes sense. See e1dc5439b705254285e6630cc07b808408ef56cb