Code covered by the BSD License  

Highlights from
ScaleTime

5.0

5.0 | 1 rating Rate this file 10 Downloads (last 30 days) File Size: 8.56 KB File ID: #25463
image thumbnail

ScaleTime

by Jan Simon

 

01 Oct 2009

Fast linear interpolation of equally spaced data (C-MEX and M)

| Watch this File

File Information
Description

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.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Fast Linear Interpolation, Fast interpolation

MATLAB release MATLAB 7.8 (R2009a)
Other requirements Compatible to Matlab 6.5
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (8)
27 Nov 2009 Jan Simon

Pre-compiled MEX at: www.n-simon.de/mex

04 Aug 2010 Erik  
20 Aug 2010 Ed Santana

Hi,
 
I'm trying to use your ScaleTime function to replace interp1 in my code. Could you tell me what i have to change to make this work...
 
rect(I) = rect(I)+interp1(yVector,rcCorrected(:,ii),dR(I))* phCorr(I);
When i put ScaleTime instead of interp1 I get error " Undefined function or method 'ScaleTime' for input arguments of type 'double'."
 

23 Aug 2010 Jan Simon

@Ed: Did you compile the C-function or downloaded the corresponding pre-compiled file? If you did, is the compiled mex file visible in the path?
Is it really needed to start the interpolation for each scalar dR(I) and each vector rcCorrected(:, ii)? The interpolation is much faster, if you perform it for matrix data and vector time points.

23 Aug 2010 Ed Santana

Yes i tried to compile mex -O ScaleTime.c but i get error mex: compile of ' "ScaleTime.c"' failed. I cannot use the pre compile mex files because I'm using MATLAB 7.9(64-bit). The purpose of my code is to output a Radar image, from my understanding dR(I) and rcCorrected(:, ii) provide the value for each pixel in the image. How do you recommend i rewrite this for matrix and vector time points?

23 Aug 2010 Jan Simon

@Ed: Further problems: As you can see in the documentatoion, ScaleTime is designed to be fast is the original ticks are [1:length(Y)]. If your yVector is something different, you have to consider this in the calculation of dR.
If the compilation fails, there is still the M-version of ScaleTime. So if "which('ScaleTime')" does not find the function, you have to include it in your path.

26 Aug 2010 Ed Santana

I looked at my yVector and it is something different than [1:length(Y)]. The reason im trying to find something faster to replace interp1 is because i managed to increase the speed of all the other major functions in my code with Jacket v1.4. Besides ScaleTime do you know any other way to increase interp1 with Jacket?

28 Aug 2010 Jan Simon

@Ed: This is a section for "Comments and Ratings". Please explain your problem with the necessary details in the newsgroup.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
interpolation Jan Simon 02 Oct 2009 11:04:38
scaling Jan Simon 02 Oct 2009 11:04:39
lookup Jan Simon 02 Oct 2009 11:04:39
table Jan Simon 02 Oct 2009 11:04:39
linear Jan Simon 02 Oct 2009 11:04:39
signal processing Jan Simon 02 Oct 2009 11:04:39
time normalization Jan Simon 02 Oct 2009 11:04:39
matrix Jan Simon 02 Oct 2009 11:04:39
cmex Jan Simon 02 Oct 2009 11:04:39

Contact us at files@mathworks.com