function [p_n] = detrendint(p,samp_int) % simple, linear least-squares detrending of roughness profile % % [P_N] = DETRENDINT(P,SAMP_INT) % % P: profile array (first column x, second column y) % SAMP_INT: sampling interval (should be 1 millimetre for JRC) % !!! profile must be in millimetre % % % Please cite: % Marsch K & Fernandez-Steeger (2021) % https://doi.org/10.1007/s00603-020-02348-0 % % % License: % "This work is licensed under the Creative Commons Attribution 4.0 % International (CC BY 4.0) License. To view a copy of this license, visit: % http://creativecommons.org/licenses/by/4.0/" %% profile rotation according to slope angle = 5; %first guess while abs(angle) > 0.01 XX = [ones(length(p(:,1)),1) p(:,1)]; slope = XX\p(:,2); angle = atand(slope(2,1)); matrix = [cosd(-angle), -sind(-angle) ; sind(-angle), cosd(-angle)]; p = (matrix*p')'; end %% interpolation/sampling according to sampling interval p = unique([(p(:,1)-min(p(:,1))) (p(:,2)-min(p(:,2)))],'rows'); xi = (min(p(:,1)):samp_int:max(ceil(p(:,1)))); zi = interp1(p(:,1),p(:,2),xi,'linear'); p = [xi' zi']; p(any(isnan(p),2),:) = []; %if any, delete NaN p_n = p;