View Full Version : studying biomechanics algorithms through Matlab

David R Collins
06-02-2004, 04:51 AM
Dear colleagues,
In Dr. Chris Kirtley's recent post ([BIOMCH-L] Simple (Excel) tools
for biomechanics; Tue, 1 Jun 2004 18:01:41 +0200) he wrote:

> It seems to me that I can't be the only person in the world who
> likes to know the inner workings of these functions, avoiding
> MATLAB whenever possible...

I mean no disrespect to Chris, but I do not think this is an entirely
fair criticism of Matlab. For me, one of Matlab's great aspects is
just the opposite: for most functions, one can open the source code
immediately and study the algorithm. Low level functions such as cos
and tan are built-in and cannot be opened, but other functions each
have their own text file that contains the Matlab code. For example,
to open Matlab's standard filter function (filt.m), go to the command
window and enter:
open filt
Therein one sees that filt.m just translates inputs for another
function, tf.m, so enter:
open tf
to see the actual transfer function code for filtering.

Almost all of the toolboxes available from Matlab [e.g. the Signal
Processing Toolbox that contains functions for dual pass filtering
(filtfilt) and calculating butterworth coefficients (butter)] have
their functions viewable in the same way. Because they are text files
(to which the Matlab Editor adds colors to distinguish code and
comments), they can be opened and modified in any text editor.
Toolbox contents can be browsed, e.g. for Matlab 6.5, the butterworth
function is located:

Of course, the code is copyrighted, but one can copy and paste the
code (file) to a new function name (with a matching file name in a
different folder). Then one can learn from it by modifying, removing
or adding code. Just be sure not to share the "new" code with anyone
(academic or otherwise) without permission from The MathWorks, Inc.

[As a note for any hardcore programmers concerned about efficiency,
Matlab manages its huge number of separate code files by compiling
its standard functions (and any others it is instructed to include)
at start-up. Then, additional functions (other text files with code)
are compiled the first time they are called per session (and
recompiled if changes are saved to the code file). Starting from
opening a Motion Analysis .trc file, my code can read data (e.g. 27
markers), filter the markers, calculate kinematics (10 angles with
angular velocities) and calculate summary data (mean, SD, max) in
less than 1 second per trial. My code is fairly efficient, given
Matlab's strong preference for matrix operations as opposed to loops,
but not exceptional. (My code is still very much in progress, with
limited comments, so I will not be able to share it for some time.)
>From what I have heard, C/C++ or Fortran may be strongly preferred
for simulations involving inverse dynamics that can take hours to

I want to reiterate that I respect and appreciate Chris' frequent
BIOMCH-L comments, questions and challenges. However, I do not share
his avoidance of Matlab. Matlab is probably not the best choice for
all applications (e.g. poor for web applications and developing
interfaces with biomechanics hardware), but it is an excellent tool
for students of biomechanics (grad, undergrad or professional)
wanting to learn programming and biomech algorithms.


David R. Collins, Ph.D.
Human Performance Laboratory
Department of Neurological Surgery, CB 8057
Washington University School of Medicine
660 South Euclid Avenue, Saint Louis, MO 63110
314-286-1595 (office) 314-286-1568 (fax)

To unsubscribe send SIGNOFF BIOMCH-L to LISTSERV@nic.surfnet.nl
For information and archives: http://isb.ri.ccf.org/biomch-l
Please consider posting your message to the Biomch-L Web-based
Discussion Forum: http://movement-analysis.com/biomch_l