sccn / lsl_archived

Multi-modal time-synched data transmission over local network
242 stars 134 forks source link

Receive 2 or more streams in Python with different sampling rates #283

Open BCIstorm opened 6 years ago

BCIstorm commented 6 years ago

I'm trying to receive at least two streams with different sampling frequencies:

What is the best way to do this in Python and save to a file for an offline analysis?

cboulay commented 6 years ago

You can save them to an xdf file with LabRecorder.

If you also need real-time access in Python then you'll have to be more specific about what you want to do before we can offer advice on "the best way". i.e. real-time visualization is different than synchronizing the streams and finding EEG features that correlate with eye movements.

BCIstorm commented 6 years ago

Thank you @cboulay , I tryed LabRecorder (pre-compiled binary) and I guess it works (how do one knows if the sync is correct?). But then I need a xdf viewer (used SigViewer from https://github.com/cbrnr/sigviewer) or a Python script like this https://github.com/sccn/xdf I would like to have as few dependencies as possible.

For now, I just want to synchronize the streams, save them to a file to do some post-processing. But, eventually I'd like to have access to real-time visualization.

dmedine commented 6 years ago

Synchronization happens when the xdf data is loaded (either in Python or in Matlab) https://github.com/sccn/xdf.

Then, you can visualize your data using scipy or matlab. Online synchronization has to be done at the code level. When you create an inlet, you can give it flags that will tell it to perform online clock offset removal and de-jittering of the incoming data's timestamps. https://github.com/sccn/labstreaminglayer/blob/master/LSL/liblsl/include/lsl_cpp.h#L71-L82

On 4/5/2018 2:16 PM, BCIstorm wrote:

Thank you @cboulay https://github.com/cboulay , I tryed LabRecorder (pre-compiled binary) and I guess it works (how do one knows if the sync is correct?). But then I need a xdf viewer (used SigViewer from https://github.com/cbrnr/sigviewer) or a Python script like this https://github.com/sccn/xdf I would like to have as few dependencies as possible.

For now, I just want to synchronize the streams, save them to a file to do some post-processing. But, eventually I'd like to have access to real-time visualization.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/283#issuecomment-378916116, or mute the thread https://github.com/notifications/unsubscribe-auth/ADch7uF_bwUbUXYFlk0LnBR_2-PBYKr1ks5tlgs4gaJpZM4THNQt.

dmedine commented 6 years ago

...and there is also a pretty good matlab based signal viewer https://github.com/sccn/labstreaminglayer/tree/master/Apps/MATLABViewer

On 4/5/2018 2:16 PM, BCIstorm wrote:

Thank you @cboulay https://github.com/cboulay , I tryed LabRecorder (pre-compiled binary) and I guess it works (how do one knows if the sync is correct?). But then I need a xdf viewer (used SigViewer from https://github.com/cbrnr/sigviewer) or a Python script like this https://github.com/sccn/xdf I would like to have as few dependencies as possible.

For now, I just want to synchronize the streams, save them to a file to do some post-processing. But, eventually I'd like to have access to real-time visualization.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/283#issuecomment-378916116, or mute the thread https://github.com/notifications/unsubscribe-auth/ADch7uF_bwUbUXYFlk0LnBR_2-PBYKr1ks5tlgs4gaJpZM4THNQt.

BCIstorm commented 6 years ago

Thank you @dmedine , but I'm using Python, do not want to use Matlab now.

BCIstorm commented 6 years ago

@dmedine de-jittering is an average filter right? I want to do my own post-processing.

So, going to my first question, what's the best way, I mean, should I create an inlet for each stream and pull a sample from each one in alternate ways? Or pull a chunk? And what would be the the synchronization error?

cboulay commented 6 years ago

@BCIstorm Take a look at NeuroPype as that already does everything you need. They have a free academic version.

I suspect I have a lot more experience working with these kinds of tools than you do so please strongly consider my recommendation to stick to established file formats and tools that work with those formats. If not xdf, then something else, but with xdf you already have a tool to save LSL streams to disk.

As for your other questions, we've already offered established solutions, but then you say "I want to do it my own way, how do I do that?" I think for someone intent on doing it their own way, the only advice I can give is to read the source code and learn from those examples.

I will answer one question specifically because, though it has come up multiple times in previous issues, it is not in example code. The easiest way (but maybe not best, depending on the application) to receive data from multiple streams is to pull_chunk from each stream with a timeout of 0 then copy the received data for each stream into its own local buffer. On some iterations you will get a few samples for Stream A, a few more for stream B; on other iterations you might get no samples for A and many for B. You have to be flexible to that.

dmedine commented 6 years ago

The de-jittering routine uses linear regression.

On 4/5/2018 3:02 PM, BCIstorm wrote:

@dmedine https://github.com/dmedine de-jittering is an average filter right? I want to do my own post-processing.

So, going to my first question, what's the best way, I mean, should I create an inlet for each stream and pull a sample from each one in alternate ways? Or pull a chunk? And what would be the the synchronization error?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sccn/labstreaminglayer/issues/283#issuecomment-378928038, or mute the thread https://github.com/notifications/unsubscribe-auth/ADch7hPI7KP2OgwWxwXrf_3KhpIFCOLeks5tlhXwgaJpZM4THNQt.

Maryada-27 commented 6 years ago

How to use LabRecorder for ubuntu?

cboulay commented 6 years ago

Hi @Maryada-27 Your question is unrelated to this issue. Please ask your question in a new issue, or you can even try to get one of us in real time in the Slack channel (see README for link).

Be sure to include lots of information. What version of Ubuntu? What do you mean "use"? Are you trying to compile it, or is it already compiled and you just want to know how it works?