From 78f31b9cbb38a0e4907facdb23d68de685d454c7 Mon Sep 17 00:00:00 2001 From: Jan Benda Date: Wed, 19 Oct 2016 10:20:39 +0200 Subject: [PATCH] added test for harmonic groups --- tests/test_harmonicgroups.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/test_harmonicgroups.py diff --git a/tests/test_harmonicgroups.py b/tests/test_harmonicgroups.py new file mode 100644 index 00000000..f08bebd8 --- /dev/null +++ b/tests/test_harmonicgroups.py @@ -0,0 +1,31 @@ +from nose.tools import assert_true, assert_equal, assert_almost_equal +import numpy as np +import thunderfish.fakefish as ff +import thunderfish.powerspectrum as ps +import thunderfish.harmonicgroups as hg + + +def test_harmonic_groups(): + + # generate data: + samplerate = 44100.0 + df = 0.5 + eodfs = np.array([123.0, 321.0, 666.0, 668.0]) + fish1 = ff.generate_wavefish(eodfs[0], samplerate, duration=8.0, noise_std=0.01, + amplitudes=[1.0, 0.5, 0.2, 0.1, 0.05]) + fish2 = ff.generate_wavefish(eodfs[1], samplerate, duration=8.0, noise_std=0.01, + amplitudes=[1.0, 0.7, 0.2, 0.1]) + fish3 = ff.generate_wavefish(eodfs[2], samplerate, duration=8.0, noise_std=0.01, + amplitudes=[10.0, 5.0, 1.0]) + fish4 = ff.generate_wavefish(eodfs[3], samplerate, duration=8.0, noise_std=0.01, + amplitudes=[6.0, 3.0, 1.0]) + data = fish1 + fish2 + fish3 + fish4 + + # analyse: + psd_data = ps.psd(data, samplerate, fresolution=df) + groups = hg.harmonic_groups(psd_data[1], psd_data[0])[0] + fundamentals = hg.fundamental_freqs(groups) + + # check: + assert_true(np.all(np.abs(eodfs-fundamentals) < df), + 'harmonic_groups() did not correctly detect all fundamental frequencies')