Wrapped smoothing

I have some data that lies on a wrapped dimension (e.g. 0 to 360) and I want to smooth it using something like lowess etc. However, I want the smoothing to wrap so that points near 360 smooth with points near 0. Any quick and easy way to get this done?

Réponses (4)

Teja Muppirala
Teja Muppirala le 1 Juin 2011

1 vote

Step 1. Rescale from (0,360) to (-pi,+pi)
Step 2. Unwrap the data using UNWRAP
Step 3. Smooth it
Step 4. Rescale from (-pi,+pi) back to (0,360)
Step 5. Rewrap the data using MOD
(Steps 4 and 5 are swappable).
%%Step 0 - Make some phony data
ph = 360*interpft(randn(1,5),1000);
ph = ph+10*randn(size(ph));
ph = mod(ph,360);
figure(1);
plot(ph);
%%Step 1
ph = ph*pi/180-pi;
figure(2);
plot(ph);
%%Step 2
ph = unwrap(ph);
figure(3);
plot(ph);
%%Step 3
ph = smooth(ph,25);
hold on;
plot(ph,'r');
%%Step 4
ph = 180/pi*ph+180;
%%Step 5
ph = mod(ph,360);
figure(1);
hold on;
plot(ph,'r');

1 commentaire

CP
CP le 2 Juin 2011
Hmm I'm a bit confused and maybe because I wasn't clear. The data itself doesn't go from 0 to 360. So if the X axis is from 0 to 360 there are Y values that correspond to that, and I want to smooth those Y values such that those corresponding to 0 and 360 smooth together.

Connectez-vous pour commenter.

Walter Roberson
Walter Roberson le 31 Mai 2011

0 votes

If you rescale the values first, you could use the unwrap() function to get continuous values; un-rescale and then do your smoothing.
John D'Errico
John D'Errico le 31 Mai 2011

0 votes

You can use my SLM tools, with knots defined over 0-360 degrees, but specify periodic end conditions.
For example, this fit works nicely:
X = rand(100,1)*360;
Y = sind(X) + randn(size(X))/5;
slm = slmengine(X,Y,'knots',linspace(0,360,7), ...
'endconditions','periodic','plot','on', ...
'concavedown',[0,150],'concaveup',[210,360])
Walter Roberson
Walter Roberson le 2 Juin 2011

0 votes

The easiest way might be to replicate the initial data at the end, using as many duplicate points as your smoothing window is wide. Smoothing done, clip off those extra points.
You would have to figure out what to do about the point for 360 being at the same place as the point for 0; possibly drop the last point if it is at 360 or higher.

3 commentaires

CP
CP le 2 Juin 2011
Hopefully there's a different solution, that would also involve replicating the data on the other side of zero since those points would also need it to smooth, and I think some of the smoothing methods that I want to test out are adaptive to the data set, meaning that it might make this task even more complicated
John D'Errico
John D'Errico le 2 Juin 2011
This will not ensure periodicity, only approximately so.
Walter Roberson
Walter Roberson le 2 Juin 2011
If your measured value for 0 is different from the measured value for 360 to beyond the noise level, getting periodicity would require fudging the numbers.

Connectez-vous pour commenter.

Catégories

Question posée :

CP
le 31 Mai 2011

Community Treasure Hunt

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

Start Hunting!

Translated by