Linear Interpolation?

Hello Everyone,
I need to “scale” an array of data points to a specific number of points.

Ex. array of 200 data points to array of 128 data points or the other way around.

Ive looked through the Doc and im not sure i understand how to use the interpolation they mention in Appendix D.

Does anyone have an example or an explanation?

Thank you

Interpolation should indeed work quite nicely for that.

Simply put, if you have an array where ar[0]=0 and ar[1]=1 and you poll the array (through the use of a texture of course) at tex1d(ar,0.5f) you will get 0.5f.

Be advised that, as stated in the programming guide, it is rather low precision. I think i have read that it has 8 bits of precision, which leaves 256 possible values between two adjacent indices in your array. But dont quote me on that.

I believe it was 12 bits, but don’t quote me on that either :D


256 values between samples. The values are computed in high precision but, so to speak, low “resolution”. What I mean is tex1d(ar, 1.0/256) will give a result as precise as hand coded interpolation (0,00390625), but tex1d(ar, 1.1/256) will snap to the same value and give 0,00390625 instead of 0,004296875. The absolute error depends on how “jumpy” the data set is, how big are the changes between subsequent sample points.

While learning how to use interpolation with textures, pay attention to the edge cases. I remember I tripped there (had to add or subtract 0.5f to something, can’t remember anymore). The graph in the appendix on the last pages of the programming guide helps.

If CUDA handles textures the same way OpenGL does, then in order to sample the center of a pixel using normalized texture coordinates, you need to calculate the sample point as:

x_s = (0.5+x)/width

y_s = (0.5+y)/height

Where (x,y) are the discrete pixel coordinates. [0,1,…,width-1]x[0,1,…,height-1]

In other words:

(x_s,y_s) = (0.0,0.0) corresponds the outer corner of the top left pixel

(x_s,y_s) = (0.5,0.5) corresponds the center of the top left pixel ( (x,y)=(0,0) -> (x_s,y_s)=(0.5,0.5)