Interpolation of circular data

60 vues (au cours des 30 derniers jours)
Nicolas Bourbaki
Nicolas Bourbaki le 1 Sep 2021
Hello everybody out there using MATLAB,
Is there a built-in function for interpolating circular data, i.e. a timeseries of angles (in degree) between 0° and 360° to other timepoints.
I've carefully read the documentation for the interp1 function, which doesn't really mention this case, although this post is mentioning it.
This post is mentioning the interpft function, but I'm not sure whether this would help in my case.

Réponse acceptée

Bjorn Gustavsson
Bjorn Gustavsson le 1 Sep 2021
To my understanding simply extend the input arrays such that you have a couple of points from the first few samples added onto the end adding 2*pi to those angles and a few points from the end of your arrays at the beginning subtracting 2*pi from those:
theta = linspace(0,2*pi-0.001,31);
f = 12*cos(theta) + 5*sin(3*theta).^2;
Theta = [theta(end-3:end)-2*pi,theta,theta(1:3)+2*pi];
F1 = [f(end-3:end),f,f(1:3)];
THETA = linspace(0,2*pi,301);
F2 = 12*cos(THETA) + 5*sin(3*THETA).^2;
Fi = interp1(Theta,F1,THETA,'pchip');
That way you force the interpolation to be periodic, you only need to braket your theta and f array with three (possibly 2 but I'm too lazy to check) points to get the cubic and spline interpolation-methods to give you a periodic interpolation.
HTH
  3 commentaires
Bjorn Gustavsson
Bjorn Gustavsson le 1 Sep 2021
Oh, I see, I misunderstood your problem completely. Here's my second attempt at understanding clear plain English...
t = 1:151;
theta = cumsum(rand(size(t))/2);
thetai = unwrap(atan2(interp1(1:51,sin(theta),ti),interp1(1:51,cos(theta),ti)));
This will give you a thetai without the branch-cut at 180,-180 (or 360,0).
HTH
Nicolas Bourbaki
Nicolas Bourbaki le 4 Sep 2021
Thanks, using `unwrap` was what is needed in this case.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by