function x=clean_data(data,CrtSTD,CrtCONV) %Written by Valentin Chabaud. v3 - August 2015 NTNU %Removes erroneous values and outsiders from time series % GLORIA COMMENT: % Increase CrtSTD a bit if small variations in the good data, typically yaw, sway, surge. % Start with for example: % crtstd=8; this is clean data setting: Increase for more sensitivity, doublecheck by comparing with original % Crtconv=0.001; % data = needs to be a 1*n row vector x=data'; sx=std(x); mx=mean(x); d=diff(x); sd=std(d); d=[d;d(end)]; % figure(3) % plot([data';d]) std_prev=std(x)/CrtSTD; N=10; while abs((std(x)-std_prev)/std_prev)>CrtCONV flag=0; ind=[]; for i=1:length(x) if abs(x(i)-mx)>sx*CrtSTD || abs(d(i))>sd*CrtSTD || abs(d(i))