From f945db3563d2bc3ecf39ed4a77a2ccbe0c3ccede Mon Sep 17 00:00:00 2001
From: ofplarsen <ofplarsen@gmail.com>
Date: Thu, 27 Apr 2023 10:27:46 +0200
Subject: [PATCH] test this delay thing

---
 jitter/ BCISpeller/BCISpellerV3.py | 24 ++++++++++++++----------
 1 file changed, 14 insertions(+), 10 deletions(-)

diff --git a/jitter/ BCISpeller/BCISpellerV3.py b/jitter/ BCISpeller/BCISpellerV3.py
index 2952113..ac970b1 100644
--- a/jitter/ BCISpeller/BCISpellerV3.py	
+++ b/jitter/ BCISpeller/BCISpellerV3.py	
@@ -191,9 +191,9 @@ inlet = StreamInlet(streams_counter[0]) #LSL Eyetracker data
 inlet_2 = StreamInlet(streams_eeg[0])# LSL EEG data
 
 fs = 250  # Sampling frequency
-delay = 0.061 #Occular delay
-
-fragment_duration = 4+delay  # Fragment duration in seconds
+sync_delay = 0.061 #sync delay
+ocular_delay = 0.100 # Ocular delay
+fragment_duration = 4 + sync_delay + ocular_delay  # Fragment duration in seconds
 fragment_samples = round(fs * fragment_duration)
 
 
@@ -218,8 +218,9 @@ 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):
-            if(buffer[fragment_samples - round(delay * fs)-1][0] != (fragment_samples-round(delay * fs))):
+        if (len(buffer) == fragment_samples) and buffer[0][round(ocular_delay*fs)] == 1 and buffer[0][fragment_samples-round(sync_delay * fs)] != 0:
+            # This prob not working :P
+            if(buffer[fragment_samples - round(sync_delay * fs)-1][0] != (fragment_samples-round(sync_delay * fs))):
                 print("Found invalid stare")
                 continue
 
@@ -250,9 +251,12 @@ while True:
             print("--- Filter time:  %s seconds ---" % (time.time() - start_time))
             print(df['N'].tolist())
 
+            df['N'] = df['N'].shift(-round(ocular_delay * fs))
+
+
             # If any delay added, shift signal accordingly
-            df['N'] = df['N'].shift(round(delay*fs))
-            df = df.iloc[round(delay*fs):]
+            df['N'] = df['N'].shift(round(sync_delay * fs))
+            df = df.iloc[round(sync_delay * fs):]
             # Reset the index
 
             df = df.reset_index(drop=True)
@@ -276,9 +280,9 @@ while True:
                 X_c, Y_c = ca.transform(X, Y)
                 # Uses two coefficients pk = sqrt(p1**2+p2*'2)
                 p1 = np.corrcoef(X_c[:, 0], Y_c[:, 0])[0][1]
-                #freqs.append(p1)
-                p2 = np.corrcoef(X_c[:, 1], Y_c[:, 1])[0][1]
-                freqs.append(np.sqrt(p1 ** 2 + p2 ** 2))
+                freqs.append(p1)
+                #p2 = np.corrcoef(X_c[:, 1], Y_c[:, 1])[0][1]
+                #freqs.append(np.sqrt(p1 ** 2 + p2 ** 2))
             cca = freqs
             #print("CCA single: " + str(perform_cca(df,1)))
             print(cca)
-- 
GitLab