I have an orginal curve in (X, Y) form in within a limited range (attached).
length(X) = length(Y) = 998
I increased the resolution and extended the range slightly by using PHIP function, as below:
Yintp = Y(1)-0.1:0.002:Y(end)+0.3;
Xintp = pchip(Y, X, Yintp);
Vector size is now, length(X) = length(Y) = 4298
I, then, calculated the gradients for both the orginal (1) and inteprolated (2) curves, as follows;
gradients1(1) = (X(2) - X(1)) / (Y(2) - Y(1));
gradients2(1) = (Xintp(2) - Xintp(1)) / (Yintp(2) - Yintp(1));
gradients1(i) = (X(i+1) - X(i-1)) / (Y(i+1) - Y(i-1));
gradients2(i) = (Xintp(i+1) - Xintp(i-1)) / (Yintp(i+1) - Yintp(i-1));
gradients1(n) = (X(n) - X(n-1)) / (Y(n) - Y(n-1));
gradients2(m) = (Xintp(m) - Xintp(m-1)) / (Yintp(m) - Yintp(m-1));
Displaying results in a figure
plot(Yintp,Xintp); grid on; hold on
plot(Y, X,'.b','DisplayName','Y vs X low res')
plot(Y, gradients1,'-.r','DisplayName','Gradient - low res');
plot(Yintp, gradients2,'-', 'DisplayName','Gradient - high res');
xlabel('Tangent Angle (deg)')
Problem 1: There is the discontinuity in the 'high res' gradient at the two ends, something not visible in the (X,Y) curves. Below are the expanded views:
Problem 2: Grandient data are noisy and noisiness increases with the resolution, as shown below:
Please help me figure out the dicontinuties in gradient calculations and create smooth gradients from the high res data.