view test_signal_processing.py @ 5:ea2387fd1b90 tip

Add CC0 disclaimers
author Chris Cannam
date Thu, 04 Oct 2012 22:12:02 +0100
parents 4be70944d21b
children
line wrap: on
line source

# To the extent possible under law, Chris Cannam and QMUL have waived
# all copyright and related or neighboring rights to this file
# (http://creativecommons.org/about/cc0)

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