function detrended = polyDetrend(t,input,n)
  [p s mu]  = polyfit(t,input,n);
  trend     = polyval(p,t,[],mu);
  detrended = input - trend;
return
