Signal Generators¶
Stateless utilities that create test signals without requiring audio
input. All generators return NumPy float64 arrays.
- pyminidsp.sine_wave(n, amplitude=1.0, freq=440.0, sample_rate=44100.0)[source]¶
Generate a sine wave.
- Parameters:
- Returns:
numpy array of length n.
- Return type:
Generate a pure sine tone:
\[x[n] = A \sin(2\pi f \, n / f_s)\]The simplest test signal in DSP. Use it to verify filter responses, check FFT bin alignment, or provide a clean input for any processing chain.
- Parameters:
- Return type:
signal = md.sine_wave(44100, amplitude=1.0, freq=440.0, sample_rate=44100.0)
- pyminidsp.white_noise(n, amplitude=1.0, seed=42)[source]¶
Generate Gaussian white noise.
- Parameters:
- Returns:
numpy array of length n.
- Return type:
Generate Gaussian white noise via the Box-Muller transform. White noise has equal energy at all frequencies — its power spectral density is approximately flat.
Use white noise to test filters, measure impulse responses, or as an additive noise source for SNR experiments.
- Parameters:
- Return type:
noise = md.white_noise(4096, amplitude=1.0, seed=42)
- pyminidsp.impulse(n, amplitude=1.0, position=0)[source]¶
Generate a discrete impulse (Kronecker delta).
- Parameters:
- Returns:
numpy array of length n.
- Return type:
Generate a discrete impulse (Kronecker delta). The output is all zeros except at position, where the value is amplitude.
The unit impulse (amplitude 1.0 at position 0) is the identity element of convolution and has a perfectly flat magnitude spectrum.
Common uses:
Measure a system’s impulse response by feeding it through a filter.
Verify that
magnitude_spectrum()returns a flat spectrum.Create delayed spikes for testing convolution and delay estimation.
- pyminidsp.chirp_linear(n, amplitude=1.0, f_start=200.0, f_end=4000.0, sample_rate=16000.0)[source]¶
Generate a linear chirp (swept sine).
- Parameters:
- Returns:
numpy array of length n.
- Return type:
Generate a linear chirp (swept sine with linearly increasing frequency):
\[f(t) = f_\text{start} + (f_\text{end} - f_\text{start}) \cdot t / T\]A linear chirp is the standard test signal for spectrograms — its instantaneous frequency traces a straight diagonal line in the time-frequency plane.
- Parameters:
- Return type:
# 1-second linear chirp from 200 Hz to 4 kHz at 16 kHz chirp = md.chirp_linear(16000, f_start=200.0, f_end=4000.0, sample_rate=16000.0)
- pyminidsp.chirp_log(n, amplitude=1.0, f_start=20.0, f_end=20000.0, sample_rate=44100.0)[source]¶
Generate a logarithmic chirp.
- Parameters:
- Returns:
numpy array of length n.
- Return type:
Generate a logarithmic chirp (exponentially increasing frequency):
\[f(t) = f_\text{start} \cdot (f_\text{end} / f_\text{start})^{t / T}\]Spends equal time per octave, making it ideal for measuring systems whose behaviour is best described on a log-frequency axis (e.g. audio equaliser response).
- pyminidsp.square_wave(n, amplitude=1.0, freq=440.0, sample_rate=44100.0)[source]¶
Generate a square wave.
Generate a bipolar square wave that alternates between +amplitude and −amplitude.
Contains only odd harmonics (1f, 3f, 5f, …) whose amplitudes decay as 1/k — a classic demonstration of the Fourier series and the Gibbs phenomenon.
- pyminidsp.sawtooth_wave(n, amplitude=1.0, freq=440.0, sample_rate=44100.0)[source]¶
Generate a sawtooth wave.
Generate a sawtooth wave that ramps linearly from −amplitude to +amplitude over each period.
Contains all integer harmonics (1f, 2f, 3f, …) decaying as 1/k — richer harmonic content compared to the square wave.
- pyminidsp.shepard_tone(n, amplitude=0.8, base_freq=440.0, sample_rate=44100.0, rate_octaves_per_sec=0.5, num_octaves=8)[source]¶
Generate a Shepard tone (auditory illusion of endlessly rising/falling pitch).
- Parameters:
n (int) – Number of samples.
amplitude (float) – Peak amplitude.
base_freq (float) – Centre frequency of the Gaussian envelope in Hz.
sample_rate (float) – Sampling rate in Hz.
rate_octaves_per_sec (float) – Glissando rate (positive=rising, negative=falling).
num_octaves (int) – Number of audible octave layers.
- Returns:
numpy array of length n.
- Return type:
Generate a Shepard tone — the auditory illusion of endlessly rising or falling pitch.
Superimposes several sine waves spaced one octave apart. Each tone glides continuously in pitch while a Gaussian spectral envelope — fixed in log-frequency space — fades tones in at one end and out at the other.
\[x[n] = A_\text{norm}\sum_k \exp\!\left(-\frac{d_k(t)^2}{2\sigma^2}\right) \sin(\varphi_k(n))\]- Parameters:
n (int) – Number of samples.
amplitude (float) – Peak amplitude.
base_freq (float) – Centre frequency of the Gaussian envelope (typical: 200–600 Hz).
sample_rate (float) – Sampling rate in Hz.
rate_octaves_per_sec (float) – Glissando rate (positive = rising, negative = falling, 0 = static chord).
num_octaves (int) – Number of audible octave layers (typical: 6–10).
- Return type:
# 5 seconds of endlessly rising Shepard tone sig = md.shepard_tone(5 * 44100, amplitude=0.8, base_freq=440.0, sample_rate=44100.0, rate_octaves_per_sec=0.5)