Question

I have a light sensor which reads light intensity from 0 to 4095. I struggling to to write an equation using the inverse-square law of light so that when the light is lowest (let's say lowest ambient light is 50), it returns 1, and if highest (4095), it returns 26, but crucially the increments from 1 to 26 require the light to increase exponentially i.e.:

123 4 5  6   7      8         9              10                          ...27
light intensity ->

Any suggestions of an equation? I can't seem to figure it out. Language is C.

Was it helpful?

Solution

You are wanting to divide your 4095 to 50 interval into 25 equal segments (26-1). That would mean the width of each "intensity segment" is:

(4095-50)/25 = 161.8

So if variable x is ranging 1 to 26, your equation for distance would be:

D = sqrt( 1 / (4095 - (x * 161.8)) )

This is from taking Intensity_value = 1/D^2 as the proportion (I say "intensity value" since this doesn't include the proportion constant if it were a real intensity - we're dealing with arbitrary units for this problem).

In other words, if you plotted x on a line and each x value was a distance D from the origin, you'd get the result you are showing for 1 through 26. I am assuming, from your diagram, that the intensity is DECREASING as you go to the right.

You should be able to generalize this for different ranges of intensities and different ranges of corresponding x.

OTHER TIPS

Try the inverse of I = a.R^2 + b with a = 4090/676 and b = -1, where I is the intensity.

I have obtained this by assuming the above function and inserting the value pairs 1,50 and 26,4095 and solving for a and b.

If your intent is to find some exponential function on domain [1,4095] with values in range [1,26] then this will satisfy these conditions:

f(x) = exp [ ( x - 50) * ln( 26) / ( 4095 - 50)]

If your intent is to find function that satisfies inverse square law then since;

enter image description here

this will work:

(f( x))^2 = ( 1 / ( 4095 - ( x * ( 4095 - 50) / 25)) )
f(x) = sqrt( 1 / ( 4095 - ( x * ( 4095 - 50) / 25)) )

I have no idea of physics, but from your explanation I believe you are looking for logarithmic interpolation; this could be done as follows.

y = ln(x-50) * (26 - 1 / ln(4095-50) ) + 1

Here 50, 26 and 1 are used as parameters to stretch and shift the function to map 50 to 1 and 4095 to 26; I hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top