round up vale calculated according to binary scaling depth
This commit is contained in:
parent
2db7cd7319
commit
3cce24f2f8
@ -20,7 +20,7 @@ main()
|
||||
{
|
||||
|
||||
int i;
|
||||
INT16 var,fvar;
|
||||
INT16 var,fvar, threeup_result;
|
||||
|
||||
var = ADRES;
|
||||
|
||||
@ -31,10 +31,11 @@ main()
|
||||
naive_filter = (naive_filter * 7 + ADRES) / 8; // old filter
|
||||
|
||||
threeup_filter = (((threeup_filter << 3) - threeup_filter) >> 3) + ADRES;
|
||||
threeup_result = (threeup_filter + 4)>>3;
|
||||
|
||||
fvar = filter16(var,3);
|
||||
|
||||
printf(" iteration: %d naive_filter = %x threeup_filter = %x fvar = %x fp = %lf\n", i, naive_filter, threeup_filter, fvar, fp);
|
||||
printf(" iteration: %d naive_filter = %d threeup_filter = %d fvar = %d fp = %lf\n", i, naive_filter, threeup_result, fvar, fp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,6 +44,8 @@ main()
|
||||
|
||||
|
||||
#define BINARY_FILTER_SCALE 8
|
||||
#define ROUND_UP ((1)<<(BINARY_FILTER_SCALE))
|
||||
|
||||
/* with BINARY_FILTER_SCALE set to 8, depth valid between 2 and 7 */
|
||||
/* with a depth of 2 what we are saying is
|
||||
* * result = (old_result * 3.0 + new_val ) / 4.0)
|
||||
@ -59,6 +62,8 @@ INT16 filter16(INT16 var, int depth)
|
||||
v <<= BINARY_FILTER_SCALE; // scale up
|
||||
printf(" v = %lx : ", v);
|
||||
v2 = (oldv << depth) - oldv + v;
|
||||
// now round-up
|
||||
v2 += ROUND_UP;
|
||||
v2 >>= depth;
|
||||
oldv = v2;
|
||||
printf(" v = %lx oldv = %lx ", v, oldv);
|
||||
|
Loading…
Reference in New Issue
Block a user