Signal Class
Bases: ndarray
A signal consisting of samples (array) and a sample frequency (float).
| ATTRIBUTE | DESCRIPTION |
|---|---|
fs |
Sample frequency.
|
samples |
Amount of samples in signal.
|
channels |
Amount of channels in signal.
|
duration |
Duration of signal in seconds.
TYPE:
|
values |
Values of signal as instance of
TYPE:
|
Attributes
Functions
__new__
Create a new signal.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Signal values.
|
fs
|
Sample frequency.
|
calibrate_to
calibrate_to(decibel, inplace: bool = False) -> Signal
Calibrate signal to value decibel.
Tip
Values of decibel are broadcasted. To set a value per channel, use decibel[...,None].
| PARAMETER | DESCRIPTION |
|---|---|
decibel
|
Value to calibrate to.
|
inplace
|
Whether to perform inplace or not.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Calibrated signal. |
Source code in acoustic_toolbox/_signal.py
calibrate_with
calibrate_with(
other: Signal, decibel, inplace: bool = False
) -> Signal
Calibrate signal with other signal.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
Other signal/array.
TYPE:
|
decibel
|
Signal level of
|
inplace
|
Whether to perform inplace or not.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Calibrated signal. |
Source code in acoustic_toolbox/_signal.py
decimate
Decimate signal by integer factor. Before downsampling a low-pass filter is applied.
| PARAMETER | DESCRIPTION |
|---|---|
factor
|
Downsampling factor.
|
zero_phase
|
Prevent phase shift by filtering with
DEFAULT:
|
ftype
|
Filter type.
DEFAULT:
|
order
|
Filter order.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Decimated signal. |
.. seealso:: :func:scipy.signal.decimate
.. seealso:: :meth:resample: Decimated signal.
Source code in acoustic_toolbox/_signal.py
resample
Resample signal.
Tip
You might want to low-pass filter this signal before resampling.
| PARAMETER | DESCRIPTION |
|---|---|
samples
|
New amount of samples.
|
times
|
Times corresponding to samples.
DEFAULT:
|
axis
|
Axis.
DEFAULT:
|
window
|
Window.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Resampled signal. |
See Also:
- scipy.signal.resample
- decimate
Source code in acoustic_toolbox/_signal.py
upsample
gain
gain(decibel, inplace: bool = False) -> Signal
Apply gain of decibel decibels.
| PARAMETER | DESCRIPTION |
|---|---|
decibel
|
Decibels
|
inplace
|
In place
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Amplified signal. |
Source code in acoustic_toolbox/_signal.py
pick
Get signal from start time to stop time.
| PARAMETER | DESCRIPTION |
|---|---|
start
|
Start time.
TYPE:
|
stop
|
End time.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Selected part of the signal. |
Source code in acoustic_toolbox/_signal.py
times
times() -> ndarray
Time vector.
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
A vector with a timestamp for each sample. |
energy
energy() -> ndarray
power
ms
rms
weigh
Apply frequency-weighting. By default 'A'-weighting is applied.
Note
By default the weighting filter is applied in the time domain using
scipy.signal.sosfilt causing a frequency-dependent delay.
In case a delay is undesired, the filter can be applied in the frequency domain using
[scipy.signal.fft][] by setting zero_phase=True.
| PARAMETER | DESCRIPTION |
|---|---|
weighting
|
Frequency-weighting filter to apply. Valid options are 'A', 'C' and 'Z'. Default weighting is 'A'.
TYPE:
|
zero_phase
|
Prevent phase shift by filtering with
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Weighted signal. |
Source code in acoustic_toolbox/_signal.py
correlate
correlate(other: Signal | None = None, mode: str = 'full')
Correlate signal with other signal. In case other==None this
method returns the autocorrelation.
| PARAMETER | DESCRIPTION |
|---|---|
other
|
Other signal.
TYPE:
|
mode
|
Mode.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If sample frequencies are not the same. |
ValueError
|
If not supported for multichannel signals. |
See Also
Source code in acoustic_toolbox/_signal.py
amplitude_envelope
Amplitude envelope.
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Amplitude envelope. |
Source code in acoustic_toolbox/_signal.py
instantaneous_frequency
Instantaneous frequency.
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Instantaneous frequency of signal |
Source code in acoustic_toolbox/_signal.py
instantaneous_phase
Instantaneous phase.
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Instantaneous phase of signal |
Source code in acoustic_toolbox/_signal.py
detrend
Detrend signal.
| PARAMETER | DESCRIPTION |
|---|---|
**kwargs
|
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Detrended signal. |
See Also
Source code in acoustic_toolbox/_signal.py
unwrap
Unwrap signal in case the signal represents wrapped phase.
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Unwrapped signal. |
See Also
complex_cepstrum
Complex cepstrum.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Quefrency |
ndarray
|
Complex cepstrum |
int
|
Delay in amount of samples. |
Source code in acoustic_toolbox/_signal.py
real_cepstrum
Real cepstrum.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Quefrency |
|
|
Real cepstrum. |
Source code in acoustic_toolbox/_signal.py
power_spectrum
power_spectrum(N: int | None = None)
Power spectrum.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
TYPE:
|
Source code in acoustic_toolbox/_signal.py
angle_spectrum
angle_spectrum(N: int | None = None)
Phase angle spectrum. Wrapped.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
amount of bins.
TYPE:
|
See Also
Source code in acoustic_toolbox/_signal.py
phase_spectrum
Phase spectrum. Unwrapped.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
DEFAULT:
|
See Also
Source code in acoustic_toolbox/_signal.py
peak
Peak sound pressure.
| PARAMETER | DESCRIPTION |
|---|---|
axis
|
Axis.
DEFAULT:
|
Source code in acoustic_toolbox/_signal.py
peak_level
Peak sound pressure level.
| PARAMETER | DESCRIPTION |
|---|---|
axis
|
Axis.
DEFAULT:
|
Source code in acoustic_toolbox/_signal.py
min
Return the minimum along a given axis.
| PARAMETER | DESCRIPTION |
|---|---|
axis
|
Axis.
DEFAULT:
|
See Also
- Refer to
np.aminfor full documentation.
max
Return the maximum along a given axis.
| PARAMETER | DESCRIPTION |
|---|---|
axis
|
Axis.
DEFAULT:
|
See Also
- Refer to
np.amaxfor full documentation.
max_level
Maximum sound pressure level.
| PARAMETER | DESCRIPTION |
|---|---|
axis
|
Axis.
DEFAULT:
|
Source code in acoustic_toolbox/_signal.py
sound_exposure
Sound exposure.
| PARAMETER | DESCRIPTION |
|---|---|
axis
|
Axis.
DEFAULT:
|
Source code in acoustic_toolbox/_signal.py
sound_exposure_level
Sound exposure level.
| PARAMETER | DESCRIPTION |
|---|---|
axis
|
Axis.
DEFAULT:
|
Source code in acoustic_toolbox/_signal.py
plot_complex_cepstrum
plot_complex_cepstrum(N: int | None = None, **kwargs)
Plot complex cepstrum of signal.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
TYPE:
|
**kwargs
|
DEFAULT:
|
Valid kwargs:
| PARAMETER | DESCRIPTION |
|---|---|
xscale |
X-axis scale.
|
yscale |
Y-axis scale.
|
xlim |
X-axis limits.
|
ylim |
Y-axis limits.
|
frequency |
Boolean indicating whether the x-axis should show time in seconds or quefrency
TYPE:
|
xlabel_frequency |
Label in case frequency is shown.
|
Source code in acoustic_toolbox/_signal.py
plot_real_cepstrum
plot_real_cepstrum(N: int | None = None, **kwargs)
Plot real cepstrum of signal.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
TYPE:
|
**kwargs
|
DEFAULT:
|
Valid kwargs:
| PARAMETER | DESCRIPTION |
|---|---|
xscale |
X-axis scale.
|
yscale |
Y-axis scale.
|
xlim |
X-axis limits.
|
ylim |
Y-axis limits.
|
frequency |
Boolean indicating whether the x-axis should show time in seconds or quefrency
TYPE:
|
xlabel_frequency |
Label in case frequency is shown.
|
Source code in acoustic_toolbox/_signal.py
plot_power_spectrum
Plot spectrum of signal.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
DEFAULT:
|
**kwargs
|
DEFAULT:
|
Valid kwargs:
| PARAMETER | DESCRIPTION |
|---|---|
xscale |
X-axis scale.
|
yscale |
Y-axis scale.
|
xlim |
X-axis limits.
|
ylim |
Y-axis limits.
|
reference |
Reference power
|
Source code in acoustic_toolbox/_signal.py
plot_angle_spectrum
plot_angle_spectrum(N: int | None = None, **kwargs)
Plot phase angle spectrum of signal. Wrapped.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
TYPE:
|
**kwargs
|
DEFAULT:
|
Valid kwargs:
| PARAMETER | DESCRIPTION |
|---|---|
xscale |
X-axis scale.
|
yscale |
Y-axis scale.
|
xlim |
X-axis limits.
|
ylim |
Y-axis limits.
|
reference |
Reference power
|
Source code in acoustic_toolbox/_signal.py
plot_phase_spectrum
plot_phase_spectrum(N: int | None = None, **kwargs)
Plot phase spectrum of signal. Unwrapped.
| PARAMETER | DESCRIPTION |
|---|---|
N
|
Amount of bins.
TYPE:
|
**kwargs
|
DEFAULT:
|
Valid kwargs:
| PARAMETER | DESCRIPTION |
|---|---|
xscale |
X-axis scale.
|
yscale |
Y-axis scale.
|
xlim |
X-axis limits.
|
ylim |
Y-axis limits.
|
reference |
Reference power
|
Source code in acoustic_toolbox/_signal.py
spectrogram
Spectrogram of signal.
| RETURNS | DESCRIPTION |
|---|---|
|
Time |
|
|
Frequency |
|
|
Power |
See Also
See scipy.signal.spectrogram. Some of the default values have been changed.
The generated spectrogram consists by default of complex values.
Source code in acoustic_toolbox/_signal.py
plot_spectrogram
Plot spectrogram of the signal.
Note
This method only works for a single channel.
Valid kwargs:
| PARAMETER | DESCRIPTION |
|---|---|
xlim |
X-axis limits.
|
ylim |
Y-axis limits.
|
clim |
Color limits.
|
NFFT |
Amount of FFT bins.
|
noverlap |
Amount of overlap between FFT bins.
|
title |
Title.
|
xlabel |
X-axis label.
|
ylabel |
Y-axis label.
|
clabel |
Color label.
|
colorbar |
Whether to show the colorbar.
|
Source code in acoustic_toolbox/_signal.py
fast_levels
fast_levels(integration_time: float = 0.125)
Calculate the FAST time weighted level as every integration_time seconds.
| PARAMETER | DESCRIPTION |
|---|---|
integration_time
|
timestep for the output. Default value is 0.125 second (FAST) but can set to other values if desired.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
sound pressure level as function of time. |
See Also
- [
acoustic_toolbox.standards.iec_61672_1_2013.time_averaged_sound_level][] - [
acoustic_toolbox.standards.iec_61672_1_2013.time_weighted_sound_level][]
Source code in acoustic_toolbox/_signal.py
slow_levels
slow_levels(integration_time: float = 1.0)
Calculate the SLOW time weighted level as every integration_time seconds.
| PARAMETER | DESCRIPTION |
|---|---|
integration_time
|
Averaging time constant. Default value is 1.0 second.
TYPE:
|
Returns: sound pressure level as function of time.
Source code in acoustic_toolbox/_signal.py
leq_levels
leq_levels(integration_time: float = 1.0)
Calculate the equivalent level (leq) as every integration_time seconds.
| PARAMETER | DESCRIPTION |
|---|---|
integration_time
|
timestep for the output. Default value is 1.0 second but can set to other values if desired.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
sound pressure level as function of time. |
Source code in acoustic_toolbox/_signal.py
levels
Calculate sound pressure level as function of time.
| PARAMETER | DESCRIPTION |
|---|---|
time
|
Averaging time or integration time constant. Default value is 0.125 corresponding to FAST.
TYPE:
|
method
|
Use time
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
sound pressure level as function of time. |
See Also
Source code in acoustic_toolbox/_signal.py
leq
Equivalent level. Single-value number.
Source code in acoustic_toolbox/_signal.py
plot_levels
Plot sound pressure level as function of time.
See Also
Source code in acoustic_toolbox/_signal.py
bandpass
Filter signal with band-pass filter.
| PARAMETER | DESCRIPTION |
|---|---|
lowcut
|
Lower cornerfrequency.
|
highcut
|
Upper cornerfrequency.
|
order
|
Filter order. (Default value = 8)
DEFAULT:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt). (Default value = False)
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
class
|
TYPE:
|
See Also
Source code in acoustic_toolbox/_signal.py
bandstop
Filter signal with band-stop filter.
| PARAMETER | DESCRIPTION |
|---|---|
lowcut
|
Lower cornerfrequency.
|
highcut
|
Upper cornerfrequency.
|
order
|
Filter order.
TYPE:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Band-pass filtered signal |
See Also
Source code in acoustic_toolbox/_signal.py
highpass
Filter signal with high-pass filter.
| PARAMETER | DESCRIPTION |
|---|---|
cutoff
|
Cornerfrequency.
|
order
|
Filter order.
TYPE:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
High-pass filtered signal |
See Also
Source code in acoustic_toolbox/_signal.py
lowpass
Filter signal with low-pass filter.
| PARAMETER | DESCRIPTION |
|---|---|
cutoff
|
Cornerfrequency.
|
order
|
Filter order.
TYPE:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Low-pass filtered signal |
See Also
Source code in acoustic_toolbox/_signal.py
octavepass
Filter signal with fractional-octave band-pass filter.
| PARAMETER | DESCRIPTION |
|---|---|
center
|
Center frequency. Any value in the band will suffice.
|
fraction
|
Band designator.
|
order
|
Filter order.
TYPE:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Band-pass filtered signal |
See Also
Source code in acoustic_toolbox/_signal.py
bandpass_frequencies
bandpass_frequencies(
frequencies: "Frequencies",
order: int = 8,
purge: bool = True,
zero_phase: bool = False,
) -> tuple["Frequencies", Signal]
Apply bandpass filters for frequencies.
| PARAMETER | DESCRIPTION |
|---|---|
frequencies
|
Instance of :class:
TYPE:
|
order
|
Filter order.
TYPE:
|
purge
|
Discard bands of which the upper corner frequency is above the Nyquist frequency.
TYPE:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
'Frequencies'
|
Frequencies |
Signal
|
Band-pass filtered signal. |
Source code in acoustic_toolbox/_signal.py
octaves
octaves(
frequencies: "Frequencies"
| ndarray = NOMINAL_OCTAVE_CENTER_FREQUENCIES,
order: int = 8,
purge: bool = True,
zero_phase: bool = False,
)
Apply 1/1-octaves bandpass filters.
| PARAMETER | DESCRIPTION |
|---|---|
frequencies
|
Band-pass filter frequencies.
TYPE:
|
order
|
Filter order.
TYPE:
|
purge
|
Discard bands of which the upper corner frequency is above the Nyquist frequency.
TYPE:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Frequencies |
|
|
Band-pass filtered signal. |
Source code in acoustic_toolbox/_signal.py
third_octaves
third_octaves(
frequencies: "Frequencies" = NOMINAL_THIRD_OCTAVE_CENTER_FREQUENCIES,
order: int = 8,
purge: bool = True,
zero_phase: bool = False,
)
Apply ⅓-octaves bandpass filters.
| PARAMETER | DESCRIPTION |
|---|---|
frequencies
|
Band-pass filter frequencies.
TYPE:
|
order
|
Filter order.
TYPE:
|
purge
|
Discard bands of which the upper corner frequency is above the Nyquist frequency.
TYPE:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Frequencies and band-pass filtered signal. |
Source code in acoustic_toolbox/_signal.py
fractional_octaves
fractional_octaves(
frequencies: "Frequencies" | None = None,
fraction: int = 1,
order: int = 8,
purge: bool = True,
zero_phase: bool = False,
)
Apply 1/N-octaves bandpass filters.
| PARAMETER | DESCRIPTION |
|---|---|
frequencies
|
Band-pass filter frequencies.
TYPE:
|
fraction
|
Default band-designator of fractional-octaves.
TYPE:
|
order
|
Filter order.
TYPE:
|
purge
|
Discard bands of which the upper corner frequency is above the Nyquist frequency.
TYPE:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Frequencies and band-pass filtered signal. |
Source code in acoustic_toolbox/_signal.py
plot_octaves
Plot octaves.
See Also
Source code in acoustic_toolbox/_signal.py
plot_third_octaves
Plot ⅓-octaves.
See Also
Source code in acoustic_toolbox/_signal.py
plot_fractional_octaves
plot_fractional_octaves(
frequencies=None,
fraction=1,
order=8,
purge=True,
zero_phase=False,
**kwargs,
)
Plot fractional octaves.
Source code in acoustic_toolbox/_signal.py
plot
Plot signal as function of time. By default the entire signal is plotted.
Valid kwargs:
| PARAMETER | DESCRIPTION |
|---|---|
filename |
Name of file.
|
start |
First sample index.
|
stop |
Last sample index.
|
Source code in acoustic_toolbox/_signal.py
normalize
Normalize signal.
The parameter gap can be understood as using gap decibels fewer for the dynamic range.
By default a 6 decibel gap is used.
| PARAMETER | DESCRIPTION |
|---|---|
gap
|
Gap between maximum value and ceiling in decibel.
DEFAULT:
|
inplace
|
Normalize signal in place.
DEFAULT:
|
Source code in acoustic_toolbox/_signal.py
to_wav
Save signal as WAV file.
By default, this function saves a normalized 16-bit version of the signal with at least 6 dB range till clipping occurs.
| PARAMETER | DESCRIPTION |
|---|---|
filename
|
Name of file to save to.
|
depth
|
If given, convert to integer with specified depth. Else, try to store using the original data type.
DEFAULT:
|
Source code in acoustic_toolbox/_signal.py
from_wav
classmethod
Create an instance of Signal from a WAV file.
| PARAMETER | DESCRIPTION |
|---|---|
filename
|
Filename of WAV file.
|
normalize
|
Whether to normalize the signal.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Signal
|
Signal |
Source code in acoustic_toolbox/_signal.py
:::