yasa icon indicating copy to clipboard operation
yasa copied to clipboard

question about sw_slope in sw_detect

Open ChinHui-Chen opened this issue 5 months ago • 2 comments

Hi,

I was trying to duplicate slow wave detection (sw_detect) function.

https://github.com/raphaelvallat/yasa/blob/f76f63541ae1dc10e645cdb9be9fa4b0f5eadda5/src/yasa/detection.py#L1762C1-L1763C58

I'm wondering whether the sw_slope calculation is correct. Since sw_ptp is measured from the negative peak to the positive peak, I think the denominator should be sw_idx_pos - sw_idx_neg instead of sw_midcrossing - sw_idx_neg?

ChinHui-Chen avatar Jul 14 '25 03:07 ChinHui-Chen

Thanks for opening the issue. You are right that the current implementation does not match what is written in the doc:

Slope between NegPeak and MidCrossing

https://github.com/raphaelvallat/yasa/blob/v0.6.5/docs/pictures/slow_waves.png

The calculation should be adjusted to use the amplitude of the negative half-wave instead of the peak-to-peak amplitude.

raphaelvallat avatar Jul 23 '25 20:07 raphaelvallat

I have added a PR #220 to fix this issue.

ChinHui-Chen avatar Oct 22 '25 20:10 ChinHui-Chen