Shop OBEX P1 Docs P2 Docs Learn Events
Logaritmic calculations — Parallax Forums

Logaritmic calculations

DriesDries Posts: 23
edited 2006-10-23 21:24 in BASIC Stamp
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

Comments

  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-10-22 17:40
    Hi Dries,

    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
  • DriesDries Posts: 23
    edited 2006-10-22 18:17
    Hi Tracy,

    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>
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-10-22 19:41
    What is the expected range of x and y?

    The Excel sheet looks something like this, so you can copy column 3 directly into a Stamp program:

    x              y                                Stamp 
    1        =5*EXP(-0.7355*A1)         "waterTable DATA Word" & INT(B1*10000)
    2        =5*EXP(-0.7355*A2)         "DATA Word" & INT(B2*10000)
    



    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
  • DriesDries Posts: 23
    edited 2006-10-22 20:04
    Actually I measured in activated sludge of a wastewater treatment plant. The concentration range is 0..6 g/l MLSS. The IR emitter and receiver have a spacing of 20 mm where the liquid is comming through. The signal from receiver is 0..5 V. When the water is clear (=0,0 g/l) the signal is around 0,1 V. When the concentration is around 8 g/l the signal is totally blocked and the signal from receiver is 5 V. Accuracy of 0,1 g/l will be OK. I measured the following curve:

    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>
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-10-22 20:26
    I'm having trouble fitting the data to the curve, y=5e(-0,7355x)
    =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
  • DriesDries Posts: 23
    edited 2006-10-22 20:35
    Sorry, I reversed the Volts before puting in the excel graph; all voltages are subtracted from 5.

    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>
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2006-10-23 18:36
    Dries said...
    Sorry, I reversed the Volts before puting in the excel graph; all voltages are subtracted from 5.

    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

    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
    398 x 271 - 8K
  • DriesDries Posts: 23
    edited 2006-10-23 21:24
    Tracy,

    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
Sign In or Register to comment.