Implementation details🔗

Processing🔗

The StreamLSL and EpochsStream object support processing in real-time of their internal buffers. The processing is done sequentially and this page presents the available processing and their application order.

StreamLSL🔗

Processing is applied to new samples available in the StreamInlet before rolling the buffer of the StreamLSL object and adding those new processed samples to it. The processing is defined in the private _acquire method of the class StreamLSL, method called by the background acquisition thread (automatic acquisition) or by the method mne_lsl.stream.StreamLSL.acquire() (manual acquisition).

  1. Add channels that were added with mne_lsl.stream.StreamLSL.add_reference_channels(). The channels are added as an array of zeros at the end of the buffer along the channel axis.

  2. Apply the rereferencing schema requested with mne_lsl.stream.StreamLSL.set_eeg_reference().

  3. Apply filters added with mne_lsl.stream.StreamLSL.filter() and mne_lsl.stream.StreamLSL.notch_filter(). The filters are applied one at a time, in the order they were added.

Stream processing flowchart

EpochsStream🔗

Processing is applied to new events and samples available to a EpochsStream before rolling the buffer of the EpochsStream object and adding new epochs to it. The processing is defined in the private _acquire method of the class EpochsStream, method called by the background acquisition thread (automatic acquisition) or by the method mne_lsl.stream.EpochsStream.acquire() (manual acquisition); and in the private _process_data function which operates on the newly acquired data array of shape (n_epochs, n_samples, n_channels).

Note

MNE-Python offers similar processing to a Raw and Epochs object. However, mne-lsl differs in this regard by offering some processing at the StreamLSL level and some at the EpochsStream level. For instance, filters are applied to a StreamLSL object while baseline correction is applied to a EpochsStream object.

  1. Select which events are new since the last acquisition and which events are retained. For instance, an event too close to the end of the buffer is discarded for now since it is not possible to cut an entire epoch from it. This event will be acquired and added to the buffer as soon as it will be possible to cut an entire epoch from it.

  2. Process the newly acquired data array of shape (n_epochs, n_samples, n_channels).

    1. Apply PTP and flatness rejection defined by the arguments reject, flat, reject_tmin and reject_tmax.

    2. Apply baseline correction defined by the arguments baseline, tmin and tmax.

    3. Apply detrending defined by the argument detrend.

Stream processing flowchart