pycwt icon indicating copy to clipboard operation
pycwt copied to clipboard

red noise generator may not function as intended

Open klapo opened this issue 3 years ago • 0 comments

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

klapo avatar Mar 31 '21 00:03 klapo