How to program primary submovement in matlab (Kinematics analysis for discrete aiming movements)

=== delete this after reading ===

In a discrete aiming movement the primary sub-movement starts at movement onset till the second zero-crossing in the acceleration profile (i.e., the first negative-to-positive point) after peak velocity.

I am able to program the peak velocity I am wondering if someone can help me based on my progress to identify tprimary movement


n = pen_lift-1;

xdata = data(1:n,1) * xres;

ydata = data(1:n,2) * yres;

xdata = filtfilt(b, a, xdata);

ydata = filtfilt(b, a, ydata);

xvel = [0; ((xdata(3:end)-xdata(1:end-2))./(2*sec)); 0];

yvel = [0; (ydata(3:end)-ydata(1:end-2))./(2*sec); 0];

res_vel = sqrt(xvel.^2 + yvel.^2);

vel_thres = (5/100)*max(res_vel);

start_time = find(res_vel>vel_thres, 1 );

end_time = find(res_vel<vel_thres, 1, ‘last’ );

if end_time<find(max(res_vel))

end_time = length(xdata);



xaccel1 = [((xvel1(3:end)-xvel1(1:end-2))./(2*sec))];

yaccel1 = [((yvel1(3:end)-yvel1(1:end-2))./(2*sec))];

xaccel = [xaccel1(20:end-19)];

yaccel = [yaccel1(20:end-19)];

res_accel = sqrt(xaccel.^2 + yaccel.^2);

ave_accel = mean(res_accel);
=== delete until here ===

This is not a psychtoolbox question. Try stackoverflow or matlab answers

Thank you for your response