Questionable 2d interpolation results (TriScatteredInterp, griddata)
Show older comments
Hi guys,
I want to interpolate 2d scattered data from a CFD simulation to a regular grid using matlab's TriScatteredInterp. I have three vectors: x,y (point coordinates) and v (fluid values).
Mesh generation and Interpolation:
xlin = linspace(min(x), max(x), 550) ;
ylin = linspace(min(y), max(y), 550) ;
[X,Y]= meshgrid(xlin, ylin) ;
Tri = TriScatteredInterp(x, y, v, 'linear') ;
Lin = Tri(X,Y) ;
The result of the interpolation seems questionable as I want to show you with some plots. The first plot shows the original scattered datapoints as well as a contour plot of the interpolation.
hold on ;
scatter(x, y, 30, v, 'filled') ;
[C,h] = contour(X, Y, Lin, '-', 'LineWidth', 1.5) ;
clabel(C,h) ;
I noticed that the contour lines in the upper part seem wavelike, in the lower part punctual. The second plot also shows my interpolation grid:
pcolor(X,Y,Lin) ;
What I expected were some mostly horizontal contour lines without those waves and punctual areas, like a smooth transition from top to bottom. I used the tool "Tecplot 360" to interpolate the exact same situation and here is what I got:
I think this is what I should get with matlab's TriScatteredInterp, too. I already tried griddata instead of TriScatteredInterp but I got the same strange results.
Is there anything I'm doing wrong with matlab's scattered data interpolation? Am I overlooking something crucial? Is there an explanation for those results?
Regards, Joe
Answers (3)
I don't think the problem lies in TriScatteredInterp, because the results of the Pcolor Plot agree with the results of the scatter/contour plots.
My guess is that the code that generated v is working in a different coordinate system than the meshgrid coordinate system that you've defined for TriScatteredInterp. We probably need to see more code.
9 Comments
Matt J
on 8 Oct 2012
I think the only thing you can do about the skewed columns is to do more dense sampling. Your sampling is noticeably more dense vertically than horizontally and that leads to more interpolation possibilities than what Tecplot gives you.
Matt J
on 8 Oct 2012
I don't see what min/max(x) and min/max(y) would have to do with it. Regardless, I don't see the same sampling densities in your scatter plots. The scattered data occur in diagonally sloping bands. The separation between the bands is something like 1.5e-3 whereas the separation between samples within a band is noticeably smaller, on the order of 1e-4 or 1e-5. My gut is that this has some unexpected impact for you on the Delaunay triangulation of the samples.
Again, there doesn't seem to be anything "wrong" with the interpolation given to you either by Tecplot or by TriScatteredInterp. Both seem perfectly legitimate given the samples you've provided. Obviously, if Tecplot is the one you prefer, it would be useful to know what it is doing, so that you can implement that instead, but I see no evidence that TriScatteredInterp is "malfunctioning".
Incidentally, the diagonal bands of your scattered data all look to be the same slope. The separation between points within these bands is not uniform, but they appear to have the same pattern in each band. This suggests to me that if you just rotate your coordinate system, so that the bands become perfectly vertical/horizontal, you will have gridded samples instead of scattered samples and can interpolate them with griddedInterpolant() instead of the more complicated Delaunay triangulation.
Matt J
on 8 Oct 2012
Unfortunately there is no way to get gridded samples
I didn't understand this part. How is there "no way" when I told you how to do it? Or do you mean that it is only in this particular example that your scattered data are a rotated mesh?
Matt J
on 8 Oct 2012
You still haven't told us what prevents you from increasing sampling density.
Joe
on 8 Oct 2012
Sean de Wolski
on 8 Oct 2012
Edited: Sean de Wolski
on 8 Oct 2012
0 votes
I would first recommend what Matt was suggesting about rotating your coordinate system to be the grid. This would not require the delaunay triangulation, which is apparently not suitable for the interpolation.
Alternatively, look at John's gridfit(). He says right the description a good reason it may work for you:
Griddata is a valuable tool for interpolation of scattered data. However it fails when there are replicates or when the data has many collinear points.
2 Comments
Jette
on 22 Jan 2013
Have you tried the smoothness parameter with different values in the two dimensions? I've just had a similar result from gridfit and this solution fixed the problem for me.
Matt J
on 9 Oct 2012
0 votes
It might be time to use a curve fitting tool, e.g., lsqcurvefit. It seems that you have a priori physical info, from fluid mechanics, about how this surface should behave, so a curve fitting tool would be the best vehicle for incorporating that.
Categories
Find more on Surface and Mesh Plots 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!