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], phases=[0.0, 0.0, 0.0, 0.0, 0.0]) fish2 = ff.generate_wavefish(eodfs[1], samplerate, duration=8.0, noise_std=0.0, amplitudes=[1.0, 0.7, 0.2, 0.1], phases=[0.0, 0.0, 0.0, 0.0]) fish3 = ff.generate_wavefish(eodfs[2], samplerate, duration=8.0, noise_std=0.0, amplitudes=[10.0, 5.0, 1.0], phases=[0.0, 0.0, 0.0]) fish4 = ff.generate_wavefish(eodfs[3], samplerate, duration=8.0, noise_std=0.0, amplitudes=[6.0, 3.0, 1.0], phases=[0.0, 0.0, 0.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')
def test_harmonic_groups(): # generate data: samplerate = 44100.0 duration = 1. # generate data: time = np.arange(0, duration, 1./samplerate) # wavefish with fixed frequency: eodf = 300.0 data = ff.generate_wavefish(eodf, samplerate, duration=duration, noise_std=0.02, amplitudes=[1.0, 0.5, 0.0, 0.0001], phases=[0.0, 0.0, 0.0, 0.0]) assert_equal(len(time), len(data), 'generate_wavefish() failed') data = ff.generate_alepto(eodf, samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_alepto() failed') data = ff.generate_eigenmannia(eodf, samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_eigenmannia() failed') # wavefish with frequency modulation: eodf = 500.0 - time/duration*400.0 data = ff.generate_wavefish(eodf, samplerate, duration=duration, noise_std=0.02, amplitudes=[1.0, 0.5, 0.0, 0.0001], phases=[0.0, 0.0, 0.0, 0.0]) assert_equal(len(time), len(data), 'generate_wavefish() failed') data = ff.generate_alepto(eodf, samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_alepto() failed') data = ff.generate_eigenmannia(eodf, samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_eigenmannia() failed') # pulse fishes: data = ff.generate_pulsefish(80., samplerate, duration=duration, noise_std=0.02, jitter_cv=0.1, peak_stds=[0.0001, 0.0002], peak_amplitudes=[1.0, -0.3], peak_times=[0.0, 0.0003]) assert_equal(len(time), len(data), 'generate_pulsefish() failed') data = ff.generate_monophasic_pulses(80., samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_monophasic_pulsefish() failed') data = ff.generate_biphasic_pulses(80., samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_biphasic_pulsefish() failed') data = ff.generate_triphasic_pulses(80., samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_triphasic_pulsefish() failed') # communication signals: data = ff.chirps_frequency(600.0, samplerate, duration=duration, chirp_kurtosis=1.0) assert_equal(len(time), len(data), 'chirps_frequency() failed') data = ff.rises_frequency(600.0, samplerate, duration=duration, rise_size=20.0) assert_equal(len(time), len(data), 'rises_frequency() failed')
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], phases=[0.0, 0.0, 0.0, 0.0, 0.0]) fish2 = ff.generate_wavefish(eodfs[1], samplerate, duration=8.0, noise_std=0.0, amplitudes=[1.0, 0.7, 0.2, 0.1], phases=[0.0, 0.0, 0.0, 0.0]) fish3 = ff.generate_wavefish(eodfs[2], samplerate, duration=8.0, noise_std=0.0, amplitudes=[10.0, 5.0, 1.0, 0.1], phases=[0.0, 0.0, 0.0, 0.0]) fish4 = ff.generate_wavefish(eodfs[3], samplerate, duration=8.0, noise_std=0.0, amplitudes=[6.0, 3.0, 1.0, 0.1], phases=[0.0, 0.0, 0.0, 0.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) fdbs = hg.fundamental_freqs_and_power(groups) # check: assert_true( np.all(np.abs(eodfs - fundamentals) < df), 'harmonic_groups() did not correctly detect all fundamental frequencies' ) fundamentals = hg.fundamental_freqs([groups, [groups[1], groups[3]]]) fdbs = hg.fundamental_freqs_and_power([groups, [groups[1], groups[3]]], 3) # check: assert_true( np.all(np.abs(eodfs - fundamentals[0]) < df), 'harmonic_groups() did not correctly detect all fundamental frequencies' ) fundamentals = hg.fundamental_freqs([[groups, [groups[1], groups[3]]]]) fdbs = hg.fundamental_freqs_and_power([[groups, [groups[1], groups[3]]]], 10, True) # check: assert_true( np.all(np.abs(eodfs - fundamentals[0][0]) < df), 'harmonic_groups() did not correctly detect all fundamental frequencies' )
def test_harmonic_groups(): # generate data: samplerate = 44100.0 duration = 1. # generate data: time = np.arange(0, duration, 1. / samplerate) # wavefish with fixed frequency: eodf = 300.0 data = ff.generate_wavefish(eodf, samplerate, duration=duration, noise_std=0.02, amplitudes=[1.0, 0.5, 0.0, 0.0001], phases=[0.0, 0.0, 0.0, 0.0]) assert_equal(len(time), len(data), 'generate_wavefish() failed') data = ff.generate_alepto(eodf, samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_alepto() failed') data = ff.generate_eigenmannia(eodf, samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_eigenmannia() failed') # wavefish with frequency modulation: eodf = 500.0 - time / duration * 400.0 data = ff.generate_wavefish(eodf, samplerate, duration=duration, noise_std=0.02, amplitudes=[1.0, 0.5, 0.0, 0.0001], phases=[0.0, 0.0, 0.0, 0.0]) assert_equal(len(time), len(data), 'generate_wavefish() failed') data = ff.generate_alepto(eodf, samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_alepto() failed') data = ff.generate_eigenmannia(eodf, samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_eigenmannia() failed') # pulse fishes: data = ff.generate_pulsefish(80., samplerate, duration=duration, noise_std=0.02, jitter_cv=0.1, peak_stds=[0.0001, 0.0002], peak_amplitudes=[1.0, -0.3], peak_times=[0.0, 0.0003]) assert_equal(len(time), len(data), 'generate_pulsefish() failed') data = ff.generate_monophasic_pulses(80., samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_monophasic_pulsefish() failed') data = ff.generate_biphasic_pulses(80., samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_biphasic_pulsefish() failed') data = ff.generate_triphasic_pulses(80., samplerate, duration=duration) assert_equal(len(time), len(data), 'generate_triphasic_pulsefish() failed') # communication signals: data = ff.chirps_frequency(600.0, samplerate, duration=duration, chirp_kurtosis=1.0) assert_equal(len(time), len(data), 'chirps_frequency() failed') data = ff.rises_frequency(600.0, samplerate, duration=duration, rise_size=20.0) assert_equal(len(time), len(data), 'rises_frequency() failed')