pyfar.signals¶
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:
n_samples = .015 * sampling_rate.
Functions:
|
This function will be deprecated in pyfar 0.5.0. |
|
Generate single channel sine sweep with exponentially increasing frequency. |
|
Generate a single or multi channel impulse signal, also known as the Dirac delta function. |
|
This function will be deprecated in pyfar 0.5.0. |
|
Generate single channel sine sweep with linearly increasing frequency. |
|
Generate single or multi channel normally distributed white or pink noise. |
|
Generate single channel normally distributed pulsed white or pink noise. |
|
Generate a single or multi channel sine signal. |
- pyfar.signals.exponential_sweep(n_samples, frequency_range, n_fade_out=90, amplitude=1, sweep_rate=None, sampling_rate=44100)[source]¶
This function will be deprecated in pyfar 0.5.0. See
exponential_sweep_time.
- pyfar.signals.exponential_sweep_time(n_samples, frequency_range, n_fade_out=90, amplitude=1, sweep_rate=None, sampling_rate=44100)[source]¶
Generate single channel sine sweep with exponentially increasing frequency.
Time domain sweep generation according to 1:

with

the duration in seconds,
the sampling points in
seconds, and the frequency limits
and
.- 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. If this is given, n_samples is calculated according to the sweep rate. 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
noneFFT normalization (seenormalization). The sweep type, frequency range, and length of the fade our are written to comment.- Return type
References
- 1
Farina, Angelo (2000): “Simultaneous measurement of impulse response and distortion with a swept-sine technique.” 108th AES Convention, Paris: France.
- pyfar.signals.impulse(n_samples, delay=0, amplitude=1, sampling_rate=44100)[source]¶
Generate a single or multi channel impulse signal, also known as the Dirac delta function.

- Parameters
n_samples (int) – Length of the impulse in samples
delay (double, array like, optional) – Delay in samples. The default is
0.amplitude (double, 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
noneFFT normalization (seenormalization). The delay and amplitude are written to comment.- Return type
Notes
The parameters delay and amplitude must be scalars and/or array likes of the same shape.
- pyfar.signals.linear_sweep(n_samples, frequency_range, n_fade_out=90, amplitude=1, sampling_rate=44100)[source]¶
This function will be deprecated in pyfar 0.5.0. See
linear_sweep_time.
- pyfar.signals.linear_sweep_time(n_samples, frequency_range, n_fade_out=90, amplitude=1, sampling_rate=44100)[source]¶
Generate single channel sine sweep with linearly increasing frequency.
Time domain sweep generation according to 2:

with
the duration in seconds,
the sampling points in
seconds, and the frequency limits
and
.- 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
noneFFT normalization (seenormalization). The sweep type, frequency range, and length of the fade our are written to comment.- Return type
References
- 2
Farina, Angelo (2000): “Simultaneous measurement of impulse response and distortion with a swept-sine technique.” 108th AES Convention, Paris: France.
- pyfar.signals.noise(n_samples, spectrum='white', rms=1, sampling_rate=44100, seed=None)[source]¶
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) –
whiteto generate noise with constant energy across frequency.pinkto generate noise with constant energy across filters with constant relative bandwith. The default iswhite.rms (double, array like, optional) – The route 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
rmsFFT normalization (seenormalization). The type of the spectrum (white,pink) and the RMS amplitude are written to comment.- Return type
- pyfar.signals.pulsed_noise(n_pulse, n_pause, n_fade=90, repetitions=5, rms=1, spectrum='pink', frozen=True, sampling_rate=44100, seed=None)[source]¶
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
pinkorwhite. The default ispink.frozen (boolean, optional) – If
True, all noise pulses are identical. IfFalseeach noise pulse is a separate stochastic process. The default isTrue.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
rmsFFT normalization (seenormalization). comment contains information about the selected parameters.- Return type
- pyfar.signals.sine(frequency, n_samples, amplitude=1, phase=0, sampling_rate=44100, full_period=False)[source]¶
Generate a single or multi channel sine signal.
- 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
rmsFFT normalization (seenormalization). The exact frequency, amplitude and phase are written to comment.- Return type
Notes
The parameters frequency, amplitude, and phase must must be scalars and/or array likes of the same shape.