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

2ROT OR NOT TO 2ROT that is the question

From: Gene Silvernail <genes_at_belhaven.com>
Date: Tue, 23 Jul 2002 12:34:18 -0700

The following code is for a simple exponential averaging filter. It
doesn't work. As best as I can see the 2ROT screws up the first time
through. Pre-loading LAST-VAL with 0. and giving ALPHA a value of 50 you
can run successive 0. X1000 LAST-VAL 2@ D. and see the results.....
We are running
SwiftX AVR 3.1.4
 
Any light would be helpful.
 
Gene Silvernail
 
AIM JULY 22, 2002 ok
  ok
  ok
0. x1000 LAST-VAL 2@ D. 21561344 ok
0. x1000 LAST-VAL 2@ D. 10780672 ok
0. x1000 LAST-VAL 2@ D. 5390336 ok
0. x1000 LAST-VAL 2@ D. 2695168 ok
0. x1000 LAST-VAL 2@ D. 1347584 ok
0. x1000 LAST-VAL 2@ D. 673792 ok
0. x1000 LAST-VAL 2@ D. 336896 ok
0. x1000 LAST-VAL 2@ D. 168448 ok
0. x1000 LAST-VAL 2@ D. 84224 ok
0. x1000 LAST-VAL 2@ D. 42112 ok
0. x1000 LAST-VAL 2@ D. 21056 ok
0. x1000 LAST-VAL 2@ D. 10528 ok
0. x1000 LAST-VAL 2@ D. 5264 ok
0. x1000 LAST-VAL 2@ D. 2632 ok
0. x1000 LAST-VAL 2@ D. 1316 ok
0. x1000 LAST-VAL 2@ D. 658 ok
0. x1000 LAST-VAL 2@ D. 329 ok
0. x1000 LAST-VAL 2@ D. 164 ok
0. x1000 LAST-VAL 2@ D. 82 ok
0. x1000 LAST-VAL 2@ D. 41 ok
0. x1000 LAST-VAL 2@ D. 20 ok
0. x1000 LAST-VAL 2@ D. 10 ok
0. x1000 LAST-VAL 2@ D. 5 ok
0. x1000 LAST-VAL 2@ D. 2 ok
0. x1000 LAST-VAL 2@ D. 1 ok
0. x1000 LAST-VAL 2@ D. 0 ok
0. x1000 LAST-VAL 2@ D. 0 ok
0. x1000 LAST-VAL 2@ D. 0 ok
0. x1000 LAST-VAL 2@ D. 0 ok
 
 
 
 
 
 
{
========================================================================
=
  Belhaven Applied Technologies Inc. -- G.P.Silvernail
 
  Created: 07-22-2002, 03:47 PM
 
  Project: AIM
  File: FILTERS.f
  Path: D:\ForthInc\ProjectS\AIM
 
  Comment: Filters, all use double numbers
 
         Exponential Averaging, y(n) = ALPHA * x(n) + (1-ALPHA) * y(n-1)
           where y(n-1) = last Exponential Average
 
========================================================================
= }
 
SAVE-SECTIONS
 
UDATA
 
2VARIABLE LAST-VAL \ Holds the last value or y(n-1)
VARIABLE ALPHA \ Holds 0 to 100
 
RESTORE-SECTIONS
 
: EXP-AVG ( d1 -- d2 ) \ Expects double d1 which is
raw reading
                      ;
[DEBUG
: X1000 ( d -- )
      LAST-VAL 2@
      100 ALPHA @ - 100 M*/
      2ROT \ <<<<<< 2ROT GETS CLOBBERED
HERE FIRST TIME THROUGH >>>>>
      ALPHA @ 100 M*/
      D+ LAST-VAL 2!
 
      ;
DEBUG]
 
 
: INIT-MATH
      50 ALPHA !
      0. LAST-VAL 2!
      ;
 
 

----------------------------------------------------------------------
swiftx_at_forth.com The SwiftX programming discussion email list
To unsubscribe, send subject "unsubscribe swiftx" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/swiftx -- check them out!
----------------------------------------------------------------------
THIS LIST IS NOT FOR BUG REPORTS! Send bug reports to support_at_forth.com.
Received on Tue Jul 23 2002 - 12:34:50 PDT

This archive was generated by hypermail 2.2.0 : Mon Dec 01 2008 - 03:04:47 PST