From af6957a27b4f40d6aa7ac87396f80a19912e4923 Mon Sep 17 00:00:00 2001 From: "William G. Tresselt" <williagt@stud.ntnu.no> Date: Fri, 21 Apr 2023 10:16:06 +0200 Subject: [PATCH] Added failsafe for speller, will only take as much data as duration says --- jitter/ BCISpeller/BCISpellerV2.py | 11 ++++++++--- jitter/ BCISpeller/BCISpellerV3.py | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/jitter/ BCISpeller/BCISpellerV2.py b/jitter/ BCISpeller/BCISpellerV2.py index 4db3185..8db937e 100644 --- a/jitter/ BCISpeller/BCISpellerV2.py +++ b/jitter/ BCISpeller/BCISpellerV2.py @@ -12,6 +12,8 @@ channels = ['Fp1', 'Fz', 'F3', 'F7', 'F9', 'FC5', 'FC1', 'C3', 'T7', 'CP5', 'CP1 removed_channels = ['Fp1', 'F8', 'F7', 'Fp2', 'F3', 'F4'] #frequencies_main = [4,5,6,7,9,11] frequencies_main = [4,5,5.5,6,7,7.4] +#frequencies_main = [8.18,9,10,11.25,12.86,15] + frequencies = ['8.18_sin_h1','8.18_cos_h1','8.18_sin_h2','8.18_cos_h2','8.18_sin_h3','8.18_cos_h3', '9_sin_h1', '9_cos_h1','9_sin_h2', '9_cos_h2','9_sin_h3', '9_cos_h3', '10_sin_h1','10_cos_h1','10_sin_h2','10_cos_h2','10_sin_h3','10_cos_h3', @@ -141,8 +143,11 @@ while True: # If buffer is filled with data ready to be compared in CCA, and the start of the buffer is the start of # the Eye Tracking data (Eye Tracking trigger) - if (len(buffer) == fragment_samples) and buffer[0][0] == 1 and buffer[0][fragment_samples-round(delay*fs)] != 0: - print(len(buffer)) + if (len(buffer) == fragment_samples) and buffer[0][0] == 1: + if (buffer[fragment_samples - round(delay * fs) - 1][0] != (fragment_samples - round(delay * fs))): + print("Found invalid stare") + continue + fragment = np.array(buffer[:fragment_samples]) fragment_eeg = np.array(buffer_eeg[:fragment_samples]) @@ -151,7 +156,7 @@ while True: # Makes both streams to a single dataframe df = pd.concat([pd.DataFrame(np.array(fragment)), pd.DataFrame(np.array(fragment_eeg))], axis=1, join='inner') - + df.columns = ['N'] + channels # If any delay added, shift signal accordingly df['N'] = df['N'].shift(round(delay * fs)) df = df.iloc[round(delay * fs):] diff --git a/jitter/ BCISpeller/BCISpellerV3.py b/jitter/ BCISpeller/BCISpellerV3.py index b4edb80..2952113 100644 --- a/jitter/ BCISpeller/BCISpellerV3.py +++ b/jitter/ BCISpeller/BCISpellerV3.py @@ -17,6 +17,7 @@ removed_channels = ['Fp1', 'F8', 'F7', 'Fp2', 'F3', 'F4'] #The frequencies used for the SSVEP speller #frequencies_main = [4,5,6,7,9,11] frequencies_main = [4,5,5.5,6,7,7.4] +#frequencies_main = [8.18,9,10,11.25,12.86,15] #The channels used for the BCI Speller combined with CCA occ_channels = ['O1', 'O2', 'Oz', 'P3', 'P4', 'Pz', 'P7', 'P8'] @@ -216,8 +217,12 @@ while True: # If buffer is filled with data ready to be compared in CCA, and the start of the buffer is the start of # the Eye Tracking data (Eye Tracking trigger) - if (len(buffer) == fragment_samples) and buffer[0][0] == 1 and buffer[0][fragment_samples-round(delay*fs)] != 0: - print(len(buffer)) + + if (len(buffer) == fragment_samples) and (buffer[0][0] == 1): + if(buffer[fragment_samples - round(delay * fs)-1][0] != (fragment_samples-round(delay * fs))): + print("Found invalid stare") + continue + fragment = np.array(buffer[:fragment_samples]) fragment_eeg = np.array(buffer_eeg[:fragment_samples]) triggered = True -- GitLab