Deformation of surface induced by Cubic interpolation
7 views (last 30 days)
Show older comments
Hello,
I am currently interpolating heatmap-style data overtime to make 3D surfaces. On the left are raw data and right interpolated ones (surface on top and colorfill on bottom).
As seen in the left image, using the 'linear' method works fine but data still look too sharp for me. However, when trying the 'cubic' method, it deforms the geometry of the dataset.
It is problem solvable with cubic interpolation ? I tried others methods but none other are suited to my data.
Thank you very much,
2 Comments
John D'Errico
on 5 Oct 2022
First, you have a noisy surface. accept that as a fact.
Next, what does interpolation do? It MUST follow the data points exactly, as that is the meaning of interpolation. But, in order to be also smooth, this means it will often do strange things, in order to be both smooth, and have fidelity to pass EXACTLY through each point in the surface.
An example of the above is what a cubic spline interpolant does, when faced with a sharp transition. This is a worst case. You will see ringing, so oscillations much like what is called Gibbs phenomena. So you often don't want to be using a higher order interpolant to fit noisy data anyway, and that is what a spline is, a higher order interpolant.
As far as changing the geometry, I assume you mean the surface has a different boundary shape. And this tells me you seem to be using interp2 to perform the interpolation, where you filled the corners where you lack data with NaNs. This is just a guess, and I lack any data or see any code.
Answers (1)
Nipun
on 15 Dec 2023
Hi Julien,
I understand that you wan to know about interpolating data for 3D surface visualization in MATLAB. The choice of interpolation method can significantly impact the appearance of the resulting surfaces.
When using the 'linear' method, the interpolation is piecewise linear between data points, resulting in sharp transitions. On the other hand, the 'cubic' method often provides smoother surfaces, but it can also introduce unintended deformations, especially if the data is not well-behaved.
There are a few tips that may help you:
MATLAB provides several interpolation methods. In addition to 'linear' and 'cubic,' you might want to try 'nearest,' 'v4,' 'spline,' or 'pchip' methods to see if any of them provide a better balance between smoothness and accuracy.
F = scatteredInterpolant(x, y, z, 'cubic');
[Xq, Yq] = meshgrid(linspace(min(x), max(x), 100), linspace(min(y), max(y), 100));
Zq = F(Xq, Yq);
If your data has a wide range of values, normalization might help in achieving better interpolation results. You can normalize your data before interpolation and then reverse the normalization on the interpolated results.
x_normalized = (x - min(x)) / (max(x) - min(x));
y_normalized = (y - min(y)) / (max(y) - min(y));
F_normalized = scatteredInterpolant(x_normalized, y_normalized, z, 'cubic');
You might also consider using different visualization techniques as follows
figure;
subplot(1,2,1);
contour(Xq, Yq, Zq);
title('Contour Plot');
subplot(1,2,2);
mesh(Xq, Yq, Zq);
title('Mesh Plot');
Hope this helps.
Regards,
Nipun
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!