Skip to content

Commit

Permalink
added an LSL stream that streams the EEG band power values
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusKlug committed Jul 4, 2023
1 parent e42610a commit 2fc4104
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions ixr_flow/gui/ixrdashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,18 @@ def __init__(self, board_shim: BoardShim, reference: str = 'none', display_ref:
# LSL stream
name = 'BrainPower'
logging.info(f"Starting '{name}' Power Metric stream.")
info_transmit = StreamInfo(name=name, type='IXR-metric', channel_count=1,
info_transmit = StreamInfo(name=name, type='IXR-metric', channel_count=1, nominal_srate=20.0,
channel_format=cf_double64, source_id='ixrflow_transmit_power')
self.outlet_transmit = StreamOutlet(info_transmit)
logging.info(f"'{self.outlet_transmit.get_info().name()}' Power Metric stream started.")

name = 'SpectralPower'
logging.info(f"Starting '{name}' stream.")
info_transmit_spectrum = StreamInfo(name=name, type='IXR-metric', channel_count=5, nominal_srate=20.0,
channel_format=cf_double64, source_id='ixrflow_transmit_spectral_power')
self.outlet_transmit_spectrum = StreamOutlet(info_transmit_spectrum)
logging.info(f"'{self.outlet_transmit_spectrum.get_info().name()}' Power Metric stream started.")

def run(self):
self.app = QtGui.QApplication([])
self.win = pg.GraphicsWindow(title='IXR-flow', size=(1500, 1000))
Expand Down Expand Up @@ -459,18 +466,19 @@ def lowpass(data, fs, cutoff):
engagement_idx += (beta / (theta + alpha)) / gamma # divided by gamma to reduce power also during strong muscle activity
inverse_workload_idx += (alpha / theta) / gamma

avg_bands = [int(x / len(self.eeg_channels)) for x in avg_bands] # average bands were just sums

if len(bad_channels)!=4:
engagement_idx = engagement_idx / (4-len(bad_channels))
inverse_workload_idx = inverse_workload_idx / (4-len(bad_channels))

# only use valid scores to scale and calibrate
self.engagement_calib.append(engagement_idx)
self.inverse_workload_calib.append(inverse_workload_idx)

avg_bands = [x / (4-len(bad_channels)) for x in avg_bands] # average bands were just sums
else:
engagement_idx = 0
inverse_workload_idx = 0
avg_bands = [0,0,0,0,0]

# limit lengths of history and calib
if len(self.engagement_calib) > self.calib_length:
Expand Down Expand Up @@ -527,5 +535,6 @@ def lowpass(data, fs, cutoff):

#print(self.power_metrics[0])
self.outlet_transmit.push_sample([self.power_metrics[0]])
self.outlet_transmit_spectrum.push_sample(avg_bands)

self.app.processEvents()

0 comments on commit 2fc4104

Please sign in to comment.