embedded systems developers tools, cross compilers
  Home  |   SwiftX Archive  |   SwiftForth Archive  |

Re: Running average

From: Jim Hartman <coast1jim_at_ispwest.com>
Date: Sun, 27 Aug 2006 19:55:38 -0700

Thanks Warren. Ill plug it in sometime this week and try some
iterations with it and let you know how it does.

Jim Hartman

wheath_at_comcast.net wrote:

>Try this
>\ MAVE.F
>\ MOVING AVERAGE
>\ FOR 16 BIT INDIVIDUAL NUMBERS MXRDS MUST BE < 32768
>\ SO THAT MSUM DOES NOT OVERFLOW
>128 CONSTANT MXRDS ( READS IN MOVING AVERAGE )
> VARIABLE SVQF ( FLAG 1 = QUE FULL )
> VARIABLE QPTR ( QUE PTR TO LAST RD SVD IN MAVSV )
> 2VARIABLE MSUM ( MAVE SUM DOUBLE PRECISION )
>\ ASSUMES 2 BYTE INDIVIDUAL NUMBERS
>MXRDS CELLS BUFFER: MAVSV ( MAVE QUE )
>
>: 2+! ( D A -> - ) -ROT third 2@ D+ ROT 2! ;
>
>: INITQ ( - ) 0 SVQF ! 0 QPTR ! 0. MSUM 2! ;
>
>: SMA ( I -- AMVSV ) CELLS MAVSV + ;
>
>\ IF QUE FULL 1ST RD = NEXT READ
>: 1STRD ( -- NCTS )
> QPTR @ 1+ MXRDS MOD SMA @ ;
>
>\ AVE = SUM/MXRDS
>: AVERD ( NCTS -- NAVE T or F | F= NOT FULL YET )
> S>D MSUM 2+! \ ADD NEW READ
> SVQF @
> IF 1STRD NEGATE S>D MSUM 2+! \ REMOVE OLDEST READ
> MSUM 2@ MXRDS M/ \ CALC NEW AVE
> TRUE
> ELSE 0 \ NO AVE TILL QUE FULL
> THEN ;
>
>: SVQ ( NCTS -- )
> QPTR @ 1+ DUP MXRDS 1- > ( NCTS PTRNX TF )
> IF 1 SVQF ! \ QUE FULL
> THEN MXRDS MOD DUP QPTR ! SMA ! ; \ ADD TO QUE
>
>: MAVE ( NCTS -- NAVE T or F | F= NOT FULL YET )
> DUP AVERD ( NCTS NAVE T or NCTS F )
> DUP IF ROT
> ELSE SWAP
> THEN SVQ ; \ MUST DO SVQ LAST TO INC AFTER SAVE
>\\
>\ TO USE
> INITQ ( - )
> BEGIN
> READ A/D ( -- NCTS )
> MAVE ( NTCS -- NAVE T or F )
>
>Warren Heath
>-------------- Original message --------------
>From: Jim Hartman <coast1jim_at_ispwest.com>
>
>
>
>>Has anyone done a simple double precision running average. I'm working
>>with about 100 samples max. The platform is the hc9s12.
>>Thanks, Jim Hartman
>>----------------------------------------------------------------------
>>swiftx_at_forth.com The SwiftX programming discussion email list
>>To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
>>For list command help, send subject "help" to swiftx-request_at_forth.com
>>Message archives are located at http://www.forth.com/archive/swiftx
>>----------------------------------------------------------------------
>>This list is a forum for SwiftX users. For product support and bug
>>reports, please send email to support_at_forth.com
>>----------------------------------------------------------------------
>>
>>
>>
>
>----------------------------------------------------------------------
>swiftx_at_forth.com The SwiftX programming discussion email list
>To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
>For list command help, send subject "help" to swiftx-request_at_forth.com
>Message archives are located at http://www.forth.com/archive/swiftx
>----------------------------------------------------------------------
>This list is a forum for SwiftX users. For product support and bug
>reports, please send email to support_at_forth.com
>----------------------------------------------------------------------
>
>
>
>
----------------------------------------------------------------------
swiftx_at_forth.com The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe" to swiftx-request_at_forth.com
For list command help, send subject "help" to swiftx-request_at_forth.com
Message archives are located at http://www.forth.com/archive/swiftx
----------------------------------------------------------------------
This list is a forum for SwiftX users. For product support and bug
reports, please send email to support_at_forth.com
----------------------------------------------------------------------
Received on Sun Aug 27 2006 - 19:52:06 PDT

This archive was generated by hypermail 2.2.0 : Tue Dec 02 2008 - 03:04:51 PST