I am a beginner in Psychopy and I am writing a script with Psychopy to conduct an EEG experiment.
In this experiment I need to record the time that since the trial start until the participant presses the key enter. I do it in two ways. First, I record the computer time when the trial starts and when the trial ends by using the command clock.getTime(), and then subtract each other.
On the other hand, I also send a trigger to the EEG system when the trial starts and when the trial ends by using the command parallel.setData(). Then, I subtract the two recorded EEG trigger latency of the triggers from each other.
My issue is that the two calculated timing differ in around 2% (not in an absolute amount like 50ms but proportional to the length of time). Did anyone encounter similar issue in here and would like to share some tips on how to solve that? Thanks very much in advance in reading this post!
The exact codes that I wrote were as follows:
while not event.getKeys(keyList=['space']) and num_steps < 181:
# Sending out the ERP Trigger in Biosemi system and record the start time
if num_steps == 0:
if EEG:
parallel.setData(1)
start_time = clock.getTime()
# Draw the clock face
clock_face.draw()
# Draw the clock ticks with draw Uing autodraw will make the clock hand not being displayed
tick_0.draw()
number_0.draw()
tick_1.draw()
number_1.draw()
tick_2.draw()
number_2.draw()
tick_3.draw()
number_3.draw()
tick_4.draw()
number_4.draw()
tick_5.draw()
number_5.draw()
tick_6.draw()
number_6.draw()
tick_7.draw()
number_7.draw()
tick_8.draw()
number_8.draw()
tick_9.draw()
number_9.draw()
tick_10.draw()
number_10.draw()
tick_11.draw()
number_11.draw()
# Calculate the coordinates of the clock hand
second_hand_x = clock_center[0] + second_hand_length * math.cos(second_rotation_angle_Libet)
second_hand_y = clock_center[1] + second_hand_length * math.sin(second_rotation_angle_Libet)
# Draw the clock hand
second_hand = visual.Line(win, start=clock_center, end=(second_hand_x, second_hand_y), lineWidth=second_hand_width,
lineColor=clock_hand_color)
second_hand.draw()
# Update the display window
win.flip()
# update the number of frames
num_steps = num_steps + 1
# Wait for the update interval
core.wait(update_interval)
# Update the rotation angle of the clock hand for the next frame
random_number_Libet = (random_number_Libet + 1) #update the position of the clock hand to the next position
second_rotation_angle_Libet = math.radians(-random_number_Libet * 6 + 90) # 360 degrees per 60 seconds, start from 12 o'clock
# Sending out the ERP Trigger after keypress
if EEG:
parallel.setData(0)
if num_steps < 181 and choice == ['y']: :
parallel.setData(11) # 11
elif num_steps > 180 and choice == ['n']:
parallel.setData(13) # 13
else:
parallel.setData(15) # 15
# record the final wait_time
final_wait_time = clock.getTime() - start_time