Why pause(eps) takes much time?

13 views (last 30 days)
Gun-min Kim
Gun-min Kim on 12 Aug 2012
Hello !
My program is utilizing Matlab and Simulink for real-time music signal processing.
The structure of Matlab code is as follows :
while (k<= maximum_iteration)
set_param('simulink', 'simulationcommand', 'pause');
pause(eps); % for update variable from simulink to matlab worksapce
set_param('simulink', 'simulationcommand', 'continue');
if( conditions on variable from simulink workspace )
signal processing;
end
tic;
pause(eps); % (A)
toc;
k = k+1;
end
The purpose of my program is for processing signal of length 0.1s in real-time.
I put 'pause command' in part (A) since if that part is missing, the while-loop is excuted infinitely.
And execution time for part (A) is really variable like follows :
Elapsed time is 0.125663 seconds. Elapsed time is 0.137812 seconds. Elapsed time is 0.019411 seconds. Elapsed time is 0.210091 seconds. Elapsed time is 0.125145 seconds. Elapsed time is 0.004557 seconds. Elapsed time is 0.126217 seconds. Elapsed time is 0.003950 seconds. Elapsed time is 0.125991 seconds.
As I know, pause(eps) should take only eps time. But it takes much more time than eps. Can you guess how I can reduce that time? Because it makes program much slower.
If you give me any comments related to this, I really appreciate your help.
Thank you.

Answers (3)

Azzi Abdelmalek
Azzi Abdelmalek on 12 Aug 2012
Edited: Azzi Abdelmalek on 12 Aug 2012
if the speed of your Laptop is 177,730 MIPS at 3.33 GHz hhttp://en.wikipedia.org/wiki/Instructions_per_second, that means the instruction "pause" takes at least 1/(177,730*1000000) sec to be executed. eps=2.2204e-16 which is very small. then your code can't be paused during eps. the minimum time of pause will be 1/(177,730*1000000) sec. the sampling frequency of your application can't be superior to the frequency of your processor

Tom
Tom on 12 Aug 2012
Edited: Tom on 12 Aug 2012
It's just a limitation of the function- see the pause documentation: http://www.mathworks.com/help/techdoc/ref/pause.html?nocookie=true
"pause(n) pauses execution for n seconds before continuing, where n can be any nonnegative real number. The resolution of the clock is platform specific. A fractional pause of 0.01 seconds should be supported on most platforms."

Walter Roberson
Walter Roberson on 12 Aug 2012
The underlying implementation of pause() uses timers that are much coarser than eps() . The time for pause() should never be expected to be exact: at the best of times the time will be the requested time "plus or minus one tick".
I do not recall at the moment which of the internal timing facilities that pause() uses, but I believe it is at most 1000 ticks per second (1 Khz)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!