def test_keep_or_kill(self): sr = 256 low = pure_tone(10, sr) mid = pure_tone(40, sr) high = pure_tone(100, sr) x = low + mid + high decomp = split_bands(x, sr, cutoffs=[20, 70]) self.assertEqual(len(decomp), 3) for est, gt, name in zip(decomp, [low, mid, high], ["low", "mid", "high"]): self.assertSimilar(est, gt, gt, name)
def test_keep_or_kill(self): for _ in range(10): freq = random.uniform(0.01, 0.4) sr = 1024 tone = pure_tone(freq * sr, sr=sr, dur=10) # For this test we accept 5% tolerance in amplitude, or -26dB in power. tol = 5 zeros = 16 # If cutoff frequency is under freq, output should be input y_pass = filters.highpass_filter(tone, 0.9 * freq, zeros=zeros) self.assertSimilar(y_pass, tone, tone, f"freq={freq}, pass", tol=tol) # If cutoff frequency is over freq, output should be zero y_killed = filters.highpass_filter(tone, 1.1 * freq, zeros=zeros) self.assertSimilar(y_killed, 0 * tone, tone, f"freq={freq}, kill", tol=tol)
def test_keep_or_kill(self): for _ in range(10): freq = random.uniform(0.01, 0.4) sr = 1024 tone = pure_tone(freq * sr, sr=sr, dur=10) # For this test we accept 5% tolerance, as 5% of delta in amplitude is -52dB. tol = 5 zeros = 16 # If cutoff freauency is under freq, output should be zero y_killed = lowpass_filter(tone, 0.9 * freq, zeros=zeros) self.assertSimilar(y_killed, 0 * y_killed, tone, f"freq={freq}, kill", tol=tol) # If cutoff freauency is under freq, output should be input y_pass = lowpass_filter(tone, 1.1 * freq, zeros=zeros) self.assertSimilar(y_pass, tone, tone, f"freq={freq}, pass", tol=tol)
def test(table, freq, zeros, fft=None, device="cpu"): sr = 44_100 attns = [] for ratio in [0.9, 1, 1.1]: x = pure_tone(ratio * freq * sr, sr, 4, device=device) with Chrono() as chrono: y = lowpass_filter(x, freq, fft=fft, zeros=zeros) attns.append(format(volume(y) - volume(x), ".2f")) table.line([freq] + attns + [int(1000 * chrono.duration)])
def test_keep_or_kill(self): for _ in range(10): freq = random.uniform(0.01, 0.4) sr = 1024 tone = pure_tone(freq * sr, sr=sr, dur=10) # For this test we accept 5% tolerance in amplitude, or -26dB in power. tol = 5 zeros = 16 y_pass = filters.bandpass_filter(tone, 0.9 * freq, 1.1 * freq, zeros=zeros) self.assertSimilar(y_pass, tone, tone, f"freq={freq}, pass", tol=tol) y_killed = filters.bandpass_filter(tone, 1.1 * freq, 1.2 * freq, zeros=zeros) self.assertSimilar(y_killed, 0 * tone, tone, f"freq={freq}, kill", tol=tol) y_killed = filters.bandpass_filter(tone, 0.8 * freq, 0.9 * freq, zeros=zeros) self.assertSimilar(y_killed, 0 * tone, tone, f"freq={freq}, kill", tol=tol)