Mercurial > hg > python-tutorial-skeleton
comparison 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 |
comparison
equal
deleted
inserted
replaced
2:32bf6cb28341 | 3:4be70944d21b |
---|---|
1 | |
2 import signal_processing as sp | |
3 import numpy as np | |
4 | |
5 def test_rms(): | |
6 assert sp.rms([1,1,1]) == 1.0 | |
7 assert sp.rms([0.5,-0.5]) == 0.5 | |
8 assert sp.rms([0,0,0,0]) == 0.0 | |
9 assert sp.rms([5]) == 5.0 | |
10 assert abs(sp.rms([1,2,-2]) - np.sqrt(3.0)) < 0.000001 | |
11 | |
12 def test_autocorrelation(): | |
13 samples = [1,0,0,1,0,0,1,0,0,1,0,0,1,0,0] | |
14 acf = sp.autocorrelation(samples) | |
15 assert len(acf) == len(samples) | |
16 assert np.argmax(acf) == 0 | |
17 assert acf[3] > acf[2] | |
18 assert acf[3] > acf[4] | |
19 | |
20 def test_bpm_lag_conversions(): | |
21 assert sp.bpm_to_lag(60, 1) == 1 | |
22 assert sp.bpm_to_lag(60, 120) == 120 | |
23 assert sp.bpm_to_lag(30, 120) == 240 | |
24 assert sp.bpm_to_lag(120, 1) == 0 # should be an integer | |
25 assert sp.lag_to_bpm(120, 120) == 60.0 | |
26 assert sp.lag_to_bpm(60, 120) == 120.0 | |
27 assert sp.lag_to_bpm(80, 6) == 4.5 |