pause() function is inaccurate
Mostrar comentarios más antiguos
Dear MATLAB,
Using a function to produce a series of auditory click trains. It does produce the click trains, but the matlab pause() function is inaccurate. it reports (roughly) 4 seconds but the duration is in fact more like 2 seconds. Below is the pasted code...
*****************************************
close all; clear; clc;
% [train, t, fs] = hb_clickTrain( frq, dura, width, fs, plotOption )
[train, t, fs] = hb_clickTrain(40,2,0.001,48000,1);
trials = 5;
tstamp = zeros(trials,6);
for ci = 1:trials
sound(train,fs)
c= clock;
tstamp(ci,:,:,:,:,:,:) = c;
tic
pause(4)
toc
end
**************************************
I hear roughly 2 seconds of pause, but matlab prints out and saves...
Elapsed time is 4.005545 seconds.
Elapsed time is 4.003628 seconds.
Elapsed time is 4.003640 seconds.
Elapsed time is 4.007986 seconds.
Elapsed time is 4.013071 seconds.
Any advice is greatly appreciated!
Thanks in advance,
Joanne
(is there an alternative to the pause function?)
Respuesta aceptada
Más respuestas (1)
Bruno Luong
el 10 de Ag. de 2022
Editada: Bruno Luong
el 10 de Ag. de 2022
The accuracy is documented.
"The accuracy of the pause function is subject to the scheduling resolution of your operating system, and to other concurrent system activity. The accuracy is not guaranteed, and finer resolution results in higher relative error."
If you want better accuracy,just use tic toc
t1 = tic;
while toc(t1) <= 4
pause(0);
end
toc(t1)
t1 = tic;
while toc(t1) <= 4
end
toc(t1)
This is however will take spin the CPU.
NOTE: the accuracy is better on my PC (Elapsed time is 4.000097 seconds.) than on online server
1 comentario
Joanne Hall
el 10 de Ag. de 2022
Categorías
Más información sobre Audio and Video Data en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!