ScaleTime - fast linear matrix interpolation
I have recorded timeseries of e.g. size [100'000 x 10] and cut out chunks of about 100 frames according to some events and normalize them to exactly 100 frames.
For this task, the direct approach with Matlab's INTERP1 works, but it is slow:
interp1(1:size(Y, 1), Y, Ti, '*linear')
Cutting Y to blocks of 1000 frames at first accelerates the computing, but encreases the complexity.
Therefore I've created the function ScaleTime for:
- linear interpolation
- equally spaced input data
- equally or non-equally spaced interpolation steps
- matrix input
- no handling of NaNs, no extrapolation.
To my surprise, ScaleTime is dramatically faster for the job mentioned above in comparison to INTERP1 (Matlab 7): M-verion: factor 170, MEX: factor 420! The usual speed gain for other input sizes is about 5 to 20 (see picture and table created by TestScaleTime).
The functions lininterp1f and qinterp1 from the FEX do not accept matrices and they are significantly slower than the MEX ScaleTime:
http://www.mathworks.com/matlabcentral/fileexchange/8627
http://www.mathworks.com/matlabcentral/fileexchange/10286
If you have installed these tools, their speed is compared in TestScaleTime.
Included: M-source, C-source.
Compilation: mex -O ScaleTime.c
Run TestScaleTime.m after compiling!
Please mail me if you need pre-compiled MEX files or in case of questions or problems. |