alexandrebarachant / muse-lsl

Python script to stream EEG data from the muse 2016 headset
BSD 3-Clause "New" or "Revised" License
629 stars 184 forks source link

Adaptive timestamp correction #101

Closed alexandrebarachant closed 3 years ago

alexandrebarachant commented 5 years ago

This PR implement the adaptive timestamp correction described in https://arxiv.org/pdf/1308.3846.pdf (i used the least square estimator).

I need to perform further testing, but it should fix #99 @HashemiScience can you git it a try ?

alexandrebarachant commented 5 years ago

Okay, i did some optimization and measurement by injecting a signal on the auxiliary channel and estimating the delay between the signal and the markers. this is what we usually refer as hardware tagging.

here are the results with the original code and without the offline dejittering :

image

We can see a pretty strong case of drift.

and with this PR :

image

basically no drift and an offset close to 0 (i optimized how we measure the time correcponding to the first EEG sample received.)

So to me this looks good, and we might want to do the same for PPG and other sensors.

@jdpigeon what do you think ?

xloem commented 3 years ago

I've merged this into https://github.com/xloem/muse-lsl .

[EDIT: but it breaks streaming, so I'm debugging it. [debugging notes: muse.last_timestamp is negative. it seems to decrease steadily; makes sense because reg_params[1] is negative. the slope is getting inverted in the first call to _update_timestamp_correction.] It looks like the issue is because the 5th timestamp channel is still zero for me. It seems when taking the minimum zero values should be excluded.]

EDIT 2: We've fixed the encountered issue and submitted a PR to this branch. Most of the other PRs are merged together with our fix at https://github.com/xloem/muse-lsl/tree/dev , but that tree still needs others to test it. What would help people have more capacity and access for pull request maintenance, merging, testing?