Signal Processing Module
The signal module contains all kinds of signal processing related functions.
Filtering
| CLASS | DESCRIPTION |
|---|---|
Filterbank |
Fractional-Octave filter bank. |
| FUNCTION | DESCRIPTION |
|---|---|
bandpass_filter |
Band-pass filter. |
bandpass |
Filter signal with band-pass filter. |
lowpass |
Filter signal with low-pass filter. |
highpass |
Filter signal with high-pass filter. |
octave_filter |
Fractional-octave band-pass filter. |
convolve |
Perform convolution of a signal with a linear time-variant system. |
Windowing
| FUNCTION | DESCRIPTION |
|---|---|
window_scaling_factor |
Calculate window scaling factor. |
apply_window |
Apply window to signal. |
Spectra
| FUNCTION | DESCRIPTION |
|---|---|
amplitude_spectrum |
Amplitude spectrum of instantaneous signal. |
auto_spectrum |
Auto-spectrum of instantaneous signal. |
power_spectrum |
Power spectrum of instantaneous signal. |
density_spectrum |
Density spectrum of instantaneous signal. |
angle_spectrum |
Phase angle spectrum of instantaneous signal. |
phase_spectrum |
Phase spectrum of instantaneous signal. |
Frequency bands
| CLASS | DESCRIPTION |
|---|---|
Frequencies |
Object describing frequency bands. |
EqualBand |
Equal bandwidth spectrum. |
OctaveBand |
Fractional-octave band spectrum. |
| FUNCTION | DESCRIPTION |
|---|---|
integrate_bands |
Reduce frequency resolution of power spectrum. |
octaves |
Calculate level per 1/1-octave in frequency domain. |
third_octaves |
Calculate level per ⅓-octave in frequency domain. |
Hilbert transform
| FUNCTION | DESCRIPTION |
|---|---|
amplitude_envelope |
Instantaneous amplitude of tone. |
instantaneous_phase |
Instantaneous phase of tone. |
instantaneous_frequency |
Determine instantaneous frequency of tone. |
Conversion
| FUNCTION | DESCRIPTION |
|---|---|
decibel_to_neper |
Convert decibel to neper. |
neper_to_decibel |
Convert neper to decibel. |
Other
| FUNCTION | DESCRIPTION |
|---|---|
isolate |
Isolate signals. |
zero_crossings |
Determine the positions of zero crossings in data. |
rms |
Root mean squared of signal. |
ms |
Mean value of signal squared. |
normalize |
Normalize power in signal. |
ir2fr |
Convert impulse response into frequency response. |
wvd |
Wigner-Ville Distribution. |
Attributes
Classes
Frequencies
Frequencies(
center: NDArray[float64] | list[float],
lower: NDArray[float64] | list[float],
upper: NDArray[float64] | list[float],
bandwidth: NDArray[float64] | list[float] | None = None,
)
Object describing frequency bands.
| ATTRIBUTE | DESCRIPTION |
|---|---|
center |
Center frequencies. |
lower |
Lower frequencies. |
upper |
Upper frequencies. |
bandwidth |
Bandwidth. |
Source code in acoustic_toolbox/signal.py
Functions
angular
EqualBand
EqualBand(
center=None,
fstart=None,
fstop=None,
nbands: int | None = None,
bandwidth=None,
)
Bases: Frequencies
Equal bandwidth spectrum. Generally used for narrowband data.
| ATTRIBUTE | DESCRIPTION |
|---|---|
center |
Center frequencies. |
fstart |
First center frequency. |
fstop |
Last center frequency. |
nbands |
Amount of frequency bands. |
bandwidth |
Bandwidth of bands. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the center frequencies are not equally spaced. |
ValueError
|
If insufficient parameters are provided. |
Source code in acoustic_toolbox/signal.py
Functions
OctaveBand
OctaveBand(
center=None,
fstart=None,
fstop=None,
nbands: int | None = None,
fraction=1,
reference=REFERENCE,
)
Bases: Frequencies
Fractional-octave band spectrum.
| ATTRIBUTE | DESCRIPTION |
|---|---|
center |
Center frequencies. |
fstart |
First center frequency. |
fstop |
Last center frequency. |
nbands |
Amount of frequency bands. |
bandwidth |
Bandwidth. |
fraction |
Fraction of fractional-octave filter.
|
reference |
Reference center frequency.
|
nominal |
Nominal center frequencies.
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If insufficient parameters are provided. |
Source code in acoustic_toolbox/signal.py
Functions
Filterbank
Filterbank(
frequencies: Frequencies,
sample_frequency: float = 44100,
order: int = 8,
)
Fractional-Octave filter bank.
Warning
For high frequencies the filter coefficients are wrong for low frequencies. Therefore, to improve the response for lower frequencies the signal should be downsampled. Currently, there is no easy way to do so within the Filterbank.
| ATTRIBUTE | DESCRIPTION |
|---|---|
frequencies |
Frequencies object.
See also Note: A frequencies attribute should have the attributes center, lower, and upper.
|
order |
Filter order of Butterworth filter.
|
sample_frequency |
Sample frequency.
|
Source code in acoustic_toolbox/signal.py
Attributes
sample_frequency
property
writable
Sample frequency.
| RETURNS | DESCRIPTION |
|---|---|
float
|
Sample frequency. |
filters
property
Filters this filterbank consists of.
| RETURNS | DESCRIPTION |
|---|---|
generator
|
Filter coefficients for each band. |
Functions
lfilter
Filter signal with filterbank.
Note
This function uses scipy.signal.lfilter.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be filtered. |
| RETURNS | DESCRIPTION |
|---|---|
generator
|
Filtered signal for each band.
TYPE:
|
Source code in acoustic_toolbox/signal.py
filtfilt
Filter signal with filterbank.
Note
This function uses scipy.signal.filtfilt and therefore has a zero-phase response.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be filtered. |
| RETURNS | DESCRIPTION |
|---|---|
None
|
List consisting of a filtered signal per filter. |
Source code in acoustic_toolbox/signal.py
power
Power per band in signal.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be analyzed. |
| RETURNS | DESCRIPTION |
|---|---|
NDArray[float64]
|
np.ndarray: Power per band. |
Source code in acoustic_toolbox/signal.py
plot_response
Plot frequency response.
Note
The following phase response is obtained in case lfilter is used.
The method filtfilt has a zero-phase response.
| RETURNS | DESCRIPTION |
|---|---|
|
matplotlib.figure.Figure: Figure with frequency response plot. |
Source code in acoustic_toolbox/signal.py
plot_power
Plot power in signal.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be analyzed.
|
| RETURNS | DESCRIPTION |
|---|---|
|
matplotlib.figure.Figure: Figure with power plot. |
Source code in acoustic_toolbox/signal.py
Functions
bandpass_filter
bandpass_filter(
lowcut: float,
highcut: float,
fs: float,
order: int = 8,
output: str = "sos",
) -> tuple | None
Band-pass filter.
| PARAMETER | DESCRIPTION |
|---|---|
lowcut
|
Lower cut-off frequency.
TYPE:
|
highcut
|
Upper cut-off frequency.
TYPE:
|
fs
|
Sample frequency.
TYPE:
|
order
|
Filter order. Defaults to 8.
TYPE:
|
output
|
Output type. {'ba', 'zpk', 'sos'}.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Filter coefficients depending on
TYPE:
|
See Also
scipy.signal.butter: For more details on the Butterworth filter.
Source code in acoustic_toolbox/signal.py
bandpass
bandpass(
signal: ndarray,
lowcut: float,
highcut: float,
fs: float,
order: int = 8,
zero_phase: bool = False,
) -> ndarray
Filter signal with band-pass filter.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be filtered.
TYPE:
|
lowcut
|
Lower cut-off frequency.
TYPE:
|
highcut
|
Upper cut-off frequency.
TYPE:
|
fs
|
Sample frequency.
TYPE:
|
order
|
Filter order. Defaults to 8.
TYPE:
|
zero_phase
|
If True, uses
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
Filtered signal. |
See Also
bandpass_filter: The filter that is used.
Source code in acoustic_toolbox/signal.py
bandstop
bandstop(
signal,
lowcut,
highcut,
fs,
order=8,
zero_phase: bool = False,
)
Filter signal with band-stop filter.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be filtered.
|
lowcut
|
Lower cut-off frequency.
|
highcut
|
Upper cut-off frequency.
|
fs
|
Sample frequency.
|
order
|
Filter order. Defaults to 8.
DEFAULT:
|
zero_phase
|
If True, uses filtfilt to prevent phase error. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Filtered signal. |
Source code in acoustic_toolbox/signal.py
lowpass
lowpass(
signal, cutoff, fs, order=4, zero_phase: bool = False
)
Filter signal with low-pass filter.
A Butterworth filter is used. Filtering is done with second-order sections.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be filtered.
|
cutoff
|
Cut-off frequency.
|
fs
|
Sample frequency.
|
order
|
Filter order. Defaults to 4.
DEFAULT:
|
zero_phase
|
If True, uses filtfilt to prevent phase error. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Filtered signal. |
See Also
scipy.signal.butter: For more details on the Butterworth filter.
Source code in acoustic_toolbox/signal.py
highpass
highpass(
signal, cutoff, fs, order=4, zero_phase: bool = False
)
Filter signal with high-pass filter.
A Butterworth filter is used. Filtering is done with second-order sections.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be filtered.
|
cutoff
|
Cut-off frequency.
|
fs
|
Sample frequency.
|
order
|
Filter order. Defaults to 4.
DEFAULT:
|
zero_phase
|
If True, uses filtfilt to prevent phase error. Defaults to False.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Filtered signal. |
See Also
scipy.signal.butter: For more details on the Butterworth filter.
Source code in acoustic_toolbox/signal.py
octave_filter
octave_filter(
center, fs, fraction, order=8, output: str = "sos"
)
Fractional-octave band-pass filter.
A Butterworth filter is used. Args: center: Center frequency of fractional-octave band. fs: Sample frequency. fraction: Fraction of fractional-octave band. order: Filter order. Defaults to 8. output: Output type. {'ba', 'zpk', 'sos'}. Defaults to 'sos'.
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Filter coefficients depending on |
See Also
bandpass_filter: Used to create the fractional-octave filter.
Source code in acoustic_toolbox/signal.py
octavepass
octavepass(
signal,
center,
fs,
fraction,
order=8,
zero_phase: bool = True,
)
Filter signal with fractional-octave bandpass filter.
A Butterworth filter is used. Filtering is done with second-order sections.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal to be filtered.
|
center
|
Center frequency of fractional-octave band.
|
fs
|
Sample frequency.
|
fraction
|
Fraction of fractional-octave band.
|
order
|
Filter order. Defaults to 8.
DEFAULT:
|
zero_phase
|
If True, uses filtfilt to prevent phase error. Defaults to True.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Filtered signal. |
See Also
octave_filter: The filter that is used.
Source code in acoustic_toolbox/signal.py
convolve
Perform convolution of a signal with a linear time-variant system (ltv).
Notes
The convolution of two sequences is given by $$ \mathbf{y} = \mathbf{t} \star \mathbf{u} $$
This can be written as a matrix-vector multiplication $$ \mathbf{y} = \mathbf{T} \cdot \mathbf{u} $$
where \(T\) is a Toeplitz matrix in which each column represents an impulse response. In the case of a linear time-invariant (LTI) system, each column represents a time-shifted copy of the first column. In the time-variant case (LTV), every column can contain a unique impulse response, both in values as in size.
This function assumes all impulse responses are of the same size.
The input matrix ltv thus represents the non-shifted version of the Toeplitz matrix.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Vector representing the input signal \(u\).
|
ltv
|
2D array where each column represents an impulse response.
TYPE:
|
mode
|
{'full', 'valid', 'same'}. Determines the size of the output.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
The result of the convolution operation. |
| RAISES | DESCRIPTION |
|---|---|
AssertionError
|
If the length of the signal does not match the number of columns in |
See Also
For convolution with LTI systems.
Source code in acoustic_toolbox/signal.py
ir2fr
ir2fr(ir, fs, N: int | None = None)
Convert impulse response into frequency response. Returns single-sided RMS spectrum.
Calculates the positive frequencies using np.fft.rfft.
Corrections are then applied to obtain the single-sided spectrum.
Note
Single-sided spectrum. Therefor the amount of bins returned is either N/2 or N/2+1.
| PARAMETER | DESCRIPTION |
|---|---|
ir
|
Impulse response.
|
fs
|
Sample frequency.
|
N
|
Blocks
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Frequencies and frequency response. |
See Also
np.fft.rfft: Used for calculating the positive frequencies.
Source code in acoustic_toolbox/signal.py
decibel_to_neper
Convert decibel to neper.
Note
The conversion is given by $$ \mathrm{dB} = \frac{\log{10}}{20} \mathrm{Np} $$
| PARAMETER | DESCRIPTION |
|---|---|
decibel
|
Value in decibel (dB).
|
| RETURNS | DESCRIPTION |
|---|---|
|
Value in neper (Np). |
See Also
neper_to_decibel: For the reverse conversion.
Source code in acoustic_toolbox/signal.py
neper_to_decibel
Convert neper to decibel.
Note
The conversion is given by $$ \mathrm{Np} = \frac{20}{\log{10}} \mathrm{dB} $$
| PARAMETER | DESCRIPTION |
|---|---|
neper
|
Value in neper (Np).
|
| RETURNS | DESCRIPTION |
|---|---|
|
Value in decibel (dB). |
See Also
decibel_to_neper: For the reverse conversion.
Source code in acoustic_toolbox/signal.py
ms
Mean value of signal x squared.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Dynamic quantity.
|
| RETURNS | DESCRIPTION |
|---|---|
|
Mean squared of |
rms
Root mean squared of signal x.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Dynamic quantity.
|
| RETURNS | DESCRIPTION |
|---|---|
|
Root mean squared value of |
|
|
$$ |
|
|
x_{rms} = \lim_{T \to \infty} \sqrt{\frac{1}{T} \int_0^T |f(x)|^2 \mathrm{d} t } |
|
|
$$ |
See Also
Source code in acoustic_toolbox/signal.py
normalize
Normalize power in y to a (standard normal) white noise signal.
Optionally normalize to power in signal x.
Note
The mean power of a Gaussian with \(\mu=0\) and \(\sigma=1\) is 1.
| PARAMETER | DESCRIPTION |
|---|---|
y
|
Signal to be normalized.
|
x
|
Reference signal. Defaults to None.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Normalized signal. |
Source code in acoustic_toolbox/signal.py
window_scaling_factor
window_scaling_factor(window, axis: int = -1)
Calculate window scaling factor.
When analysing broadband (filtered noise) signals, it is common to normalize the windowed signal so that it has the same power as the un-windowed signal. $$ S = \sqrt{\frac{\sum_{i=0}^N w_i^2}{N}} $$
| PARAMETER | DESCRIPTION |
|---|---|
window
|
Window.
|
axis
|
Axis along which to calculate.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Window scaling factor. |
Source code in acoustic_toolbox/signal.py
apply_window
Apply window to signal.
where \(S\) is the window scaling factor.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
window
|
Vector representing window.
|
| RETURNS | DESCRIPTION |
|---|---|
|
Signal with window applied. |
See Also
window_scaling_factor: For calculating the scaling factor.
Source code in acoustic_toolbox/signal.py
amplitude_spectrum
amplitude_spectrum(x, fs, N: int | None = None)
Amplitude spectrum of instantaneous signal \(x(t)\).
The amplitude spectrum gives the amplitudes of the sinusoidal the signal is built up from, and the RMS (root-mean-square) amplitudes can easily be found by dividing these amplitudes with \(\sqrt{2}\)
The amplitude spectrum is double-sided.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency \(f_s\).
|
N
|
Number of FFT bins.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
Frequencies and amplitude spectrum. |
Source code in acoustic_toolbox/signal.py
auto_spectrum
auto_spectrum(x, fs, N: int | None = None)
Auto-spectrum of instantaneous signal \(x(t)\).
The auto-spectrum contains the squared amplitudes of the signal. Squared amplitudes are used when presenting data as it is a measure of the power/energy in the signal.
The auto-spectrum is double-sided.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency \(f_s\).
|
N
|
Number of FFT bins.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
f
|
Frequencies |
a
|
Auto-spectrum |
Source code in acoustic_toolbox/signal.py
power_spectrum
power_spectrum(x, fs, N: int | None = None)
Power spectrum of instantaneous signal \(x(t)\).
The power spectrum, or single-sided autospectrum, contains the squared RMS amplitudes of the signal.
A power spectrum is a spectrum with squared RMS values. The power spectrum is calculated from the autospectrum of the signal.
Warning
Does not include scaling to reference value!
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency \(f_s\).
|
N
|
Number of FFT bins.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
f
|
Frequencies |
a
|
Power spectrum |
See Also
Source code in acoustic_toolbox/signal.py
angle_spectrum
angle_spectrum(x, fs, N: int | None = None)
Phase angle spectrum of instantaneous signal \(x(t)\).
This function returns a single-sided phase angle spectrum.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency \(f_s\).
|
N
|
Number of FFT bins.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
f
|
Frequencies |
a
|
Phase angle spectrum |
See Also
phase_spectrum: For unwrapped phase spectrum.
Source code in acoustic_toolbox/signal.py
phase_spectrum
phase_spectrum(x, fs, N: int | None = None)
Phase spectrum of instantaneous signal \(x(t)\).
This function returns single-sided unwrapped phase spectrum.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency \(f_s\).
|
N
|
Number of FFT bins.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
f
|
Frequencies |
a
|
Unwrapped phase spectrum |
See Also
angle_spectrum: For wrapped phase angle.
Source code in acoustic_toolbox/signal.py
density_spectrum
density_spectrum(x, fs, N: int | None = None)
Density spectrum of instantaneous signal \(x(t)\).
A density spectrum considers the amplitudes per unit frequency. Density spectra are used to compare spectra with different frequency resolution as the magnitudes are not influenced by the resolution because it is per Hertz. The amplitude spectra on the other hand depend on the chosen frequency resolution.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency \(f_s\).
|
N
|
Number of FFT bins.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
f
|
Frequencies |
a
|
Density spectrum |
Source code in acoustic_toolbox/signal.py
integrate_bands
Reduce frequency resolution of power spectrum. Merges frequency bands by integration.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Vector with narrowband powers.
|
a
|
Instance of
|
b
|
Instance of
|
| RETURNS | DESCRIPTION |
|---|---|
|
Integrated bands. |
| RAISES | DESCRIPTION |
|---|---|
NotImplementedError
|
If the ratio of fractional-octaves is not an integer. |
Todo
Needs rewriting so that the summation goes over axis=1.
Source code in acoustic_toolbox/signal.py
bandpass_frequencies
bandpass_frequencies(
x,
fs,
frequencies: Frequencies,
order: int = 8,
purge: bool = False,
zero_phase: bool = False,
) -> tuple[Frequencies, ndarray]
Apply bandpass filters for frequencies.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency.
|
frequencies
|
Instance of
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 |
|---|---|
OctaveBand
|
Instance of
TYPE:
|
ndarray
|
np.ndarray: Filtered array. |
Source code in acoustic_toolbox/signal.py
bandpass_octaves
bandpass_octaves(
x,
fs,
frequencies=NOMINAL_OCTAVE_CENTER_FREQUENCIES,
order=8,
purge=False,
zero_phase: bool = False,
) -> tuple[OctaveBand, ndarray]
Apply 1/1-octave bandpass filters.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency.
|
frequencies
|
Center frequencies.
DEFAULT:
|
order
|
Filter order.
DEFAULT:
|
purge
|
Discard bands of which the upper corner frequency is above the Nyquist frequency.
DEFAULT:
|
zero_phase
|
Prevent phase error by filtering in both directions (filtfilt)
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OctaveBand
|
Instance of
TYPE:
|
ndarray
|
np.ndarray: Filtered array. |
See Also
Source code in acoustic_toolbox/signal.py
bandpass_third_octaves
bandpass_third_octaves(
x,
fs,
frequencies=NOMINAL_THIRD_OCTAVE_CENTER_FREQUENCIES,
order: int = 8,
purge: bool = False,
zero_phase: bool = False,
) -> tuple[OctaveBand, ndarray]
Apply ⅓-octave bandpass filters.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency.
|
frequencies
|
Center frequencies. |
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 |
|---|---|
OctaveBand
|
Instance of
TYPE:
|
ndarray
|
np.ndarray: Filtered array. |
See Also
Source code in acoustic_toolbox/signal.py
bandpass_fractional_octaves
bandpass_fractional_octaves(
x,
fs,
frequencies,
fraction=None,
order: int = 8,
purge: bool = False,
zero_phase: bool = False,
) -> tuple[OctaveBand, ndarray]
Apply 1/N-octave bandpass filters.
| PARAMETER | DESCRIPTION |
|---|---|
x
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency.
|
frequencies
|
Center frequencies or instance of
|
fraction
|
Fraction of fractional-octave band.
DEFAULT:
|
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 |
|---|---|
OctaveBand
|
Instance of
TYPE:
|
ndarray
|
np.ndarray: Filtered array. |
See Also
Source code in acoustic_toolbox/signal.py
third_octaves
third_octaves(
p,
fs,
density: bool = False,
frequencies=NOMINAL_THIRD_OCTAVE_CENTER_FREQUENCIES,
ref: float = REFERENCE_PRESSURE,
) -> tuple[OctaveBand, ndarray]
Calculate level per ⅓-octave in frequency domain using the FFT.
Note
Exact center frequencies are always calculated.
| PARAMETER | DESCRIPTION |
|---|---|
p
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency.
|
density
|
Calculate power density instead of power.
TYPE:
|
frequencies
|
Center frequencies. |
ref
|
Reference pressure.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OctaveBand
|
Instance of
TYPE:
|
ndarray
|
np.ndarray: Level array. |
Source code in acoustic_toolbox/signal.py
octaves
octaves(
p,
fs,
density=False,
frequencies=NOMINAL_OCTAVE_CENTER_FREQUENCIES,
ref=REFERENCE_PRESSURE,
)
Calculate level per 1/1-octave in frequency domain using the FFT.
Notes
- Based on power spectrum (FFT)
- Exact center frequencies are always calculated.
| PARAMETER | DESCRIPTION |
|---|---|
p
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency.
|
density
|
Calculate power density instead of power.
DEFAULT:
|
frequencies
|
Center frequencies.
DEFAULT:
|
ref
|
Reference value.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
OctaveBand
|
Instance of |
|
np.ndarray: Level array. |
See Also
Source code in acoustic_toolbox/signal.py
fractional_octaves
fractional_octaves(
p,
fs,
start: float = 5.0,
stop: float = 16000.0,
fraction: int = 3,
density: bool = False,
ref: float = REFERENCE_PRESSURE,
)
Calculate level per 1/N-octave in frequency domain using the FFT. N is fraction.
Notes
- Based on power spectrum (FFT)
- This function does not use nominal center frequencies.
- Exact center frequencies are always calculated.
| PARAMETER | DESCRIPTION |
|---|---|
p
|
Instantaneous signal \(x(t)\).
|
fs
|
Sample frequency.
|
start
|
Start frequency.
TYPE:
|
stop
|
Stop frequency.
TYPE:
|
fraction
|
Fraction of fractional-octave band.
TYPE:
|
density
|
Calculate power density instead of power.
TYPE:
|
ref
|
Reference value.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
OctaveBand
|
Instance of |
|
np.ndarray: Level array. |
Source code in acoustic_toolbox/signal.py
isolate
Isolate signals using Singular Value Decomposition.
| PARAMETER | DESCRIPTION |
|---|---|
signals
|
Array of shape N x M where N is the amount of samples and M the amount of signals. Thus, each column is a signal
|
| RETURNS | DESCRIPTION |
|---|---|
|
Array of isolated signals. |
Source code in acoustic_toolbox/signal.py
zero_crossings
Determine the positions of zero crossings in data.
| PARAMETER | DESCRIPTION |
|---|---|
data
|
Vector.
|
| RETURNS | DESCRIPTION |
|---|---|
|
Vector with indices of samples before the zero crossing. |
Source code in acoustic_toolbox/signal.py
amplitude_envelope
amplitude_envelope(signal: ndarray, fs, axis=-1)
Instantaneous amplitude of tone.
The instantaneous amplitude is the magnitude of the analytic signal.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal.
TYPE:
|
fs
|
Sample frequency.
|
axis
|
Axis. Defaults to -1.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Amplitude envelope of |
See Also
Source code in acoustic_toolbox/signal.py
instantaneous_phase
instantaneous_phase(signal: ndarray, fs, axis=-1)
Instantaneous phase of tone.
The instantaneous phase is the angle of the analytic signal. This function returns a wrapped angle.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal.
TYPE:
|
fs
|
Sample frequency.
|
axis
|
Axis.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Instantaneous phase of |
See Also
Source code in acoustic_toolbox/signal.py
instantaneous_frequency
instantaneous_frequency(signal: ndarray, fs, axis=-1)
Determine instantaneous frequency of tone.
The instantaneous frequency can be obtained by differentiating the unwrapped instantaneous phase.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal.
TYPE:
|
fs
|
Sample frequency.
|
axis
|
Axis.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
Instantaneous frequency of |
See Also
Source code in acoustic_toolbox/signal.py
wvd
wvd(signal: ndarray, fs, analytic=True)
Wigner-Ville Distribution.
Includes positive and negative frequencies.
| PARAMETER | DESCRIPTION |
|---|---|
signal
|
Signal.
TYPE:
|
fs
|
Sample frequency.
|
analytic
|
If True, uses the analytic signal. Defaults to True.
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
Frequencies
|
Instance of |
|
W.T: Wigner-Ville distribution |
Source code in acoustic_toolbox/signal.py
decimate
decimate(
x: ndarray,
q: int,
n: int | None = None,
ftype: str = "iir",
axis: int = -1,
zero_phase: bool = False,
) -> ndarray
Downsample the signal by using a filter.
By default, an order 8 Chebyshev type I filter is used. A 30 point FIR
filter with hamming window is used if ftype is 'fir'.
Notes
- The
zero_phasekeyword was added in v0.17.0. - The possibility to use instances of
ltiasftypewas added in v0.17.0
| PARAMETER | DESCRIPTION |
|---|---|
x
|
The signal to be downsampled.
TYPE:
|
q
|
The downsampling factor.
TYPE:
|
n
|
The order of the filter.
TYPE:
|
ftype
|
The type of the lowpass filter.
TYPE:
|
axis
|
The axis along which to decimate.
TYPE:
|
zero_phase
|
Prevent phase shift by filtering with
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
ndarray
|
The down-sampled signal. |
See Also
resample: For resampling the signal.
Source code in acoustic_toolbox/signal.py
impulse_response_real_even
The impulse response of a real and even frequency response is also real and even.
A symmetric impulse response is needed. The center of symmetry determines the delay of the filter and thereby whether the filter is causal (delay>0, linear-phase) or non-causal (delay=0, linear-phase, zero-phase).
Creating linear phase can be done by multiplying the magnitude with a complex exponential corresponding to the desired shift. Another method is to rotate the impulse response.
https://ccrma.stanford.edu/~jos/filters/Zero_Phase_Filters_Even_Impulse.html
| PARAMETER | DESCRIPTION |
|---|---|
tf
|
Real and even frequency response. Only positive frequencies.
|
ntaps
|
Amount of taps.
|
| RETURNS | DESCRIPTION |
|---|---|
|
A real and even impulse response with length |
Source code in acoustic_toolbox/signal.py
linear_phase
Compute linear phase delay for a single-sided spectrum.
A linear phase delay can be added to an impulse response using the function np.fft.ifftshift.
Sometimes, however, you would like to add the linear phase delay to the frequency response instead.
This function computes the linear phase delay which can be multiplied with a single-sided frequency response.
| PARAMETER | DESCRIPTION |
|---|---|
ntaps
|
Amount of filter taps.
|
steepness
|
Steepness of phase delay. Default value is 1, corresponding to delay in samples of
DEFAULT:
|
| RETURNS | DESCRIPTION |
|---|---|
|
np.ndarray: Linear phase delay. |
Source code in acoustic_toolbox/signal.py
:::