1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
clear all, close all
for stim= 1:5;
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 independantly
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 separately
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 overall 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 variables for each condition independantly
for i= 1:2
Condition{stim} = data1{stim}(:,3)==i;
%defines the peak of 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 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 reach (should
%relative to movement start and not to the start of the trial.
%Hence, the substraction of movementstart{stim}.
ttpv{stim} = find (velocity{stim}(Condition{stim}) == max(velocity{stim}(Condition{stim})),1);
timetopeakvel{stim} = data1{stim}(ttpv{stim},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};
allendmovement(stim,i) = movementend{stim};
allmovementtime(stim,i) = movementtime{stim};
end
end |
Partager