Hello - I’m trying to create a signal detection task. Individuals will hear white noise and need to detect if there is a tone or not. Individual detection thresholds at 75%, 50% and 25% need to be attained (it will eventually be uploaded to Pavlovia - but I’ll cross that path later).
So far I’ve kept it simple with three routines: welcome page, thresholding trial, and end screen.
In the thresholding trial I’ve uploaded the audio files separately - using the builder. I’ve added a fixation cross and text (do you hear a tone?) and a key response(press left or right). In addition to the builder components I used code.
When I use this code:
from psychopy import core, visual, event, sound
import random
Define the volume range for the tone
min_volume = 0
max_volume = 1
Define the initial step size for adjusting the volume
step_size = 0.1
Define the detection thresholds for the participant
thresholds = [0.25, 0.5, 0.75]
Create a staircase handler for each threshold
stairs =
for threshold in thresholds:
step_sizes = [step_size]*10
stair = data.StairHandler(startVal=random.uniform(min_volume, max_volume),
stepSizes=step_sizes,
nTrials=10,
nReversals=5,
nUp=1,
nDown=2,
stepType=‘lin’,
minVal=min_volume,
maxVal=max_volume,
name=‘staircase_{}’.format(threshold),
extraInfo={‘threshold’: threshold})
stairs.append(stair)
Create a loop to run the trials
for trial_num in range(60):
# Get the volume for the current trial
volume = stairs[0].next()
# Determine if the tone should be played based on the volume
if volume > 0:
tone = sound.Sound('FILEPATH', volume=volume)
correct_resp = 'left'
else:
tone = sound.Sound(value=0)
correct_resp = 'right'
# Create a loop to wait for a response
resp = None
while resp is None:
# Play the white noise and the tone
noise = sound.Sound('FILEPATH')
noise.play()
core.wait(0.5)
tone.play()
# Determine if the response was correct and update the staircase accordingly
if resp[0] == correct_resp:
corr = 1
else:
corr = -1
for stair in stairs:
if stair.extraInfo['threshold'] == thresholds[0]:
stair.addResponse(corr)
# Check if any of the staircases have reached the threshold
for stair in stairs:
if stair.extraInfo['threshold'] == thresholds[0] and stair.finished:
print('Threshold of {} reached for staircase {}'.format(thresholds[0], stair.name))
# Check if all of the staircases have finished
if all([stair.finished for stair in stairs]):
break
(FILEPATH - I use the actual path). It runs the trial on the welcome screen and freezes the computer with the white noise playing.
Any help on what’s going wrong or how I could do this task.