- From: Sandy Pond <sandy_pond_at_myrealbox.com>
- Date: Sun, 06 Mar 2005 20:34:35 -0500
On Sun, 2005-03-06 at 16:58 -0500, Sandy Pond wrote: > On Sun, 2005-03-06 at 16:16 -0500, Sandy Pond wrote: > > > The example program feeds a square wave into the low_pass_filter and > > prints out a count, filter input and filter output. I'll leave it to > > you to plot, but you can use gnuplot: > > > > Whoops ... before I get blasted I'm not treating the remainder quite > correct :) > > Here's a patch: > > $ diff -u low_pass_filter.c.orig low_pass_filter.c > --- low_pass_filter.c.orig 2005-03-06 14:59:26.000000000 -0500 > +++ low_pass_filter.c 2005-03-06 16:51:47.000000000 -0500 > _at__at_ -41,7 +41,7 _at__at_ > > dy = in_count - lpfp->out_count; /* 32 bit delta*/ > dy *= lpfp->scaled_T; /* scaled and filter delta */ > - dy += lpfp->remainder; /* add last remainder back in */ > + dy += (lpfp->remainder*lpfp->scaled_T) >> 16; /* remainder*/ > lpfp->remainder = dy & 0x0000ffff; /* get new remainder */ > lpfp->out_count += dy >> 16; /* calc new output */ > > Damn ... I had it right the first time. That what I get for working when I hungry and tired :)
Received on 2005-03-07Z01:34:35