Episode 5: g.USBamp
Stream a g.USBamp, the wired 16-channel biosignal amplifier, with its digital trigger kept apart from the signal by role rather than by channel number.
The g.USBamp is organised as four groups of four channels, and it has a digital input that records a trigger pulse beside the data. Showing that pulse on its own scale, apart from the biosignal, is the point of this episode.
Install the
devicesextra:pip install "gpype[devices]". It bringsgtec_gds, which reaches the amplifier through the g.tec Device Service, GDS. The service has to be installed and running.Connect the amplifier over USB and switch it on. As with the g.Nautilus, only one program can hold it at a time.
Something that pulses the trigger input is useful, a stimulus program or a switch, but the example runs without.
The device opens when the node is created. sampling_rate must be one the device supports. Tying all four groups to a common ground and a common reference is the usual choice for an EEG montage; leaving them separate records electrically isolated groups, EEG in one and EMG in another. enable_trigger appends the digital input as one more channel after the acquired ones.
10 # 16 channels in four groups of four. A common ground and reference
11 # across the groups is the usual EEG montage; separate groups record
12 # electrically isolated signals, EEG in one and EMG in another.
13 # enable_trigger appends the digital input as one more channel
14 source = gp.GUSBamp(sampling_rate=256, channel_count=16,
15 enable_trigger=True,
16 common_ground=[True, True, True, True],
17 common_reference=[True, True, True, True])
The amplifier declares its acquired channels as signal and the digital input as a trigger, so two ChannelSelector nodes split the stream by role, and neither path needs to know which channel number the trigger ended up at.
19 # Split by role, not by channel number: the amplifier declares its
20 # inputs as signal and the digital input as a trigger
21 signal = gp.ChannelSelector(roles=gp.Constants.ChannelRoles.SIGNAL)
22 trigger = gp.ChannelSelector(roles=gp.Constants.ChannelRoles.TRIGGER)
The filters would leave the trigger alone in any case: they skip a channel declared a trigger. The split is for the scopes. On a microvolt scale a trigger is a flat line or a wall, so it gets a scope of its own, unfiltered. That leaves the signal path delayed by the filters’ group delay and the trigger path not; insert a Delay if the two must line up sample-accurately.
24 # The filters would skip the trigger by role anyway; the split gives
25 # each path a scope at its own scale
26 bandpass = gp.Bandpass(f_lo=1, f_hi=30)
27 notch50 = gp.Bandstop(f_lo=48, f_hi=52)
28
29 scope = gp.TimeSeriesScope(name="eeg", amplitude_limit=50,
30 time_window=10)
31 # The digital input's level depends on the amplifier's scaling and
32 # on the wiring: raise this limit if the trace rails
33 trigger_scope = gp.TimeSeriesScope(name="trigger", amplitude_limit=2,
34 time_window=10)
35
36 p.connect(source, signal)
37 p.connect(signal, bandpass)
38 p.connect(bandpass, notch50)
39 p.connect(notch50, scope)
40 p.connect(source, trigger)
41 p.connect(trigger, trigger_scope)
42 app.add_widget(scope)
43 app.add_widget(trigger_scope)
44
45 p.start()
46 app.run()
47 p.stop()
48 p.close()
Run the script. Two scopes: the biosignal, scaled for EEG, and the trigger, whose level depends on the amplifier’s scaling and on how the input is wired, so raise its limit if the trace rails and lower it if it looks flat.
In this episode, you learned how to:
stream a GUSBamp with its channel groups and digital input
split a stream by role with ChannelSelector
give a trigger its own scope and scale, apart from the filtered signal
Proceed to Episode 6, where a Keyboard marks moments in the signal.
Nodes in this episode: GUSBamp, ChannelSelector, Bandpass, Bandstop, TimeSeriesScope
File s3e5_gusbamp.py – View file on GitHub
1"""Season 3, Episode 5: a g.USBamp, its trigger on a scope of its own."""
2
3import gpype as gp
4
5if __name__ == "__main__":
6
7 app = gp.MainApp()
8 p = gp.Pipeline()
9
10 # 16 channels in four groups of four. A common ground and reference
11 # across the groups is the usual EEG montage; separate groups record
12 # electrically isolated signals, EEG in one and EMG in another.
13 # enable_trigger appends the digital input as one more channel
14 source = gp.GUSBamp(sampling_rate=256, channel_count=16,
15 enable_trigger=True,
16 common_ground=[True, True, True, True],
17 common_reference=[True, True, True, True])
18
19 # Split by role, not by channel number: the amplifier declares its
20 # inputs as signal and the digital input as a trigger
21 signal = gp.ChannelSelector(roles=gp.Constants.ChannelRoles.SIGNAL)
22 trigger = gp.ChannelSelector(roles=gp.Constants.ChannelRoles.TRIGGER)
23
24 # The filters would skip the trigger by role anyway; the split gives
25 # each path a scope at its own scale
26 bandpass = gp.Bandpass(f_lo=1, f_hi=30)
27 notch50 = gp.Bandstop(f_lo=48, f_hi=52)
28
29 scope = gp.TimeSeriesScope(name="eeg", amplitude_limit=50,
30 time_window=10)
31 # The digital input's level depends on the amplifier's scaling and
32 # on the wiring: raise this limit if the trace rails
33 trigger_scope = gp.TimeSeriesScope(name="trigger", amplitude_limit=2,
34 time_window=10)
35
36 p.connect(source, signal)
37 p.connect(signal, bandpass)
38 p.connect(bandpass, notch50)
39 p.connect(notch50, scope)
40 p.connect(source, trigger)
41 p.connect(trigger, trigger_scope)
42 app.add_widget(scope)
43 app.add_widget(trigger_scope)
44
45 p.start()
46 app.run()
47 p.stop()
48 p.close()