Skip to content

Commit

Permalink
Filter: fix notch filter test
Browse files Browse the repository at this point in the history
  • Loading branch information
andyp1per committed Jun 26, 2023
1 parent e14023b commit 2d8a9a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions libraries/Filter/tests/test_notchfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ TEST(NotchFilterTest, SineTest)
const float v = filter.apply(sample);
if (i >= 2*period_samples) {
integral1_in += sample * dt;
integral2_in += fabsf(sample) * dt;
integral2_in += fabsF(sample) * dt;
integral1_out += v * dt;
integral2_out += fabsf(v) * dt;
integral2_out += fabsF(v) * dt;
}
}

// we expect both absolute integrals to be zero
EXPECT_LE(fabsf(integral1_in), 0.01);
EXPECT_LE(fabsf(integral1_out), 0.01);
EXPECT_LE(fabsF(integral1_in), 0.01);
EXPECT_LE(fabsF(integral1_out), 0.01);

// we expect the output abs integral to be smaller than input
// integral by the attenuation
const float ratio1 = integral2_in / integral2_out;
::printf("ratio1=%f expected_ratio=%f\n", ratio1, expected_ratio);
const float err_pct = 100 * fabsf(ratio1 - expected_ratio) / ratio1;
const float err_pct = 100 * fabsF(ratio1 - expected_ratio) / ratio1;
EXPECT_LE(err_pct, 1);
}

Expand Down Expand Up @@ -122,8 +122,8 @@ TEST(NotchFilterTest, HarmonicNotchTest)
v = f.apply(v);
}
if (s >= s/10) {
integrals[i].in += fabsf(sample) * dt;
integrals[i].out += fabsf(v) * dt;
integrals[i].in += fabsF(sample) * dt;
integrals[i].out += fabsF(v) * dt;
}
if (sample >= 0 && integrals[i].last_in < 0) {
integrals[i].last_crossing = s;
Expand Down
1 change: 1 addition & 0 deletions libraries/Filter/tests/wscript
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
def build(bld):
bld.ap_find_tests(
use='ap',
DOUBLE_PRECISION_SOURCES = ['test_notchfilter.cpp']
)

0 comments on commit 2d8a9a3

Please sign in to comment.