diff test_signal_processing.py @ 3:4be70944d21b skeleton_v2

Add some basic signal processing methods we need
author Chris Cannam
date Thu, 04 Oct 2012 17:14:05 +0100
parents
children ea2387fd1b90
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test_signal_processing.py	Thu Oct 04 17:14:05 2012 +0100
@@ -0,0 +1,27 @@
+
+import signal_processing as sp
+import numpy as np
+
+def test_rms():
+    assert sp.rms([1,1,1]) == 1.0
+    assert sp.rms([0.5,-0.5]) == 0.5
+    assert sp.rms([0,0,0,0]) == 0.0
+    assert sp.rms([5]) == 5.0
+    assert abs(sp.rms([1,2,-2]) - np.sqrt(3.0)) < 0.000001
+
+def test_autocorrelation():
+    samples = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,0]
+    acf = sp.autocorrelation(samples)
+    assert len(acf) == len(samples)
+    assert np.argmax(acf) == 0
+    assert acf[3] > acf[2]
+    assert acf[3] > acf[4]
+
+def test_bpm_lag_conversions():
+    assert sp.bpm_to_lag(60, 1) == 1
+    assert sp.bpm_to_lag(60, 120) == 120
+    assert sp.bpm_to_lag(30, 120) == 240
+    assert sp.bpm_to_lag(120, 1) == 0 # should be an integer
+    assert sp.lag_to_bpm(120, 120) == 60.0
+    assert sp.lag_to_bpm(60, 120) == 120.0
+    assert sp.lag_to_bpm(80, 6) == 4.5