Logaritmic calculations
I want to measure the clarity of water with a InfraRed emitter/receiver connected to a Basic Stamp. The relation between clarity and absorption of IR light: y=5e(-0,7355x) . Is it possible with the basic stamp to use this "e" function ?
BR /Dries
BR /Dries
Comments
If it were my project, I would use a lookup table with interpolation. Create the table in Excel to cover the expected values of x and y, and then bring that as DATA Word statemens into the Stamp program.
There are alternatives. You could get the math coprocessor chip from Parallax or from Al Williams. It is possible to calculate it directly on the Stamp, but that is slow and cumbersome. The table/interpolation will be quite accurate and also as fast as you are going to get.
Where did you derive the formula, y=5e(-0,7355x)? I have worked with turbidity meters from D&A Instruments, and from McVan instruments and from Global Water (all are expensive things!), but they use scattered light, not absorbed light. The doorstop in my office is a (nonfunctioning) dragline transmissometer that looks like a small missile with an open nose funnel so that water can run through as it is dragged behind a boat. There is a light emitter at one end of the tube and a detector at the other end.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Thanks for you reply. Indeed interpolation between point in a table was the second option if the exponential function is not available.
The formula I got from field measurements with an analog version, results in excel > curve with formula in the graph.
Official turbidity meters are based on scattered light (expressed in NTU, FTU). I will use absorption because this is a more stable signal and I don't measure in NTU but in % transmission.
Any suggestion about the easiest way to bring in a 10 point table and look for the two closest point ?
/Dries
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<img src="www.nelemans.org/dn.jpg>
The Excel sheet looks something like this, so you can copy column 3 directly into a Stamp program:
If the x values are equally spaced, then the table is simply a lookup of the value to find the two values x and y that bracket the variable, then interpolation is,
y = (y2 - y1) * (x - x1) / (x2 - x1) + y1
It is a little harder if the values of x are not regularly spaced, but it can still be pretty fast with a binary search. The details of the interpolation depend on the range of x and y and the accuracy required. On the Stamp it must be approached ad hoc.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
MLSS (g/l) Signal (V)
6,41 4,940
5,13 4,880
4,10 4,810
3,28 4,640
2,62 4,390
2,10 4,010
1,68 3,430
1,34 2,800
1,07 1,900
0,00 0,095
BR, Dries
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<img src="www.nelemans.org/dn.jpg>
=5*EXP(-0.7355*A1) in excel:
If x=2.1, then y=1.07
if x=4.010, y=0.26
but from the data, when g/l=2.1, then V=4.010
I ask, because if you have a good curve fit, then you can the values of y that correspond to evenly spaced values of x, and that will make the computation easier.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
MLSS g/l V Vinv
6,41 4,940 0,060
5,13 4,880 0,120
4,10 4,810 0,190
3,28 4,640 0,360
2,62 4,390 0,610
2,10 4,010 0,990
1,68 3,430 1,570
1,34 2,800 2,200
1,07 1,900 3,100
0,00 0,095 4,905
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
<img src="www.nelemans.org/dn.jpg>
I graphed out the data and the fit, also another fit to a log function that excel came up with. The fits are not that great. It would be easy enough to do the lookup table off of the data values directly. But how much variation is there in the data, the error bars if you will? If there is
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
The LN is closer to the data then the EXP. Based on that I can make a look-up table with equal spaced x-values.
Thanks a lot for your help.
/Dries
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Dries Nelemans