From a5a90a1edc87257e5872a4b1474853a62b3f5101 Mon Sep 17 00:00:00 2001 From: nicolas-f <1382241+nicolas-f@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:34:12 +0100 Subject: [PATCH] Use mean squared error as in noisesensor v1 for comparison --- tests/test_biquad_filter.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/test_biquad_filter.py b/tests/test_biquad_filter.py index 7cf6f5e..1497212 100644 --- a/tests/test_biquad_filter.py +++ b/tests/test_biquad_filter.py @@ -5,6 +5,7 @@ from noisesensor.filterdesign import FilterDesign from noisesensor.spectrumchannel import SpectrumChannel, compute_leq import acoustics +import math UNIT_TEST_PATH = os.path.dirname(os.path.abspath(__file__)) @@ -159,13 +160,11 @@ def test_leq_speak(self): # process with this library spectrum = sc.process_samples(samples) self.assertEqual(len(expected_leqs), len(spectrum)) - for expected, got in zip(expected_leqs, spectrum): - # Use error delta in linear scale - self.assertAlmostEqual(to_w(expected), to_w(got), - delta=8e-4, - msg="%f != %f" % - (expected, got)) - + err = 0 + for freq, expected, got in zip(frequencies.nominal, expected_leqs, spectrum): + err += (expected[0] - got)**2 + mean_squared_error = math.sqrt(err / len(expected_leqs)) + self.assertLess(mean_squared_error, 0.32) except FileNotFoundError as e: print("Working directory: "+os.path.abspath("./")) raise e @@ -205,12 +204,11 @@ def test_leq_speak_g2(self): # process with this library spectrum = sc.process_samples(samples) self.assertEqual(len(expected_leqs), len(spectrum)) + err = 0 for expected, got in zip(expected_leqs, spectrum): - # Use error delta in linear scale - self.assertAlmostEqual(to_w(expected), to_w(got), - delta=17e-4, - msg="%f != %f" % - (expected, got)) + err += (expected[0] - got)**2 + mean_squared_error = math.sqrt(err / len(expected_leqs)) + self.assertLess(mean_squared_error, 0.6) except FileNotFoundError as e: print("Working directory: "+os.path.abspath("./"))