Chris@5
|
1
|
Chris@5
|
2 # To the extent possible under law, Chris Cannam and QMUL have waived
|
Chris@5
|
3 # all copyright and related or neighboring rights to this file
|
Chris@5
|
4 # (http://creativecommons.org/about/cc0)
|
Chris@3
|
5
|
Chris@3
|
6 import signal_processing as sp
|
Chris@3
|
7 import numpy as np
|
Chris@3
|
8
|
Chris@3
|
9 def test_rms():
|
Chris@3
|
10 assert sp.rms([1,1,1]) == 1.0
|
Chris@3
|
11 assert sp.rms([0.5,-0.5]) == 0.5
|
Chris@3
|
12 assert sp.rms([0,0,0,0]) == 0.0
|
Chris@3
|
13 assert sp.rms([5]) == 5.0
|
Chris@3
|
14 assert abs(sp.rms([1,2,-2]) - np.sqrt(3.0)) < 0.000001
|
Chris@3
|
15
|
Chris@3
|
16 def test_autocorrelation():
|
Chris@3
|
17 samples = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,0]
|
Chris@3
|
18 acf = sp.autocorrelation(samples)
|
Chris@3
|
19 assert len(acf) == len(samples)
|
Chris@3
|
20 assert np.argmax(acf) == 0
|
Chris@3
|
21 assert acf[3] > acf[2]
|
Chris@3
|
22 assert acf[3] > acf[4]
|
Chris@3
|
23
|
Chris@3
|
24 def test_bpm_lag_conversions():
|
Chris@3
|
25 assert sp.bpm_to_lag(60, 1) == 1
|
Chris@3
|
26 assert sp.bpm_to_lag(60, 120) == 120
|
Chris@3
|
27 assert sp.bpm_to_lag(30, 120) == 240
|
Chris@3
|
28 assert sp.bpm_to_lag(120, 1) == 0 # should be an integer
|
Chris@3
|
29 assert sp.lag_to_bpm(120, 120) == 60.0
|
Chris@3
|
30 assert sp.lag_to_bpm(60, 120) == 120.0
|
Chris@3
|
31 assert sp.lag_to_bpm(80, 6) == 4.5
|