function [lMax, lMin, tMax, tMin, lPk2Pk, lMean, lMedian, lRMS] = Statistics(lineXData, lineYData)
%#codegen
  [lMax, maxTimeIdx] = max(lineYData);
  [lMin, minTimeIdx] = min(lineYData);
  tMax = lineXData(maxTimeIdx(end));
  tMin = lineXData(minTimeIdx(end));
  lPk2Pk = peak2peak(lineYData);
  lMean = mean(lineYData);
  lMedian = median(lineYData);
  lRMS = rms(lineYData);  
end

% define functions local to statistics
% signal depends on shared_measure so we cannot call signal functions
function y = peak2peak(x, dim)
  if nargin==1
    y = max(x) - min(x);
  else
    y = max(x,[],dim) - min(x,[],dim);
  end
end

function y = rms(x, dim)
  if nargin==1
    y = sqrt(mean(x .* conj(x)));
  else
    y = sqrt(mean(x .* conj(x), dim));
  end
end
