How can I extract the time length (in miliseconds) between two audio signals?
33 views (last 30 days)
Show older comments
I have a psychology experiment paradigm which asks participants to give a verbal response immediately after they hear a beep sound. Participants may or may not respond to the beep, and their response could be quick or slow. I need to extract the time length between the end of the beep sound and the start of their verbal response. Such time length should be measured in miliseconds as the total time allowed for each response was 3 seconds (3000 ms). There are hundreds of trials so I would like to find a way to do the extraction automatically. How should I achieve this? Carload thanks to any suggestions!

2 Comments
Walter Roberson
44 minutes ago
I recommend using the third-party Psychtoolbox for this kind of work.
Answers (2)
Star Strider
about 23 hours ago
Considering the nature of this problem, probably the best option is to estimate the signal envelops with the Signal Processing Toolbox envelope function (use the 'peak' option with an appropriate window), decide on a threshold, and measure the time the envelope crosses the threshold.
It may be necessary to use a filter to eliminate noise. If you are using the lowpass function (or any of its friends) for this, use the ImpulseResponse='iir' name-value pair for best results.
This approach as worked for me in the past.
It will probably be necessary to experiment to get the result you want.
2 Comments
Star Strider
about 5 hours ago
My pleasure!
I would not use the peak values, however you need to use the 'peak' option in your envelope call. If you want to know when the voice response begins, set a threshold and then determine the time the voice response envelope (I use the upper envelope here) first crosses that threshold.
Try something like this --
Fs = 44100; % Sampling Frequency (z)
L = 5;
t = linspace(0, Fs*L, Fs*L+1).'/Fs;
ts = seconds(t); % Time Vector ('duration' Here)
s = randn(size(t)) .* exp(-(t-2.2).^2*10); % Voice Response Signal
[et,eb] = envelope(s, 1000, 'peak'); % Use 'peak' Option
thrshld = 0.25; % Detection Threshold Value
tidx = find(diff(sign(et - thrshld))); % Approximate Indices of Threshold Crossing
idxrng = tidx(1)+[-1 0 1]; % Index Range For Interpolation
t_exact = interp1(et(idxrng), ts(idxrng), thrshld); % 'Exact" Value Of Upper Envelope Crossing Threshold Value
fprintf('\nResponse envelope crosses detection threshold level at %.3f seconds\n', seconds(t_exact))
figure
plot(ts, s, DisplayName='Response Signal')
hold on
plot(ts, [et eb], LineWidth=2, DisplayName="Envelope")
hold off
grid
xlabel("Time (s)")
ylabel("Amplitude")
yline(thrshld, '--k', "Detection Threshold", DisplayName='Detection Threshold')
xline(t_exact, '-.r', "Response Onset Time", DisplayName="Response Onset Time")
text(t_exact, 1.5, sprintf('%.3f s \\rightarrow',seconds(t_exact)), Horiz='right')
legend(Location='best')
.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!