This module contains functions for generating common deterministic and
stochastic audio signals such as impulses, sine sweeps, and noise signals.
All signal lengths are given in samples. The value for the length is casted to
an integer number in all cases. This makes it possible to pass float numbers.
For example:
The exponential sweep can also be generated in the time domain
(exponential_sweep_time). Frequency domain synthesis
exhibits smooth magnitude spectra at the cost of a slightly irregular
temporal envelope. Time domain synthesis exhibits a constant temporal
envelope at the cost of slight ripples in the magnitude response.
Note
The envelope of the sweep time signal should be constant, apart from
slight overshoots at the beginning and end. If this is not the case,
try to increase n_samples, start_margin, stop_margin, n_fade_in
or n_fade_out.
Parameters:
n_samples (int) – The length of the sweep in samples.
frequency_range (array like) – Frequency range of the sweep given by the lower and upper cut-off
frequency in Hz. The restriction of the frequency range is realized
by applying a Butterworth high-pass if frequency_range[0]>0
and/or by a low-pass if frequency_range[1]<sampling_rate/2.
Note that the exponential sweep can not start at 0 Hz, because its
magnitude is defined by 1/frequency.
start_margin (int, float) – The time in samples, at which the sweep starts. The start margin is
required because the frequency domain sweep synthesis has pre-ringing
in the time domain.
stop_margin (int, float) – Time in samples, at which the sweep stops. This is relative to
n_samples, e.g., a stop margin of 100 samples means that the sweep
ends at sample n_samples-100. This is required, because the
frequency domain sweep synthesis has post-ringing in the time domain.
n_fade_in (int, optional) – Duration of a squared sine fade-in in samples. The fade starts at the
first sample of the sweep that is closer than 60 dB to the absolute
maximum of the sweep time signal. The default 0 does not apply
a fade-in.
n_fade_out (int, optional) – Duration of a squared cosine fade-out in samples. The fade ends at the
last sample of the sweep that is closer than 60 dB to the absolute
maximum of the sweep time signal. The default 0 does not apply
a fade-out.
bandpass_order (int, optional) – The order of the Butterworth filters that are applied to limit the
frequency range (see above). The default is 8.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
return_group_delay (boolean, optional) – Return the analytical group delay of the sweep. This can be used to
compute the times at which distortion products appear. The default is
False.
Returns:
sweep (Signal) – The sweep signal. The Signal is in the time domain, has a maximum
absolute amplitude of 1 and the none FFT normalization
(see normalization).
group_delay_sweep (FrequencyData) – The analytical group delay of the sweep in seconds as a single sided
spectrum. Only returned if return_group_delay is True.
\[s(t) = \sin(2\pi f_\mathrm{low} L \left( e^{t/L} - 1 \right))\]
with
\[L = T / \log(f_\mathrm{high}/f_\mathrm{low}),\]
\(T\) the duration in seconds, \(t\) the sampling points in
seconds, and the frequency limits \(f_\mathrm{low}\) and
\(f_\mathrm{high}\).
The exponential sweep can also be generated in the frequency domain (see
see exponential_sweep_freq). Time domain synthesis exhibits a
constant temporal envelope at the cost of slight ripples in the magnitude
response. Frequency domain synthesis exhibits smooth magnitude spectra
at the cost of a slightly irregular temporal envelope.
Parameters:
n_samples (int) – The length of the sweep in samples
frequency_range (array like) – Frequency range of the sweep given by the lower and upper cut-off
frequency in Hz.
n_fade_out (int, optional) – The length of the squared cosine fade-out in samples. This is done to
avoid discontinuities at the end of the sweep. The default is 90,
which equals approximately 2 ms at sampling rates of 44.1 and 48 kHz.
amplitude (double, optional) – The amplitude of the signal. The default is 1.
sweep_rate (double, optional) – Rate at which the sine frequency increases over time in octaves per
second. If this is given, n_samples is calculated according to the
sweep_rate and frequency_range. The default is None, which uses
n_samples without modifications.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
Returns:
sweep – The sweep signal. The Signal is in the time domain and has the none
FFT normalization (see normalization). The
sweep type, frequency range, and length of the fade our are written to
comment.
n_samples (int) – Length of the impulse in samples
delay (double, array like, optional) – Delay in samples. The default is 0.
amplitude (double, array like, optional) – The peak amplitude of the impulse. The default is 1.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
Returns:
signal – The impulse signal. The Signal is in the time domain and has the
none FFT normalization (see
normalization). The delay and amplitude
are written to comment.
The parameters delay and amplitude are broadcasted using the
numpy rules. For example delay
could be of shape (2,4), amplitude of shape (2,1) or a scalar.
In this case all parameters would be broadcasted to a shape of (2,4).
Generate a perfect linear sweep in the frequency domain.
The perfect sweep is generated according to [3] and is used for adaptive
system identification. It is orthogonal to delayed versions of itself.
Parameters:
n_samples (int) – The length of the sweep in samples.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
return_group_delay (boolean, optional) – Return the analytical group delay of the sweep. This can be used to
compute the times at which distortion products appear. The default is
False.
Returns:
sweep (Signal) – The sweep signal. The Signal is in the time domain, has a maximum
absolute amplitude of 1 and the none FFT normalization
(see normalization).
group_delay_sweep (FrequencyData) – The analytical group delay of the sweep in seconds as a single sided
spectrum. Only returned if return_group_delay is True.
References
Examples
Plot a shifted perfect sweep to show that it can be looped
The linear sweep can also be generated in the time domain
(linear_sweep_time). Frequency domain synthesis exhibits
smooth magnitude spectra at the cost of a slightly irregular temporal
envelope. Time domain synthesis exhibits a constant temporal envelope in
trade of slight ripples in the magnitude response.
Note
The envelope of the sweep time signal should be constant, apart from
slight overshoots at the beginning and end. If this is not the case,
try to increase n_samples, start_margin, stop_margin, n_fade_in
or n_fade_out.
Parameters:
n_samples (int) – The length of the sweep in samples.
frequency_range (array like) – Frequency range of the sweep given by the lower and upper cut-off
frequency in Hz. The restriction of the frequency range is realized
by applying a Butterworth high-pass if frequency_range[0]>0
and/or by a low-pass if frequency_range[1]<sampling_rate/2.
start_margin (int, float) – The time in samples, at which the sweep starts. The start margin is
required because the frequency domain sweep synthesis has pre-ringing
in the time domain.
stop_margin (int, float) – Time in samples, at which the sweep stops. This is relative to
n_samples, e.g., a stop margin of 100 samples means that the sweep
ends at sample n_samples-100. This is required, because the
frequency domain sweep synthesis has post-ringing in the time domain.
n_fade_in (int, optional) – Duration of a squared sine fade-in in samples. The fade starts at the
first sample of the sweep that is closer than 60 dB to the absolute
maximum of the sweep time signal. The default 0 does not apply
a fade-in.
n_fade_out (int, optional) – Duration of a squared cosine fade-out in samples. The fade ends at the
last sample of the sweep that is closer than 60 dB to the absolute
maximum of the sweep time signal. The default 0 does not apply
a fade-out.
bandpass_order (int, optional) – The order of the Butterworth filters that are applied to limit the
frequency range (see above). The default is 8.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
return_group_delay (boolean, optional) – Return the analytical group delay of the sweep. This can be used to
compute the times at which distortion products appear. The default is
False.
Returns:
sweep (Signal) – The sweep signal. The Signal is in the time domain, has a maximum
absolute amplitude of 1 and the none FFT normalization
(see normalization).
group_delay_sweep (FrequencyData) – The analytical group delay of the sweep in seconds as a single sided
spectrum. Only returned if return_group_delay is True.
\[s(t) = \sin(2\pi f_\mathrm{low} t + 2\pi (f_\mathrm{high}-
f_\mathrm{low}) / T \cdot t^2 / 2),\]
with \(T\) the duration in seconds, \(t\) the sampling points in
seconds, and the frequency limits \(f_\mathrm{low}\) and
\(f_\mathrm{high}\).
The linear sweep can also be generated in the frequency domain (see
linear_sweep_freq). Time domain synthesis exhibits a constant
temporal envelope at the cost of slight ripples in the magnitude response.
Frequency domain synthesis exhibits smooth magnitude spectra at the cost
of a slightly irregular temporal envelope.
Parameters:
n_samples (int) – The length of the sweep in samples
frequency_range (array like) – Frequency range of the sweep given by the lower and upper cut-off
frequency in Hz.
n_fade_out (int, optional) – The length of the squared cosine fade-out in samples. This is done to
avoid discontinuities at the end of the sweep. The default is 90,
which equals approximately 2 ms at sampling rates of 44.1 and 48 kHz.
amplitude (double, optional) – The amplitude of the signal. The default is 1.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
Returns:
sweep – The sweep signal. The Signal is in the time domain and has the none
FFT normalization (see normalization). The
sweep type, frequency range, and length of the fade our are written to
comment.
Generate sine sweep with arbitrary magnitude spectrum in the frequency
domain.
Frequency domain sine sweep synthesis according to [6]. There is currently
no method to design sine sweeps with arbitrary magnitude response in the
time domain.
Note
The envelope of the sweep time signal should be constant, apart from
slight overshoots at the beginning and end. If this is not the case,
try to increase n_samples, start_margin, stop_margin, n_fade_in
or n_fade_out, or provide a more smooth magnitude spectrum.
Parameters:
n_samples (int) – The length of the sweep in samples.
magnitude_spectrum (Signal) – The magnitude spectrum as a Signal object. Must be at least n_samples
long and is zero-padded to n_samples otherwise.
start_margin (int, float) – The time in samples, at which the sweep starts. The start margin is
required because the frequency domain sweep synthesis has pre-ringing
in the time domain.
stop_margin (int, float) – Time in samples, at which the sweep stops. This is relative to
n_samples, e.g., a stop margin of 100 samples means that the sweep
ends at sample n_samples-100. This is required, because the
frequency domain sweep synthesis has post-ringing in the time domain.
n_fade_in (int, optional) – Duration of a squared sine fade-in in samples. The fade starts at the
first sample of the sweep that is closer than 60 dB to the absolute
maximum of the sweep time signal. The default 0 does not apply
a fade-in.
n_fade_out (int, optional) – Duration of a squared cosine fade-out in samples. The fade ends at the
last sample of the sweep that is closer than 60 dB to the absolute
maximum of the sweep time signal. The default 0 does not apply
a fade-out.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
return_group_delay (boolean, optional) – Return the analytical group delay of the sweep. This can be used to
compute the times at which distortion products appear. The default is
False.
Returns:
sweep (Signal) – The sweep signal. The Signal is in the time domain, has a maximum
absolute amplitude of 1 and the none FFT normalization
(see normalization).
group_delay_sweep (FrequencyData) – The analytical group delay of the sweep in seconds as a single sided
spectrum. Only returned if return_group_delay is True.
Generate single or multi channel normally distributed white or pink noise.
The pink noise is generated by applying a sqrt(1/f) filter to the
spectrum.
Parameters:
n_samples (int) – The length of the signal in samples
spectrum (str, optional) – white to generate noise with constant energy across frequency.
pink to generate noise with constant energy across filters with
constant relative bandwidth. The default is white.
rms (double, array like, optional) – The root mean square (RMS) value of the noise signal. A multi channel
noise signal is generated if an array of RMS values is passed.
The default is 1.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
seed (int, None, optional) – The seed for the random generator. Pass a seed to obtain identical
results for multiple calls. The default is None, which will yield
different results with every call.
Returns:
signal – The noise signal. The signal is in the time domain and has the rms
FFT normalization (see normalization). The
type of the spectrum (white, pink) and the RMS amplitude are
written to comment.
Generate single channel normally distributed pulsed white or pink noise.
The pink noise is generated by applying a sqrt(1/f) filter to the
spectrum.
Parameters:
n_pulse (int) – The length of the pulses in samples
n_pause (int) – The length of the pauses between the pulses in samples.
n_fade (int, optional) – The length of the squared sine/cosine fade-in and fade outs in samples.
The default is 90, which equals approximately 2 ms at sampling
rates of 44.1 and 48 kHz.
repetitions (int, optional) – Specifies the number of noise pulses. The default is 5.
rms (double, array like, optional) – The RMS amplitude of the white signal. The default is 1.
spectrum (string, optional) – The noise spectrum, which can be pink or white. The default is
pink.
frozen (boolean, optional) – If True, all noise pulses are identical. If False each noise
pulse is a separate stochastic process. The default is True.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
seed (int, None, optional) – The seed for the random generator. Pass a seed to obtain identical
results for multiple calls. The default is None, which will yield
different results with every call.
Returns:
signal – The noise signal. The Signal is in the time domain and has the rms
FFT normalization (see normalization).
comment contains information about the selected parameters.
frequency (double, array like) – Frequency of the sine in Hz (0 <= frequency <= sampling_rate/2).
n_samples (int) – Length of the signal in samples.
amplitude (double, array like, optional) – The amplitude. The default is 1.
phase (double, array like, optional) – The phase in radians. The default is 0.
sampling_rate (int, optional) – The sampling rate in Hz. The default is 44100.
full_period (boolean, optional) – Make sure that the returned signal contains an integer number of
periods resulting in a periodic signal. This is done by adjusting the
frequency of the sine. The default is False.
Returns:
signal – The sine signal. The Signal is in the time domain and has the rms
FFT normalization (see normalization).
The exact frequency, amplitude and phase are written to comment.
The parameters frequency, amplitude, and phase are broadcasted using
the numpy rules. For example
frequency could be of shape (2,4), amplitude of shape (2,1),
and phase could be a scalar. In this case all parameters would be
broadcasted to a shape of (2,4).