Skip to content

Commit

Permalink
Add comment to code
Browse files Browse the repository at this point in the history
  • Loading branch information
hagenw committed Jan 29, 2024
1 parent cc799ce commit 8b725bc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions auglib/core/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3261,10 +3261,14 @@ def _pink_noise(self, samples: int) -> np.ndarray:
def psd(f):
return 1 / np.where(f == 0, float("inf"), np.sqrt(f))

white_noise = np.fft.rfft(np.random.randn(samples + 1))
# Add extra sample
# to ensure correct length for odd samples
length = samples + 1

white_noise = np.fft.rfft(np.random.randn(length))

# Normalized pink noise shape
pink_shape = psd(np.fft.rfftfreq(samples + 1))
pink_shape = psd(np.fft.rfftfreq(length))
pink_shape = pink_shape / np.sqrt(np.mean(pink_shape**2))

white_noise_shaped = white_noise * pink_shape
Expand Down

0 comments on commit 8b725bc

Please sign in to comment.