Skip to content

Commit

Permalink
Use mean squared error as in noisesensor v1 for comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-f committed Jan 25, 2024
1 parent af84d4f commit a5a90a1
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions tests/test_biquad_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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("./"))
Expand Down

0 comments on commit a5a90a1

Please sign in to comment.