Skip to content

Commit

Permalink
add test for noise output type
Browse files Browse the repository at this point in the history
  • Loading branch information
aewallin committed Jul 25, 2019
1 parent f2feeac commit bffddf4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 4 additions & 4 deletions allantools/noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 5 additions & 1 deletion tests/functional_tests/test_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit bffddf4

Please sign in to comment.