MATLAB: Smoothing 2D scattered points

filterimageimage processinginterpolationSignal Processing Toolboxsmoothing

Hi Friends,
Is there anyway to smooth 2D scattered points?
I drew my question in this picture:
on the left we have an scattered path of points, but, rationally one can think of a smoothed representing set of points (black dots) in the right picture.
Thank you very much.

Best Answer

Yes. You can use something like spline or sgolayfilt() to smooth both the x and y coordinates independently. See attached demo. Here is the main part:
% Now smooth with a Savitzky-Golay sliding polynomial filter
windowWidth = 45
polynomialOrder = 2
smoothX = sgolayfilt(x, polynomialOrder, windowWidth);
smoothY = sgolayfilt(y, polynomialOrder, windowWidth);
Attach your x and y data if you can't figure it out from the well commented demo code.