Shop OBEX P1 Docs P2 Docs Learn Events
Averaging routine — Parallax Forums

Averaging routine

ArchiverArchiver Posts: 46,084
edited 2002-05-30 20:35 in General Discussion
Does any one have a good routine that will mimmic a true floating
point average. One that gives a result that could be output to a seec
serial lcd display?

Beating my head aginst the wall - please help before I get yelled at
for putting dents in the drywall. [noparse]:)[/noparse]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2002-05-30 06:32
    Hi;

    The Basic Stamp does not do floating point math. If you can multiple all
    your numbers before adding them then
    dividing them by the total numbers you use, and then divide this result by what
    you multiplied all the numbers by
    you will get an integer value close to, but not quite the floating point value
    you want. Others will give you
    more details on how to do this better, I only started to learn about Basic
    Stamps a short time age. Look at past
    posts about floating point math, if you do not get any response soon.

    Have Fun !!
    Dale Fleischmann

    rhess_1 wrote:

    > Does any one have a good routine that will mimmic a true floating
    > point average. One that gives a result that could be output to a seec
    > serial lcd display?
    >
    > Beating my head aginst the wall - please help before I get yelled at
    > for putting dents in the drywall. [noparse]:)[/noparse]
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the Subject and Body
    of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
  • ArchiverArchiver Posts: 46,084
    edited 2002-05-30 13:14
    You may consider a fixed point solution if your numbers will fit in a 16
    bit word. For example, suppose you want to find the average of 34 50 21
    and 40. Multiply each number by 10 FIRST. So you have:

    340+500+210+400 = 1450

    Now you can divide by 4 to get 362

    The correct answer is 36.2

    Well... It is really 36.25, but you only "asked" for one digit of
    precision. OK, so you want two digits. Multiply by 100:

    3400 + 5000 + 2100 + 4000 = 14500
    /4 = 3625

    But don't get carried away. As soon as one of your numbers multiplied by
    your scaling factor goes over 65535 you are out of luck.

    If you really want to do this in floating point check out the PAK-I, II,
    and IX coprocessors. They do 32-bit floating point. The PAK-IX even has
    a multichannel A/D and can read an average of a channel automatically.
    http://www.al-williams.com/awce/pak1.htm

    Al Williams
    AWC
    * Control 8 servos at once
    http://www.al-williams.com/awce/pak8.htm



    >
    Original Message
    > From: Dale Fleischmann [noparse]/noparse]mailto:[url=http://forums.parallaxinc.com/group/basicstamps/post?postID=hmnlYMSMpv2NabwCsomnhZywR4iFXCXcyhDp4Adwd9v6WTWAI2lHFFs_U-zQ0CuhYAdovx3U65gUh6w]fleidale@c...[/url
    > Sent: Thursday, May 30, 2002 12:32 AM
    > To: basicstamps@yahoogroups.com
    > Subject: Re: [noparse][[/noparse]basicstamps] Averaging routine
    >
    >
    > Hi;
    >
    > The Basic Stamp does not do floating point math. If you
    > can multiple all your numbers before adding them then
    > dividing them by the total numbers you use, and then divide
    > this result by what you multiplied all the numbers by you
    > will get an integer value close to, but not quite the
    > floating point value you want. Others will give you more
    > details on how to do this better, I only started to learn
    > about Basic Stamps a short time age. Look at past posts
    > about floating point math, if you do not get any response soon.
    >
    > Have Fun !!
    > Dale Fleischmann
    >
    > rhess_1 wrote:
    >
    > > Does any one have a good routine that will mimmic a true floating
    > > point average. One that gives a result that could be output
    > to a seec
    > > serial lcd display?
    > >
    > > Beating my head aginst the wall - please help before I get
    > yelled at
    > > for putting dents in the drywall. [noparse]:)[/noparse]
    > >
    > > To UNSUBSCRIBE, just send mail to:
    > > basicstamps-unsubscribe@yahoogroups.com
    > > from the same email address that you subscribed. Text in
    > the Subject
    > > and Body of the message will be ignored.
    > >
    > >
    > > Your use of Yahoo! Groups is subject to
    > > http://docs.yahoo.com/info/terms/
    >
    >
    > To UNSUBSCRIBE, just send mail to:
    > basicstamps-unsubscribe@yahoogroups.com
    > from the same email address that you subscribed. Text in the
    > Subject and Body of the message will be ignored.
    >
    >
    > Your use of Yahoo! Groups is subject to
    > http://docs.yahoo.com/info/terms/
    >
  • ArchiverArchiver Posts: 46,084
    edited 2002-05-30 20:35
    >Does any one have a good routine that will mimmic a true floating
    >point average. One that gives a result that could be output to a seec
    >serial lcd display?
    >
    >Beating my head aginst the wall - please help before I get yelled at
    >for putting dents in the drywall. [noparse]:)[/noparse]

    I have a routine for calculating the mean and standard deviation of
    data from a 12-bit converter posted at

    http://www.emesys.com/BS2math5.htm#Statistics

    It is a double precision (32 bit) integer routine, as both the sum of
    values and especially the sum of the squares become quite large.

    The mean and SD will also be 12 bit values, so they can be displayed
    on the serial display using the standard DEC modifier.


    -- best regards
    Tracy Allen
    electronically monitored ecosystems
    http://www.emesystems.com
    mailto:tracy@e...
Sign In or Register to comment.