Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply dejittering / sychronization to several streams at once #57

Open
tstenner opened this issue Nov 29, 2019 · 1 comment
Open

Apply dejittering / sychronization to several streams at once #57

tstenner opened this issue Nov 29, 2019 · 1 comment

Comments

@tstenner
Copy link
Contributor

Some devices (case in point: the BrainAmps) record a digital trigger alongside the EEG data and offer three options to send the markers:

  1. as an additional channel in the EEG stream converted to whatever data type the EEG data has
  2. as a continouous int8 / int16 / string stream with the same sampling rate as the EEG stream
  3. as a separate, irregular int8 / int16 / string stream

The procedure is as follows (pseudocode, but probably also valid python):

data, triggers, first_timestamp = device.get_chunk()
trigger_indices = triggers.find()
data_outlet.push(data, first_timestamp)
trigger1_outlet.push([data; triggers], first_timestamp)
trigger2_outlet.push(triggers, first_timestamp)
trigger3_outlet.push(triggers[trigger_indices], first_timestamp + trigger_indices / sampling_rate)

Both for resource usage and usability, 3 is the best option but irregularly sampled stream can't be dejittered so the markers aren't as reliable as they should be.

But, as seen in the example above, the timestamps have the same jitter and time offsets so if it were possible to copy dejitter / synchronization parameters from one stream to another the third option would be feasable for offline analysis.

@agricolab
Copy link
Member

agricolab commented Nov 30, 2019

Are you certain that the markerstream under option 3 has the same jitter as the datastream?
Would the following approach to align a marker of type 3 with the data work?

for marker, tstamp in zip(marker["time_series"], marker["time_stamps"]:
    idx = np.argmin(np.abs(tstamp-data["time_stamps"]))

even if the data stream is dejittered and synchronized, the sample-index should not be affected as long as data arrived in order.

I do it similarly here: https://github.com/agricolab/xdf-Python/blob/sync_timestamps/pyxdf/pyxdf.py#L864 or

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants