raphaelvallat / yasa

YASA (Yet Another Spindle Algorithm): a Python package to analyze polysomnographic sleep recordings.
https://raphaelvallat.com/yasa/
BSD 3-Clause "New" or "Revised" License
417 stars 113 forks source link

Detecting sleep spindles #46

Closed apoorva6262 closed 2 years ago

apoorva6262 commented 2 years ago

Hi,

I preprocessed the sleep data which was in .edf format in MNE. I changed the channel names in accordance to 1020 montage on MNE and saved it as .set file. I am currently interested in detecting sleep spindles in the n2, n3 and rem phase for c3 and c4 channel. I used the function spindles _detect and got this error (image below). Is it because the data is not getting converted to the right units ?

Screenshot 2021-11-04 at 12 47 48

Thanks, Apoorva.

raphaelvallat commented 2 years ago

Hi @apoorva6262,

Most likely this is because the data is in Volts (which is the default in MNE), when it should be in microVolts. You can solve this by doing:

sig *= 1e6  # Multiply signal in-place by a million

Hope this helps, Raphael

apoorva6262 commented 2 years ago

@raphaelvallat , thanks that worked. I see that it prints the number of rows which represents the number of spindles . How do you get an average of the "duration" for the total number of spindles ?

Also there is a slight difference between pre-filtering the data and then running spindle detection vs spindle detection only. For example, pre-filtering the signal at 10-15hz and then run spindle detection vs spindle detection only at 10-15hz. How is that different ?

raphaelvallat commented 2 years ago

Hi @apoorva6262,

1) To see average spindles parameters, aggregated by channel and sleep stage (if you specify an hypnogram)

sp = yasa.spindles_detect(...)
sp.summary(grp_chan=True, grp_stage=True)

2) You should NOT filter your data in the sigma band prior to running the spindles detection. Indeed, YASA needs the full broadband signal (e.g. 0.5-30 Hz) to calculate the relative sigma power:

https://github.com/raphaelvallat/yasa/blob/1f83229b6b8315885a51ddb08bbd60e54d40b61c/yasa/detection.py#L615-L627

Thanks, Raphael