EETimes

Embedded Systems October 2000 Vol13_11

Issue link: http://dc.ee.ubm-us.com/i/71842

Contents of this Issue

Navigation

Page 25 of 181

PROGRAMMER'S TOOLBOX • At the moment, the big question is: does this approach fix the parabolic fit's tendency to hang onto outlier points? Well, it might have, if I'd done it properly. In fact, though, it didn't, because I screwed up. let's not worry about that too much for now. We' ll be th inking harder about optimizing after we better understand the behavior. At the moment, the big question is: int para_shrink(double &xO, double &x1, double &x2, double &yO, double &y1, double &y2){ double too_close; #define MAX-PARA 4 static int count = MAX-PARA; if( count = OH } count = MAX-PARA; return FALSE; double x = para_fit(xO, x1, x2, yO, y1, y2); too_close = (x2 - xO)/20; if(max(x-xO, x2-x) < too_close){ count = MAX-PARA; return FALSE; } double y = f(x); if(x < x1 H if(y> y1H xO = x; yO = y; } else{ x2 = x1; y2 = y1; x1 = x; y1 = y; } } else{ if(y> y1H x2 = x; y2 = y; } else{ xO = x1; yO = y1; x1 = x; y1 = y; } } return TRUE; } We don ' t have to look very far to see the pro bl em: if you examine the 24 oaOBER 2000 Embedded Systems Programming To swap or not to swap does this approach fIX the parabolic fit 's tendency to hang onto outlier poin ts? Well, it might have, if I'd done it prop- erly. In fact, though, it didn 't, because I screwed up. The parabolic fit ended up giving me points tllat failed to satisfy our fundamentaJ requirement, that tlle middle point is always lowest. The problem is still in that pesky statement, wh ich was: i f( y > y1) last mo nth, and in Listing 1: i f« y > y1 ) && (x2 > xO» Turns out, neither test is correct. What I was trying to do was to swap Po and P2 if x turned o ut to be between XI and ~. That's because X is guaranteed to be between Xo and XI for the golden sec- tion, and I wanted it to look tlle same way after a parabolic fit. However, I fo rgot that, because of all the swapping, sometimes Xo is larg- e r than ~, and sometimes not. The correct test is: if«y > y1)*(x2 > xO) > 0) (Recognizing that this can be a risky test if Xo and ~ ar e drawing closer together, a we hope they do). So I can fix the test. Do we now get pe rforma nce whe re th e endpoints always move inward? No, we don 't. Figure 1 shows the case where I alter- nate between golden and parabolic methods. In Figure 2, I've set the fre- quency to allow two parabolic fits , then a forced golden section. It doesn 't seem to matter; the problem of end- poin ts stuck at the same vaJues persists.

Articles in this issue

Archives of this issue

view archives of EETimes - Embedded Systems October 2000 Vol13_11