Questionable 2d interpolation results (TriScatteredInterp, griddata)

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)

Matt J
Matt J on 7 Oct 2012
Edited: Matt J on 7 Oct 2012
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

The thing is that x,y,v are not calculated in matlab but imported from a CFD solver so there is actually no more code. The points in the first plot represent this scattered data and based on the fact that it's from fluid boundary layer I expect an linear interpolation as Tecplot (third link) delivers, without waves and local maxima. Matlab's interpolation seems to struggle with the original data beeing in kind of skewed columns? Is there anything I could do about that?
Here's another plot with the original data only:
scatter(x, y, 30, v, 'filled') ;
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.
The sampling is vertically and horizontally the same since min(x)=min(y), max(x)=max(y). It looks like there is no correct linear interpolation between those scattered points which have similar y-values.
Another plot shows the scattered data, the interpolated contour lines and my grid in one image: scattered data, contour, grid
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.
Sorry, I thought you were referring to my interpolation grid. I see where you're going with this. Unfortunately there is no way to get gridded samples and in the next step I wanted to use TriScatteredInterp() for 3d interpolation between planes of scattered data. Furthermore I can't figure out what Tecplot is doing in detail besides a linear interpolation with the exact same data.
The Delaunay triangulation seems to be unsuitable for my scattered data:
DT = DelaunayTri(x,y) ;
triplot(DT) ;
I couldn't find an alternative to TriScatteredInterp/griddata so there is basically nothing I can do to get a Tecplot-like interpolation in matlab? :-/
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?
Yes, the scattered data in my plots is only a tiny part of a irregular L-shaped mesh so I see no way of rotating the coordinate system.
I'll have a look at gridfit() mentioned by Sean de Wolski. The thing is that I acutally need to interpolate in 3d and the problem here is only a first step.
You still haven't told us what prevents you from increasing sampling density.
The scattered data I use come from CFD simulations. Each node in the original mesh is a data point. I can not influence the meshes they use and therefore can not change the sampling density.

Sign in to comment.

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

I tried gridfit() with several parameters but the output is pretty much the same as from TriScatteredInterp(), waves and local maxima are more or less still there. The limitation of 2d interpolation would be a problem, too.
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.

Sign in to comment.

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.

Asked:

Joe
on 7 Oct 2012

Community Treasure Hunt

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

Start Hunting!