Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

red noise generator may not function as intended #37

Open
klapo opened this issue Mar 31, 2021 · 0 comments
Open

red noise generator may not function as intended #37

klapo opened this issue Mar 31, 2021 · 0 comments

Comments

@klapo
Copy link

klapo commented Mar 31, 2021

I think the rednoise function does not produce the results desired. Here is a minimal example based on the function.

from scipy.signal import lfilter
import matplotlib.pyplot as plt
import numpy as np


# This should be strongly non-white when g is close to 1
g = 0.9
# standard deviation of the gaussian white noise
a = 1
# Just a short sample to make visual assessment simpler 
N = 100
tau = int(np.ceil(-2 / np.log(np.abs(g))))

# Save the noise for comparison
noise = np.random.randn(N + tau, 1) * a
# Apply the filter
yr = lfilter([1, 0], [1, -g], noise)
yr = yr[tau:]

# Compare the two
plt.plot(yr)
plt.plot(noise[tau:])

which produces the attached plot. For some reason the parameters passed to lfilter do not modify the noisy time series in the way that I would have anticipated. I verified that rednoise returns flat spectra, consistent with the white noise being unaltered as in the example.

Am I implementing the rednoise function incorrectly?

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant