function tremplot(group,deriv)

%   TREMPLOT(GROUP,DERIV) plots the tremor time series for subjects
%   of GROUP in the time domain using the derivative of the signal
%   specified by DERIV (0=displacement, 1=velocity or 2=acceleration). 
%  
%   If no DERIV is specified, TREMPLOT plots the raw displacement data
%   (without any filtering). 
%
%   GROUP ='p' for Parkinsonian
%         ='n' for Normal (control) group
%         ='m' for Mystery group
%         ='a' for the artificial data group
%  
%   Example: TREMPLOT('n',1)
%            plots the time series from the filtered velocity 
%            data (obtained by numerical differentiation) of the
%            control subject group.  
%
%   See also TREMFREQPLOT, TREMFILT.
%

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

if (group=='p'),
  nsubj=3;
  tgroup='Parkinson data';
end
if (group=='n'),
  nsubj=3; 
  tgroup = 'Control data';
end
if (group=='m'),
  nsubj=3; 
  tgroup = 'Mystery data';
end
if (group=='a') 
  nsubj=4; 
  tgroup = 'Artificial data';
end

tt = (0:5999)/200;
offset=0;

clf
for (i=1:nsubj)
  eval(['load trem' group int2str(i) ';']);
  x = eval(['trem' group int2str(i)]);
  if (nargin > 1)
    x = tremfilt(x,deriv);
    ttext = '(Filtered)';
  else
    deriv=0;
    ttext='(Raw)';
  end;
  x=x-mean(x);
  bottom(i)=abs(min(x))*1.1;
  offset=offset+(max(x)*1.1);
  if(i>1) offset=offset+bottom(i-1); end;
  plot(tt(1:length(x)),x-offset)

  xlabel('Time (sec)')
  if (deriv == 0)
    ytext='Displacement (mm) -- shifted';
  elseif (deriv == 1)
    ytext='Velocity (mm/sec) -- shifted';
  elseif (deriv == 2)
    ytext='Acceleration (mm/sec^2) -- shifted';
  end;
  ylabel(ytext)
  title([tgroup,' ',ttext])
  hold on
end
hold off

