Ticket #29 (closed development: fixed)

Opened 5 years ago

Last modified 4 years ago

Fix MATLAB's low 15ms-timing accuracy on Windows

Reported by: atorf Owned by:
Priority: high Milestone:
Component: Toolbox Function Keywords:
Cc:

Description

On Windows systems, all MATLAB versions up to the current release 2009a show an inaccuracy / poor resolution with timing (functions clock, etime, tic, toc, pause): Histogram tests show that timing is binned to 15ms steps, a finer timing / more accurate resolution is not possible.

Either wait for The MathWorks? to fix this (then this problem is eliminated), or implement a workaround using Windows High Accuracy Timers API (or just use GetTickCount? Kernel-API function). An already implemented MATLAB-function can be found here: http://www.mathworks.com/matlabcentral/fileexchange/16534

Make sure this works on 64bit as well (create mex-file), and replace critical functions inside the COM-layer with this custom function (introduce a new wrapper, which decides between Linux (use etime, clock as usual) and Windows (use HAT)).

This would improve Bluetooth-Performance and be a "nice feature" in general…

Attachments

TicTocVsEtime.png (3.9 KB) - added by atorf 5 years ago.
Graph showing the difference between etime and tic/toc on Windows
TicTocTest.m (410 bytes) - added by atorf 5 years ago.
Sample m-file to test and create the etime vs tic/toc plot

Change History

  Changed 5 years ago by atorf

Solution:

  • Replace ALL occurences of etime() with tic / toc
  • While etime() with clock() is quantized to 15ms on Windows, tic / toc are not
  • Use this syntax to nest calls:
    ticHandle = tic;
        % stuff...
    t = toc(ticHandle);
    
  • Replace timestamps on the handle struct with tic / toc handles

Changed 5 years ago by atorf

Graph showing the difference between etime and tic/toc on Windows

Changed 5 years ago by atorf

Sample m-file to test and create the etime vs tic/toc plot

in reply to: ↑ description   Changed 5 years ago by atorf

Replying to atorf:

An already implemented MATLAB-function can be found here: http://www.mathworks.com/matlabcentral/fileexchange/16534

Be careful with this hat() function, apparently it sometimes stalls / lags for periods of >200ms, when repeatedly called thousands of times in a loop…

Tic/tocs accuracy, coupled with the new nested functionality since MATLAB 7.7, should be good enough.

  Changed 5 years ago by atorf

  • priority changed from none to high

  Changed 5 years ago by atorf

  • status changed from new to closed
  • resolution set to fixed

(In [773]) * Replaced usage of etime in BT sending/receiving functions by tic/toc

  • Remove pause-statements in BT send/receive pause waiting loops → faster, better performance, unfortunately more CPU load probably
  • Removing colons (:) from param UseThixNXTMAC in COM_OpenNXTEx (to allow both '0016123…' and '00:16:12:..' input arguments)
  • Fixes #29
Note: See TracTickets for help on using tickets.