csu-hmc / GaitAnalysisToolKit

Tools for the Cleveland State Human Motion and Control Lab
http://hmc.csuohio.edu
Other
111 stars 31 forks source link

Realtime filter in leg2d seems to be rather slow #30

Open moorepants opened 10 years ago

moorepants commented 10 years ago
octave:8> profile on
octave:9> leg2d(rand(5000, 1), rand(5000, 12), rand(5000, 3), options);
Marker 1: 0 samples are missing, longest gap is 0 samples.
Marker 2: 0 samples are missing, longest gap is 0 samples.
Marker 3: 0 samples are missing, longest gap is 0 samples.
Marker 4: 0 samples are missing, longest gap is 0 samples.
Marker 5: 0 samples are missing, longest gap is 0 samples.
Marker 6: 0 samples are missing, longest gap is 0 samples.
octave:10> profile off
octave:11> T = profile('info');
octave:12> profshow(T)
   #                  Function Attr     Time (s)        Calls
-------------------------------------------------------------
  26                  rtfilter             3.560        70000
  25 myfiltfilt>rtfilter_batch             2.287           14
   3                  binary *             0.306       947201
  12                  binary +             0.138       315762
  10                     zeros             0.112        69898
  24                  binary /             0.104       315715
  29                        pi             0.074        70162
   5                      size             0.072        70001
  11                  binary -             0.065       175555
  30                  binary ^             0.060       175388
  27                   isempty             0.046        70000
  28                 binary <=             0.042        70018
  31                      sqrt             0.022        35081
   2                     leg2d             0.005            1
  33                    lookup             0.004           18
   1                      rand             0.004            3
  32                  interp1q             0.003           18
  18                myfiltfilt             0.001            7
  19                    flipud             0.001           21
  44                    unwrap             0.001            4
octave:13> 
moorepants commented 10 years ago

More on the scale of what we are doing.

octave:13> profile on
octave:14> leg2d(rand(50000, 1), rand(50000, 12), rand(50000, 3), options);
Marker 1: 0 samples are missing, longest gap is 0 samples.
Marker 2: 0 samples are missing, longest gap is 0 samples.
Marker 3: 0 samples are missing, longest gap is 0 samples.
Marker 4: 0 samples are missing, longest gap is 0 samples.
Marker 5: 0 samples are missing, longest gap is 0 samples.
Marker 6: 0 samples are missing, longest gap is 0 samples.
octave:15> profile off
octave:16> T = profile('info');
octave:17> profshow(T)
   #                  Function Attr     Time (s)        Calls
-------------------------------------------------------------
  26                  rtfilter            36.118       700000
  25 myfiltfilt>rtfilter_batch            23.364           14
   3                  binary *             3.112      9438593
  12                  binary +             1.412      3146226
  10                     zeros             1.157       700906
  24                  binary /             1.061      3146179
  29                        pi             0.748       699154
   5                      size             0.745       701009
  11                  binary -             0.660      1748035
  30                  binary ^             0.623      1747868
  27                   isempty             0.466       700000
  28                 binary <=             0.433       700018
  31                      sqrt             0.226       349577
   7                 binary !=             0.050           35
  33                    lookup             0.040           18
   2                     leg2d             0.031            1
  61                   profile             0.022            1
  32                  interp1q             0.019           18
   1                      rand             0.017            3
  15                      diff             0.009           42
moorepants commented 10 years ago

Octave 3.8 now has a JIT compiler that could speed up this filter loop. Another option would be to write the filter in C or something, as this is just a typical case where Matlab is poor: for loops. Finally, we could just change this out to a non-real time filter.

moorepants commented 10 years ago

We should probably replace the call to myfilfilt with http://octave.sourceforge.net/signal/function/filtfilt.html and then use finite differences for the differentiation. It would speed things up considerably.

moorepants commented 10 years ago

Here is the output from some real data:

octave:8> profshow (data);
   #                  Function Attr     Time (s)        Calls
-------------------------------------------------------------
  26                  rtfilter            26.271       336056
  25 myfiltfilt>rtfilter_batch            12.351           14
   4                  binary *             3.138      9073445
  13                  binary +             1.475      3024510
  24                  binary /             1.098      3024463
  29                        pi             0.762       672106
  12                  binary -             0.627      1680415
  30                  binary ^             0.603      1680248
  27                   isempty             0.236       336056
  31                      sqrt             0.224       336053
  28                 binary <=             0.212       336073
   3                     leg2d             0.019            1
  32                  interp1q             0.008           18
  11                     zeros             0.008           66
  43                     atan2             0.004            4
  16                      diff             0.004           42
  34                 binary ./             0.003           34
  44                    unwrap             0.003            4
  33                    lookup             0.003           18
  20                    flipud             0.002           21