Audio triggers for EEG system
26 次查看(过去 30 天)
显示 更早的评论
I have 3 scripts that generate 3 different audio files. Each 3 seconds long, with 1 containing white noise in the background and a pulse stimulus, 1 containing white noise in the background and a short pause/gap in the noise, and then the 3rd contains both the gap and the pulse.
I then have a 4th script that combines these 3 audio files and randomly repeats them as a continuous 8 minute sound file.
I want to add triggers to this so that if I play this audio file while connected to an EEG system triggers will appear to identify the timepoints that each of these individual files occur within the full 8 minute file. The triggers will be sent via a parallel port.
Does anyone know the best way to do this?
Can matlab distinguish the changes in db? I was going to time-lock a trigger to each file but there is a jitter in the 8-minute file so I don’t think this would work.
2 个评论
Taylor
2024-5-17
MATLAB can most likely distinguish changes in the audio signal (depending on how large of a spike in amplitude the pulse is). Does your amplifier have and analog or audio in? It might just be easier to split your audio signal into this channel so it is time-synced with the EEG data by your recording system. Then you can process it in post to determine the exact timestamps of the pulses/gaps.
回答(1 个)
Ayush
2024-9-3
Hi Nathan,
I understand that you can successfully transmit trigger signals to the EEG system but are encountering challenges with synchronizing these signals with the audio player.
A potential solution is the "two-pointer" algorithm. In this method, one pointer tracks the audio timestamps while the other tracks the stimulus timestamps. This can help ensure that both processes are aligned effectively. This can be achieved by using “tic-toc” functions.
For further clarification, please refer to the code provided below.
% you can replace it with actual data
data = [time_points, stimulus_labels];
[audioData, fs] = audioread('your_audio_file.wav');
audioPlayer = audioplayer(audioData, fs);
play(audioPlayer);
% store the start time of the audio
startTime = tic;
% you can replace it with your actual trigger sending function
sendtrigger = @(trg, port) fprintf('Sending trigger %d to port %d\n', trg, port);
port = BioSemiSerialPort();
ioObj=[]
% if no hardware device is present, alternatively, you can define the port
% and ioObj in a similar way as you did in your code
port = hex2dec('3FB8'); % windows 10
ioObj = io64; %64 bit OS
% Iterate through the time points and stimuli
for i = 1:size(data, 1)
% Get the time point and stimulus
timePoint = data(i, 1);
stimulus = data(i, 2);
% Calculate the delay
delay = timePoint - toc(startTime); % Time to wait until the trigger should be sent
% Wait until it's time to send the trigger
pause(max(0, delay));
% Send the trigger
sendtrigger(stimulus, port);
end
% Ensure that the audio playback is completed
while isplaying(audioPlayer)
% can do additional checks or operations concurrently using similar
% approach as used above
end
stop(audioPlayer);
For further information, you can refer to the following documentation of “tic” and “toc” functions: https://www.mathworks.com/help/matlab/ref/tic.html
Hope it helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 EEG/MEG/ECoG 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!