Analyse of human kinematics: formula issues

2 views (last 30 days)
Hi there,
I've been working for a few days on a matlab script to analyse human movement data (XYZ coordinates recorded at 240 Hz). My recording is composed of two reaching actions (each to a different target). In my script, I refer to these two actions by the term 'Condition'. These two actions will be repeated 5 times and recorded on 5 separated files.
For each action, I have to calculate the peak tangential velocity, the time to peak tangential velocity, the start time of the action, the end time of the action and the action duration. At first, I need to calculate each these values for every iterations of the 2 actions. But later on, I'll need to get the average performance accross the 5 repetitions.
You can find here a copy of the script. I apologize in advance if it's a bit messy: I'm really new at programming, so their might be some mistakes here and there.
My questions are the followings:
  • I stuggle to write the formulas to get movement end time (relative to the start of the trial, and not the whole recording). I've already written something but I'm sure there is a mistake as I don't get the expected values with my sample files. Did I miss something obvious ?
  • I also have issues calculating 'time to peak velocity' for a specific trial. What I get is the time relative to the start of the recording ...
  • Is it correct to extract the content of cell arrays to write it back into matrices (lines 70 ->75)? After processing all the files, I'll need to export the different values in SPSS for more advanced statistical analysis.
Here is a copy of the script and attempted comments to make it clearer (hopefully :)).
if true
clear all, close all
for stim= 1:3; data{stim} = load(sprintf('C%02d.txt', stim));
trialtype{stim} = data{stim}(:,1);
%Separates each coordinate in a separate variable
sx{stim} = data{stim}(:, 2);
sy{stim} = data{stim}(:, 3);
sz{stim} = data{stim}(:, 4);
%Define the paramaters required for the butterworth filter
cutoff = 20;
samplerate = 240;
Wn = cutoff/(samplerate/2);
[B,A]= butter(2, Wn);
%apply the butterworth filter to each coordinate
sx_filt{stim}= filtfilt(B,A,sx{stim});
sy_filt{stim}= filtfilt(B,A,sy{stim});
sz_filt{stim}= filtfilt(B,A,sz{stim});
%take the derivative(velocity) of each coordinate
sx_vel{stim}= [0; diff(sx_filt{stim})./(1/240)];
sy_vel{stim}= [0; diff(sy_filt{stim})./(1/240)];
sz_vel{stim}= [0; diff(sz_filt{stim})./(1/240)];
%calculate the tangential velocity for the filtered data +
%defines a timing variable "frame"
frame{stim}= 1:(size(data{stim}));
frame{stim}=frame{stim}';
frame{stim}= (frame{stim} - frame{stim}(1)) ./240;
velocity{stim} = sqrt((sx_vel{stim}.^2)+(sy_vel{stim}.^2)+(sz_vel{stim}.^2));
data1{stim}=[frame{stim},velocity{stim},trialtype{stim}];
%calculate different measures for each condition independantly
for i= 1:2
Condition{stim} = data1{stim}(:,3)==i;
%defines the peak velocity for condition 1 & 2
peak_vel{stim}= max(velocity{stim}(Condition{stim}));
%find when the velocity reaches 5% of the peak velocity and defines
%movementstart as the movement time when the specified velocity is reached
start{stim} = find (velocity{stim}(Condition{stim}) > 0.05*max(velocity{stim}(Condition{stim})),1);
movementstart{stim} = data1{stim}(start{stim},1);
%end of the movement is the first time the velocity goes below 5% of peak (after passing 50% of the peak velocity).
half{stim} = find (velocity{stim}(Condition{stim}) > 0.5*max(velocity{stim}(Condition{stim})),1);
passedhalf{stim} = data1{stim}(half{stim},1);
endt{stim} = find (velocity{stim}(half{stim}:end,:)< 0.05*max(velocity{stim}(Condition{stim})))+ half{stim}-1;
movementend{stim} = data1{stim}(endt{stim},1);
%total movement time
movementtime{stim} = movementend{stim} - movementstart{stim};
%create an index to find when the peak velocity is reached
%relative to movement start and not to the start of the trial.
tindex= data1{stim}(:,2)==peak_vel{stim};
timetopeakvel{stim} = data1{stim}(tindex,1);
%create matrices summarizing all the variables collected in cell
%arrays
allpeak_vel(stim,i) = peak_vel{stim};
alltimeto(stim,i) = timetopeakvel{stim};
allstartmovement(stim,i) = movementstart{stim};
allpassedhald(stim,i) = passedhalf{stim};
%I had to comment out the two following lines because I get an error msg "??? Subscripted assignment dimension mismatch."
%allendmovement(stim,i) = movementend{stim};
%allmovementtime(stim,i) = movementtime{stim};
end
end
end
Any help or suggestions would be greatly appreciated !
Best,
CL

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!