Search code examples
matlabinterpolationpolar-coordinates

pchip for angular data


I'm trying to fit a shape perserving interpolation curve to my angular data (r/phi). However, as I have repeated x-values when I transform the datapoints to (x/y), I can not simply use pchip.

I know for spline interpolation, there is cscvn and fnplt, is there anything similar for pchip?

Furthermore, there is an example of spline fitting to angular data in the matlab documentation of "spline", but I don't quite get it how I could adapt it to pchip and different data points.

I also found the interparc-function by John d'Errico, but I would like to keep my datapoints instead of having equally spaced ones.

To make it clearer, here a figure of my datapoints with linear (blue) and spline interpolation (black). The curve I'd like to get would be something in between this two, without the steep edges in the linear case but with less overshoot than in the spline case....

Thanks for your help!


Solution

  • use 1D parametric interpolation:

    n = 20;
    r = 1 + rand(n-1,1)*0.01;%noisy r's
    theta = sort(2*pi*rand(n-1,1));
    % closing the circle
    r(end+1) = r(1);
    theta(end+1) = theta(1);
    % convert to cartesian
    [x,y] = pol2cart(theta,r);
    % interpolate with parameter t
    t = (1:n)';
    v = [x,y];
    tt = linspace(1,n,100);
    X = interp1(t,v,tt,'pchip');
    % plot
    plot(x,y,'o');
    hold on
    plot(X(:,1),X(:,2));
    

    enter image description here