# 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:

 exponential_sweep_time(n_samples, ...[, ...]) Generate single channel sine sweep with exponentially increasing frequency. impulse(n_samples[, delay, amplitude, ...]) Generate a single or multi channel impulse signal, also known as the Dirac delta function. linear_sweep_time(n_samples, frequency_range) Generate single channel sine sweep with linearly increasing frequency. noise(n_samples[, spectrum, rms, ...]) Generate single or multi channel normally distributed white or pink noise. pulsed_noise(n_pulse, n_pause[, n_fade, ...]) Generate single channel normally distributed pulsed white or pink noise. sine(frequency, n_samples[, amplitude, ...]) Generate a single or multi channel sine signal.
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]:

$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}$$.

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 none FFT normalization (see normalization). The sweep type, frequency range, and length of the fade our are written to comment.

Return type:

Signal

References

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.

$\begin{split}s(n) = \begin{cases} \text{amplitude}, & \text{if n = delay}\\ 0, & \text{else} \end{cases}\end{split}$
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 none FFT normalization (see normalization). The delay and amplitude are written to comment.

Return type:

Signal

Notes

The parameters delay and amplitude are broadcasted to the parameter that contains the most elements. 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 single channel sine sweep with linearly increasing frequency.

Time domain sweep generation according to [2]:

$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}$$.

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.

Return type:

Signal

References

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) – 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.

Return type:

Signal

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 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.

Return type:

Signal

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 rms FFT normalization (see normalization). The exact frequency, amplitude and phase are written to comment.

Return type:

Signal

Notes

The parameters frequency, amplitude, and phase are broadcasted to the parameter that contains the most elements. 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).