A package to generate custom noise signals with 1/f^alpha PSD.
Project description
Custom Noise Generator
A Python package for generating noise signals with custom power spectral density (PSD) of 1/f^alpha.
Installation
pip install custom_noise
Or install from source:
git clone https://github.com/commuted/custom_noise.git
cd custom_noise
pip install -e .
Quick Start
from custom_noise import pink_noise, brown_noise
# Generate 5 seconds of pink noise
signal = pink_noise(duration=5)
# Save brown noise to a WAV file
brown_noise(duration=10, output_file="brown_noise.wav")
Noise Types
| Function | Alpha | Description |
|---|---|---|
white_noise() |
0 | Equal power at all frequencies |
pink_noise() |
1 | 1/f spectrum, equal power per octave |
brown_noise() |
2 | 1/f² spectrum, deep rumbling (also called red/Brownian noise)* |
blue_noise() |
-1 | f spectrum, bright/hissing quality |
violet_noise() |
-2 | f² spectrum, high-frequency emphasis |
*Note: True Brownian noise has infinite power at DC (0 Hz), causing unbounded drift. This implementation leaves the DC component unscaled to produce a bounded, stationary signal suitable for audio use.
Usage
Basic Usage
from custom_noise import pink_noise, white_noise, brown_noise
# Generate noise (returns numpy array)
signal = pink_noise(duration=3)
# Save directly to file
white_noise(duration=5, output_file="white.wav")
# Custom sample rate
signal = brown_noise(duration=2, sample_rate=48000)
Output Formats
from custom_noise import pink_noise
# 16-bit integers (default) - ready for WAV files
signal_int = pink_noise(duration=1, dtype="int16")
# Normalized float [-1.0, 1.0] - for DSP processing
signal_float = pink_noise(duration=1, dtype="float32")
Custom Alpha Values
For noise colors not covered by the convenience functions:
from custom_noise import generate_custom_noise
# Custom alpha value
signal = generate_custom_noise(alpha=0.5, duration=3)
# Gray noise (alpha ≈ 1, psychoacoustically balanced)
signal = generate_custom_noise(alpha=1, duration=5)
Reproducibility
from custom_noise import pink_noise
# Same seed = same output
signal1 = pink_noise(duration=1, random_seed=42)
signal2 = pink_noise(duration=1, random_seed=42)
assert (signal1 == signal2).all()
# Random each time
signal = pink_noise(duration=1, random_seed=None)
Visualization
from custom_noise import generate_custom_noise
# Plot the power spectral density
generate_custom_noise(alpha=1, duration=3, plot_psd=True)
Command Line Interface
# Generate pink noise
python -m custom_noise --type pink --duration 5 -o pink.wav
# Generate with custom alpha
python -m custom_noise --alpha 1.5 --duration 10 -o custom.wav
# Show PSD plot
python -m custom_noise --type brown --duration 3 --plot
# See all options
python -m custom_noise --help
CLI Options
| Option | Description |
|---|---|
-t, --type TYPE |
Noise type: white, pink, brown, blue, violet |
-a, --alpha ALPHA |
Custom alpha exponent |
-d, --duration SECONDS |
Duration in seconds (default: 3) |
-r, --sample-rate HZ |
Sample rate in Hz (default: 44100) |
-o, --output FILE |
Output WAV file path |
--plot |
Display PSD plot |
-s, --seed SEED |
Random seed for reproducibility |
API Reference
Convenience Functions
All convenience functions share these parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
duration |
float | 3 | Duration in seconds |
sample_rate |
int | 44100 | Sample rate in Hz |
output_file |
str | None | Path to save WAV file |
random_seed |
int | 42 | Seed for reproducibility (None for random) |
dtype |
str | "int16" | Output type: "int16", "float32", "float64" |
generate_custom_noise()
Full control over noise generation:
generate_custom_noise(
sample_rate=44100, # Sample rate in Hz
duration=3, # Duration in seconds
alpha=None, # PSD exponent (mutually exclusive with noise_type)
noise_type=None, # Preset: "white", "pink", "brown", "blue", "violet"
output_file=None, # Path to save WAV file
plot_psd=False, # Show PSD plot
random_seed=42, # Seed for reproducibility
dtype="int16", # Output format
)
How It Works
- Generate Gaussian white noise
- Apply FFT to transform to frequency domain
- Scale frequencies by 1/|f|^(α/2) to achieve desired PSD slope
- Inverse FFT back to time domain
- Normalize and convert to requested output format
Requirements
- Python >= 3.9
- NumPy
- SciPy
- Matplotlib (for plotting)
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file custom_noise-0.1.0.tar.gz.
File metadata
- Download URL: custom_noise-0.1.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
728926df32b2ecd164ccddcacc12d1efc2f56ae1884e5503a2407ba52538a763
|
|
| MD5 |
7db07f7e6381a53550ac3438334045f8
|
|
| BLAKE2b-256 |
20409ae9e2419fa74e5fed42a5136a3b374691073e50998b7db8f7f722d5ab4e
|
Provenance
The following attestation bundles were made for custom_noise-0.1.0.tar.gz:
Publisher:
publish.yml on commuted/Noise_generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
custom_noise-0.1.0.tar.gz -
Subject digest:
728926df32b2ecd164ccddcacc12d1efc2f56ae1884e5503a2407ba52538a763 - Sigstore transparency entry: 927078184
- Sigstore integration time:
-
Permalink:
commuted/Noise_generator@05729f599f6b0de319c15aa3a819197d1c64bc6d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/commuted
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@05729f599f6b0de319c15aa3a819197d1c64bc6d -
Trigger Event:
push
-
Statement type:
File details
Details for the file custom_noise-0.1.0-py3-none-any.whl.
File metadata
- Download URL: custom_noise-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fed925312c31931d07c6bd5327b5e95c349a1801b633dda2075c75d6e4d7f21c
|
|
| MD5 |
7861be90cf7c4c1cc8376d4e27bd6903
|
|
| BLAKE2b-256 |
98b20202bed2e62ec99d3dc543eed0b39b778edbe0269222e20f8c7ad7cda491
|
Provenance
The following attestation bundles were made for custom_noise-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on commuted/Noise_generator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
custom_noise-0.1.0-py3-none-any.whl -
Subject digest:
fed925312c31931d07c6bd5327b5e95c349a1801b633dda2075c75d6e4d7f21c - Sigstore transparency entry: 927078186
- Sigstore integration time:
-
Permalink:
commuted/Noise_generator@05729f599f6b0de319c15aa3a819197d1c64bc6d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/commuted
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@05729f599f6b0de319c15aa3a819197d1c64bc6d -
Trigger Event:
push
-
Statement type: