Lookup Table With Interpolation


Recommended Posts

I am trying to acquire data from an angle transducer. The data can be approximated by a 6th degree polynomial until +/-60 deg, but 60-90 on either side is crazy. Thus, I would like to use a lookup table with interpolation instead. I have seen the post about thermistors, but there is nothing in there about interpolation. My sample rate is slow (<20Hz), so a function is acceptable and won't cripple my computer. 

 

This is what I am thinking:

 

volt_list [0, 4] = 0,1,2,3,4

angle_list [0, 4] = 0, 15, 50, 90

 

function angle(value)
private index1 = search(volt_list < resistanceReading)

private index2 = search (volt_list > resistanceReading)

private volt1=volt_list[index1]

private volt2=volt_list[index2]

private position = value/(index2-index1)

 

return(angle_list[index1]+(angle_list[index2]-angle_list[index1])*position)

 

Do you have any suggestions?

Link to comment
Share on other sites

Look up tables are a great way to handle things that can't be described in a simple function.  They also can be faster, though not the way you are using them.  Its much better if you can use the reading directly in the index rather than having to do a search.  In the example you gave, this is easy since volt_list simply contains the index (i.e. volt_list[0] = 0, volt_list[1] = 1, etc).  So you can do:

 

private index1 = floor(resistanceReading)

private index2 = ceil(resistanceReading)

 

And in your case, volt1 = index1, so the next two lines you have are unnecessary.  I should also add: in your code where you search for index1 and 2, once you find index1, you know that index2 is going to be = index1+1, so there is no need for the second search.

 

I'm not sure if these are real numbers for you, but try and make it so you have just one lookup table and the index of the array matches the reading, i.e. you can do angle_list[resistanceReading] directly.  If you need more than integer resolution, use a scaling factor.  So, for example, if you want to be able to provide resistanceReading's in 0.1 volt increments, just make the angle_list array index step by 0.1.  Then you do: angle_list[resistanceReading*10]

 

Finally, you can't use the word "Value" in script.  Its a DAQFactory keyword and can only be used in Conversions.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.