function y = wobble(x)

%   Y = WOBBLE(X) calculates the wobble Y of the signal vector X
%   (should be a velocity signal).
%
%   Wobble, designed to characterize a particular morphology of
%   Parkinsonian tremor, is measured as the ratio of the number of
%   zero-crossings in 'jerk' (the derivative of acceleration) and the
%   number of zero-crossings in velocity.
%   
%   See also MAKEFILT, DATAFILT.
%

%   Copyright 2003
%   Centre for Nonlinear Dynamics in Physiology and Medicine

xfilt = makefilt(.1,length(x),.025);
xf = datafilt(x,xfilt);
a=diff(diff(xf));

nx = length(x);
na = length(a);
crossa = a(1:(na-1)).*a(2:na);
crossx = xf(1:(nx-1)).*xf(2:nx);

y = length(find(crossa<0)) / length(find(crossx<0));

return