From eacd887c25d1ddde6f165513e9fd1f4a0c5b8afc Mon Sep 17 00:00:00 2001 From: "sgunderson@bigfoot.com" <> Date: Thu, 28 Dec 2006 14:46:25 +0100 Subject: [PATCH] Fix quite a few bad bugs in the skew estimation. --- estimate-skew.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/estimate-skew.c b/estimate-skew.c index 1c44f86..d2991fc 100644 --- a/estimate-skew.c +++ b/estimate-skew.c @@ -11,7 +11,7 @@ double frac(double x) double filter(double x) { static double l = 0.0; - l = 0.001 * x + 0.999 * l; + l = 0.01 * x + 0.99 * l; return l; } @@ -58,8 +58,10 @@ int main(int argc, char **argv) double speed = 1.0; while (!feof(in1) && !feof(in2)) { + short refs; + // read sample from reference - if (fread(&sample, sizeof(short), 1, in1) != 1) { + if (fread(&refs, sizeof(short), 1, in1) != 1) { exit(0); } @@ -75,14 +77,14 @@ int main(int argc, char **argv) // linear interpolation (works well since delta_p varies so slowly) double t = frac(p); - short intp_sample = prev_sample * (1.0 - t) + sample * t; + double intp_sample = prev_sample * (1.0 - t) + sample * t; // subtract the two samples and pull it through a filter. we assume // the sines are normalized for now (and that there's no dc skew) - double offset = -0.001 * filter(intp_sample - sample); - speed += offset; + double offset = filter(intp_sample - refs); + speed -= 0.00000001 * offset; fwrite(&speed, sizeof(double), 1, skew); - printf("%f (offset=%f)\n", speed, offset); + printf("%f (offset=%f)\n", speed, intp_sample - sample); } } -- 2.39.2