Generators (dsptoolbox.generators)

Generators

This module contains some utility signal generators. Choose from:

  • chirp() (sweep)

  • noise() (white, pink, red, blue, violet, grey)

  • dirac() (impulse)

  • oscillator()

class dsptoolbox.generators.ChirpType(*values)

Bases: Enum

Chirp types:

  • Logarithmic (or exponential).

  • Linear.

  • The SyncLog chirp is defined according to [2] and ensures that the harmonic responses have coherent phase with the linear response.

References

Linear = 1
Logarithmic = 2
SyncLog = 3
class dsptoolbox.generators.NoiseType(*values)

Bases: Enum

Blue = 4
Grey = 6
Pink = 2
Red = 3
Violet = 5
White = 1
class dsptoolbox.generators.WaveForm(*values)

Bases: Enum

Harmonic = 1
Sawtooth = 4
Square = 2
Triangle = 3
dsptoolbox.generators.chirp(sampling_rate_hz: int, type_of_chirp: ChirpType = ChirpType.Logarithmic, range_hz=None, length_seconds: float = 1.0, peak_level_dbfs: float = -10.0, number_of_channels: int = 1, fade: FadeType = FadeType.Logarithmic, phase_offset: float = 0.0, padding_end_seconds: float = 0.0) Signal | tuple[Signal, float]

Creates a sine-sweep signal.

Parameters:
sampling_rate_hzint

Sampling rate in Hz.

type_of_chirpChirpType, optional

Type of chirp. Default: Logarithmic.

range_hzarray-like with length 2

Define range of chirp in Hz. When None, all frequencies between 15 Hz and nyquist are taken. Default: None.

length_secondsfloat, optional

Length of the generated signal in seconds. Default: 1.

peak_level_dbfsfloat, optional

Peak level of the signal in dBFS. Default: -10.

number_of_channelsint, optional

Number of channels (with the same chirp) to be created. Default: 1.

fadeFadeType, optional

Type of fade done on the generated signal. By default, 10% of signal length (without the padding in the end) is faded at the beginning and end. Default: Logarithmic.

phase_offsetfloat, optional

This is an offset in radians for the phase of the sine. Default: 0.

padding_end_secondsfloat, optional

Padding at the end of signal. Default: 0.

Returns:
chirp_sigSignal

Chirp Signal object.

chirp_duration_secondsfloat

Effective chirp duration. This is only returned if the chirp is of type “sync-log” because the provided length might differ slightly.

Notes

  • The “sync-log” chirp is defined according to [2] and ensures that the harmonic responses have coherent phase with the linear response.

References

dsptoolbox.generators.dirac(length_samples: int, sampling_rate_hz: int, delay_samples: int = 0, number_of_channels: int = 1) ImpulseResponse

Generates a dirac impulse (ImpulseResponse) with the specified length and sampling rate.

Parameters:
length_samplesint

Length in samples.

sampling_rate_hzint

Sampling rate to be used.

delay_samplesint, optional

Delay of the impulse in samples. Default: 0.

number_of_channelsint, optional

Number of channels to be generated with the same impulse. Default: 1.

Returns:
impImpulseResponse

Signal with dirac impulse.

dsptoolbox.generators.noise(length_seconds: float, sampling_rate_hz: int, type_of_noise: NoiseType | float = NoiseType.White, peak_level_dbfs: float = -10.0, number_of_channels: int = 1, fade: FadeType = FadeType.Logarithmic, padding_end_seconds: float = 0.0) Signal

Creates a noise signal.

Parameters:
length_secondsfloat

Length of the generated signal in seconds.

sampling_rate_hzint

Sampling rate in Hz.

type_of_noiseNoiseType, float, optional

Type of noise to generate. If a float is passed, it corresponds to beta, where beta is used to define the slope of the power spectral density (psd) with psd * frequency**(-beta). See notes for details. Default: White.

peak_level_dbfsfloat, optional

Peak level of the signal in dBFS. Default: -10.

number_of_channelsint, optional

Number of channels (with different noise signals) to be created. Default: 1.

fadeFadeType, optional

Type of fade done on the generated signal. By default, 10% of signal length (without the padding in the end) is faded at the beginning and end. Default: Logarithmic.

padding_end_secondsfloat, optional

Padding at the end of signal. Default: 0.

Returns:
noise_sigSignal

Noise Signal object.

Notes

  • Using the beta parameter to define noise is the most flexible approach. For instance, beta=1.0 will deliver pink noise, beta=-1.0 corresponds to blue.

References

dsptoolbox.generators.oscillator(frequency_hz: float, sampling_rate_hz: int, length_seconds: float = 1.0, mode: WaveForm = WaveForm.Harmonic, harmonic_cutoff_hz: float | None = None, peak_level_dbfs: float = -10.0, number_of_channels: int = 1, uncorrelated: bool = False, fade: FadeType = FadeType.Logarithmic, padding_end_seconds: float = 0.0) Signal

Creates a non-aliased, multi-channel wave tone.

Parameters:
frequency_hzfloat, optional

Frequency (in Hz). Default: 1000.

length_secondsfloat, optional

Length of the generated signal in seconds. Default: 1.

modeWaveForm, optional

Type of wave to generate. Default: Harmonic.

harmonic_cutoff_hzfloat, optional

It is possible to pass a cutoff frequency for the harmonics. If None, they are computed up until before the nyquist frequency. Default: None.

sampling_rate_hzint

Sampling rate in Hz. Default: None.

peak_level_dbfsfloat, optional

Peak level of the signal in dBFS. Default: -10.

number_of_channelsint, optional

Number of channels to be created. Default: 1.

uncorrelatedbool, optional

When True, each channel gets a random phase shift so that the signals are not perfectly correlated. Default: False.

fadeFadeType, optional

Type of fade done on the generated signal. By default, 5% of signal length (without the padding in the end) is faded at the beginning and end. Default: Logarithmic.

padding_end_secondsfloat, optional

Padding at the end of signal. Default: 0.

Returns:
wave_signalSignal

Wave signal.