diff --git a/allantools/noise.py b/allantools/noise.py index eb9b13b..efcf5e5 100644 --- a/allantools/noise.py +++ b/allantools/noise.py @@ -66,21 +66,21 @@ def brown(num_points=1024, b2=1.0, fs=1.0): """ return (1.0/float(fs))*numpy.cumsum(white(num_points, b0=b2*(4.0*math.pi*math.pi), fs=fs)) -def violet(num_points): +def violet(num_points=1024): """ violet noise with f^2 PSD """ # diff() reduces number of points by one. return numpy.diff(numpy.random.randn(num_points+1)) -def pink(N, depth=80): +def pink(num_points=1024, depth=80): """ N-length vector with (approximate) pink noise pink noise has 1/f PSD """ a = [] s = iterpink(depth) - for n in range(N): # FIXME: n is unused here. + for n in range(num_points): # FIXME: num_points is unused here. a.append(next(s)) - return a + return numpy.array(a) def iterpink(depth=20): diff --git a/tests/functional_tests/test_noise.py b/tests/functional_tests/test_noise.py index c21228d..ebae0a7 100644 --- a/tests/functional_tests/test_noise.py +++ b/tests/functional_tests/test_noise.py @@ -17,10 +17,14 @@ def test_noise(): v = noise.violet(N) p = noise.pink(N) + # check output length assert len(w) == N assert len(b) == N assert len(v) == N assert len(p) == N - + # check output type + for x in [w, b, v, p]: + assert type(x) == numpy.ndarray, "%s is not numpy.ndarray" % (type(x)) + if __name__ == "__main__": test_noise()