Transforms (dsptoolbox.transforms)¶
Transforms¶
This module contains signal transforms.
cepstrum()
from_cepstrum()
log_mel_spectrogram() (returns a logarithmic magnitude spectrogram with mel frequency axis)
mel_filterbank() (returns matrix with triangular mel filters used to convert spectrograms’ frequency axis from Hz into mel)
plot_waterfall() (creates and returns a waterfall plot)
mfcc() (mel-frequency cepstral coefficients)
istft() (inverse STFT)
MorletWavelet (class for a complex morlet wavelet)
cwt() (continuous wavelet transform)
chroma_stft() (STFT adapted to the chroma scale)
hilbert() (Hilbert Transform)
vqt() (Variable-Q Transform)
stereo_mid_side() (Mid-Side representation of stereo signal)
laguerre() (Frequency-warping by means of the Laguerre transform)
warp() (Convert signal to/from warped domain)
warp_filter() (Warp a filter transforming its poles and zeros)
lpc() (linear-predictive coding)
dft() (discrete fourier transform for arbitrary frequency resolution)
spectrum_via_filterbank() (magnitude spectrum via filterbank)
- class dsptoolbox.transforms.MorletWavelet(b: float | None = None, h: float | None = None, scale: float = 1.0, precision_bounds: float = 1e-05, step: float = 0.005, interpolation: bool = True)¶
Bases:
WaveletComplex morlet wavelet.
Methods
Return complex morlet wavelet.
Return center frequency for the complex morlet wavelet.
get_scale_lengths(frequencies, fs)Returns the lengths of the queried frequencies.
get_wavelet(f, fs)Return wavelet scaled for a specific frequency and sampling rate.
- get_base_wavelet() tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]]¶
Return complex morlet wavelet.
- get_wavelet(f: float | ndarray[tuple[Any, ...], dtype[float64]], fs: int) ndarray[tuple[Any, ...], dtype[float64]] | list[ndarray[tuple[Any, ...], dtype[float64]]]¶
Return wavelet scaled for a specific frequency and sampling rate. The wavelet values can also be linearly interpolated for a higher accuracy at the expense of computation time.
- Parameters:
- ffloat or NDArray[np.float64]
Queried frequency or array of frequencies.
- fsint
Sampling rate in Hz.
- Returns:
- waveNDArray[np.float64] or list of NDArray[np.float64]
Wavelet function. It is either a 1d-array for a single frequency or a list of arrays for multiple frequencies.
- dsptoolbox.transforms.cepstrum(signal: Signal, complex: bool = True) ndarray[tuple[Any, ...], dtype[float64]] | ndarray[tuple[Any, ...], dtype[complex128]]¶
Returns the cepstrum of a given signal in the Quefrency domain.
- Parameters:
- signalSignal
Signal to compute the cepstrum from.
- complexbool, optional
When True, the complex cepstrum is returned, otherwise, the real cepstrum is computed. Default: True.
- Returns:
- cepsNDArray[np.float64] or NDArray[np.complex128]
Cepstrum.
References
- dsptoolbox.transforms.chroma_stft(signal: Signal, tuning_a_hz: float = 440, compression: float = 0.5, plot_channel: int = -1) tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]] | tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], Figure, Axes]¶
This computes the Chroma Features and Pitch STFT. See [1] for details.
- Parameters:
- signalSignal
Signal for which to compute the chroma features. The saved parameters for the spectrogram are used to compute the STFT.
- tuning_a_hzfloat, optional
Tuning in Hz for the A4. Default: 440.
- compressionfloat, optional
Compression factor as explained in [1]. Default: 0.5.
- plot_channelint, optional
When different than -1, a chroma plot for the corresponding channel is generated and returned. Default: -1.
- Returns:
- tNDArray[np.float64]
Time vector corresponding to each time frame.
- chroma_stftNDArray[np.float64]
Chroma Features with shape (note, time frame, channel). First index is C, second C#, etc. (Until B).
- pitch_stftNDArray[np.float64]
Pitch log-STFT with shape (pitch, time frame, channel). First index is note 0 (MIDI), i.e., C0.
- When plot_channel != -1:
Figure and Axes.
References
[1]: Short-Time Fourier Transform and Chroma Features. Müller.
- dsptoolbox.transforms.cwt(signal: Signal, frequencies: ndarray[tuple[Any, ...], dtype[float64]], wavelet: Wavelet | MorletWavelet, channel: ndarray[tuple[Any, ...], dtype[float64]] | None = None, synchrosqueezed: bool = False, apply_synchrosqueezed_normalization: bool = False) ndarray[tuple[Any, ...], dtype[complex128]]¶
Returns a scalogram by means of the continuous wavelet transform.
- Parameters:
- signalSignal
Signal for which to compute the cwt.
- frequenciesNDArray[np.float64]
Frequencies to query with the wavelet.
- waveletWavelet or MorletWavelet
Type of wavelet to use. It must be a class inherited from the Wavelet class.
- channelNDArray[np.float64], optional
Channel for which to compute the cwt. If None, all channels are computed. Default: None.
- synchrosqueezedbool, optional
When True, the scalogram is synchrosqueezed using the phase transform. Default: False.
- apply_synchrosqueezed_normalizationbool, optional
When True, each scale is scaled by taking into account the normalization as shown in Eq. (2.4) of [1]. False does not apply any normalization. This is only done for synchrosqueezed scalograms. Default: False.
- Returns:
- scalogramNDArray[np.complex128]
Complex scalogram scalogram with shape (frequency, time sample, channel).
Notes
Zero-padding in the beginning is done for reducing boundary effects.
References
[1]: Ingrid Daubechies, Jianfeng Lu, Hau-Tieng Wu. Synchrosqueezed wavelet transforms: An empirical mode decomposition-like tool. 2011.
General information about synchrosqueezing: https://dsp.stackexchange.com/questions/71398/synchrosqueezing-wavelet -transform-explanation
- dsptoolbox.transforms.dft(signal: Signal, frequency_vector_hz: ndarray[tuple[Any, ...], dtype[float64]])¶
DFT for any set of frequencies. This is a direct computation of the DFT, so it is significantly slower than an FFT, but it can be used to obtain any desired frequency resolution.
- Parameters:
- signalSignal
Signal for which to compute the spectrum.
- frequency_vector_hzNDArray[np.float64]
Frequency vector to query.
- Returns:
- spectrumNDArray[np.complex128]
Spectrum with the defined frequency resolution. It has shape (frequency bin, channel).
Notes
This function uses a parallelized computation of the DFT bins with numba, its performance might differ significantly from one computer to the other.
Frequency resolution different than linear can be obtained from the FFT via warping, FFTLog (fast hankel transform) or the Chirp-Z transform. None of these transforms allow for a completely arbitrary spacing of the frequency bins.
- dsptoolbox.transforms.from_complex_cepstrum(cepstrum: ndarray[tuple[Any, ...], dtype[complex128]], sampling_rate_hz: int) Signal¶
Compute the real signal from the complex cepstrum.
- Parameters:
- cepstrumNDArray[np.complex128]
Complex cepstrum to convert into a signal. The expected shape is (quefrency, channel).
- sampling_rate_hzint
Sampling rate of cepstrum and output signal.
- Returns:
- Signal
- dsptoolbox.transforms.hilbert(signal: Signal | ImpulseResponse | MultiBandSignal) Signal | ImpulseResponse | MultiBandSignal¶
Compute the analytic signal using the hilbert transform of the real signal.
- Parameters:
- signalSignal, MultiBandSignal
Signal to convert.
- Returns:
- analyticSignal, MultiBandSignal
Analytical signal.
Notes
Since it is not causal, the whole time series must be passed through an FFT. This could take long or be too memory intensive depending on the size of the original signal and the computer.
The new Signal has the real part saved in self.time_data and the imaginary in self.time_data_imaginary. Complex time series can therefore be constructed with:
complex_ts = Signal.time_data + Signal.time_data_imaginary*1j
- dsptoolbox.transforms.istft(stft: ndarray[tuple[Any, ...], dtype[complex128]], original_signal: Signal | None = None, parameters: dict | None = None, sampling_rate_hz: int | None = None, window_length_samples: int | None = None, window_type: str | None = None, overlap_percent: int | None = None, fft_length_samples: int | None = None, padding: bool | None = None, scaling: bool | None = None) Signal¶
This function transforms a complex STFT back into its respective time signal using the method presented in [1]. For this to be possible, it is necessary to know the parameters that were used while converting the signal into its STFT representation. A dictionary containing the parameters corresponding can be passed, as well as the original Signal in which these parameters are saved. Alternatively, it is possible to pass them explicitely.
- Parameters:
- stftNDArray[np.complex128]
Complex STFT with shape (frequency, time frame, channel). It is assumed that only positive frequencies (including 0) are present.
- original_signalSignal, optional
Initial signal from which the STFT matrix was generated. Default: None.
- parametersdict, optional
Dictionary containing the parameters used to compute the STFT matrix. Default: None.
- sampling_rate_hzint, optional
Sampling rate of the original signal.
- window_length_samplesint, optional
Window length in samples. Default: None.
- window_typestr, optional
Window type. It must be supported by scipy.signal.windows.get_window. Default: None.
- overlap_percentint, optional
Window overlap in percent (between 0 and 100). Default: None.
- fft_length_samplesint, optional
Length of the FFT applied to the time frames. Default: None.
- paddingbool, optional
True means that the original signal was zero-padded in the beginning and end in order to avoid losing energy due to window effects. Default: None.
- scalingbool, optional
When True, it is assumed that the STFT matrix was scaled as an amplitude spectrum. Default: None.
- Returns:
- reconstructed_signalSignal
Reconstructed signal from the complex STFT.
Notes
In order to get the STFT (framed signal representation), it is probable that the original signal was zero-padded in the end. If the original signal is passed, the output will have the same length. If not, it might be longer by an amount of samples smaller than a window size.
It is important to notice that if the original signal was detrended, this can not be recovered and might lead to small distortions in the reconstructed one.
Instabilities when the original STFT was not zero-padded are avoided by padding during reconstruction at the expense of small amplitude distortion at the edges.
References
[1]: D. Griffin and Jae Lim, “Signal estimation from modified short-time Fourier transform,” in IEEE Transactions on Acoustics, Speech, and Signal Processing, vol. 32, no. 2, pp. 236-243, April 1984, doi: 10.1109/TASSP.1984.1164317.
- dsptoolbox.transforms.laguerre(signal: Signal, warping_factor: float) Signal¶
This function implements the discrete Laguerre Transform in the time domain according to [1]. It is mainly used for frequency warping. See notes for details.
This is a resource-intensive operation that should be applied to signals that are not very long.
- Parameters:
- signalSignal
Signal to be transformed.
- warping_factorfloat
Warping factor. It must be in the range ]-1; 1[.
- Returns:
- Signal
Transformed signal.
Notes
This transform can be reversed by applying it once with warping_factor and then with -warping_factor.
It is an alternative, more general formulation to Warping and a special case of using Kautz filters for a fixed pole. warping_factor here leads to the same frequency mapping as warping.
This can be used for frequency-dependent windowing of an impulse response. Since this is not shift-invariant, the start of the IR should be placed at t=0.
In general, warping_factor < 0. shifts the frequency axis towards nyquist, i.e., increases the resolution of the lower frequencies while lowering that of higher frequencies. See [2] for the resolution/frequency-mapping of warping.
References
[1]: Zölzer, Battista. Digital Audio Effects DAFX. Chapter 11, second edition.
[2]: Bank, B. (2022). Warped, Kautz, and Fixed-Pole Parallel Filters: A Review. Journal of the Audio Engineering Society.
- dsptoolbox.transforms.log_mel_spectrogram(s: Signal, channel: int = 0, range_hz=None, n_bands: int = 40, generate_plot: bool = True, stft_parameters: dict | None = None) tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]] | tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], Figure, Axes]¶
Returns the log mel spectrogram of the specific signal and channel.
- Parameters:
- sSignal
Signal to generate the spectrogram.
- channelint, optional
Channel of the signal to be used for the plot generation. Only one channel can be passed. Default: 0.
- range_hzarray-like with length 2, optional
Range of frequencies to use. Pass None to analyze the whole spectrum. Default: None.
- n_bandsint, optional
Number of mel bands to generate. Default: 40.
- generate_plotbool, optional
Plots the obtained results. Use
dsptoolbox.plots.show()to show the plot. Default: True.- stft_parametersdict, optional
Pass arguments to define computation of STFT. If None is passed, the parameters already set in the signal will be used. Refer to Signal.set_spectrogram_parameters() for details. Default: None.
- Returns:
- time_sNDArray[np.float64]
Time vector.
- f_melNDArray[np.float64]
Frequency vector in Mel.
- log_mel_spNDArray[np.float64]
Log mel spectrogram with shape (frequency, time frame, channel).
- When generate_plot=True:
- time_sNDArray[np.float64]
Time vector.
- f_melNDArray[np.float64]
Frequency vector in Mel.
- log_mel_spNDArray[np.float64]
Log mel spectrogram with shape (frequency, time frame, channel).
- figmatplotlib.figure.Figure
Figure.
- axmatplotlib.axes.Axes
Axes.
- dsptoolbox.transforms.lpc(signal: Signal, order: int, window_length_samples: int, synthesize_encoded_signal: bool = False, use_burg_method: bool = False, hop_size_samples: int | None = None, window_type: Window = Window.Hann)¶
Encode an input signal into its linear-predictive coding coefficients. This transforms the signal into source-filter representation and works best with inputs that can be modeled through the all-pole model.
- Parameters:
- signalSignal
Input to encode.
- orderint
Order of the coefficients to use.
- window_length_samplesint
Window length in samples.
- synthesize_encoded_signalbool, optional
When True, the encoded signal is synthesized and returned. To this end, white noise is always used as source. Pass False to avoid this computation. Default: False.
- use_burg_methodbool, optional
Method to use for obtaining the LP coefficients. When True, Burg’s method is used. Otherwise, Yule-Walker will be used. Default: False.
- hop_size_samplesint, None, optional
Hop size to use from window to window. If None is passed, a hop size corresponding to 50% of the window length will be used. Default: None.
- window_typeWindow, optional
Window type to use. It is recommended that a window type that satifies the COLA-condition with length and hop size is chosen. Default: Hann.
- Returns:
- a_coefficientsNDArray[np.float64]
LP coefficients with shape (time window, coefficient, channel).
- variancesNDArray[np.float64]
Variances (quadratic) of the source with shape (time window, channel).
- reconstructed_signalSignal
Signal reconstructed from the estimated LP coefficients using white noise as the source. This is only returned if synthesize_encoded_signal=True.
References
- dsptoolbox.transforms.mel_filterbank(f_hz: ndarray[tuple[Any, ...], dtype[float64]], range_hz=None, n_bands: int = 40, normalize: bool = True) tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]]¶
Creates equidistant mel triangle filters in a given range. The returned matrix can be used to convert Hz into Mel in a spectrogram.
NOTE: This is not a filter bank in the usual sense, thus it does not create a FilterBank object to be applied to a signal. Its intended use is in the frequency domain.
- Parameters:
- f_hzNDArray[np.float64]
Frequency vector.
- range_hzarray-like with length 2, optional
Range (in Hz) in which to create the filters. If None, the whole available spectrum is used. Default: None.
- n_bandsint, optional
Number of bands to create. Default: 40.
- normalizebool, optional
When True, the bands are area normalized for preserving approximately same energy in each band. Default: True.
- Returns:
- mel_filtersNDArray[np.float64]
Mel filters matrix with shape (bands, frequency). These are to be applied to a power response (squared spectrum).
- mel_center_freqsNDArray[np.float64]
Vector containing mel center frequencies.
- dsptoolbox.transforms.mfcc(signal: Signal, channel: int = 0, mel_filters: ndarray[tuple[Any, ...], dtype[float64]] | None = None, generate_plot: bool = True, stft_parameters: dict | None = None) tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]]] | tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[float64]], Figure, Axes]¶
Mel-frequency cepstral coefficients for a windowed signal are computed and returned using the discrete cosine transform of type 2 (see scipy.fft.dct for more details).
- Parameters:
- signalSignal
The signal for which to compute the mel-frequency cepstral coefficients.
- channelint, optional
Channel of the signal for which to plot the MFCC when generate_plot=True. Default: 0.
- mel_filtersNDArray[np.float64], optional
Hz-to-Mel transformation matrix with shape (mel band, frequency Hz). It can be created using mel_filterbank. If None is passed, the filters are automatically computed regarding the whole available spectrum and dividing it in 40 bands (with normalized amplitudes for energy preserving filters, see mel_filterbank for details). Default: None.
- generate_plotbool, optional
When True, a plot of the MFCC is generated and returned. Default: True.
- stft_parametersdict, optional
Pass arguments to define computation of STFT. If None is passed, the parameters already set in the signal will be used. Refer to Signal.set_spectrogram_parameters() for details. Default: None.
- Returns:
- time_sNDArray[np.float64]
Time vector.
- f_melNDArray[np.float64]
Frequency vector in mel. If mel_filters is passed, this is only a list with entries [0, n_mel_filters].
- mfccNDArray[np.float64]
Mel-frequency cepstral coefficients with shape (cepstral coefficients, time frame, channel).
- When generate_plot=True:
- time_sNDArray[np.float64]
Time vector.
- f_melNDArray[np.float64]
Frequency vector in mel. If mel_filters is passed, this is only a list with entries [0, n_mel_filters].
- mfccNDArray[np.float64]
Mel-frequency cepstral coefficients with shape (cepstral coefficients, time frame, channel).
- figmatplotlib.figure.Figure
Figure.
- axmatplotlib.axes.Axes
Axes.
- dsptoolbox.transforms.plot_waterfall(sig: Signal, channel: int = 0, dynamic_range_db: float = 40, stft_parameters: dict | None = None) tuple[Figure, Axes]¶
Generates and returns a waterfall plot from a signal. The settings for the spectrogram saved in the signal are the ones used for the plot generation.
- Parameters:
- sigSignal
Signal to plot waterfall diagramm for.
- channelint, optional
Channel to take for the waterfall plot.
- dynamic_range_dbfloat, optional
Sets the maximum dynamic range in dB to show in the plot. Pass None to avoid setting any dynamic range. Default: 40.
- stft_parametersdict, optional
Dictionary containing settings for the stft. If None is passed, the parameters already set in Signal object are used. Refer to Signal.set_spectrogram_parameters() for details. Default: None.
- Returns:
- figmatplotlib.figure.Figure
Figure.
- axmatplotlib.axes.Axes
Axes.
- dsptoolbox.transforms.spectrum_via_filterbank(signal: Signal, frequency_vector_hz: ndarray[tuple[Any, ...], dtype[float64]], bandwidth_octaves: float | None = None, bandwidth_hz: float | None = None, order: int = 8, zero_phase: bool = False) Spectrum¶
Obtain a magnitude spectrum of the signal via a butterworth filter bank and posterior computation of the RMS value for each resulting band. This is useful when the needed frequency resolution from the spectrum is difficult to obtain via an FFT or periodogram.
- Parameters:
- signalSignal
Signal from which to extract the spectrum.
- frequency_vector_hzNDArray[np.float64]
Frequencies to use for the spectrum.
- bandwidth_octavesfloat, optional
The width of each band in octaves. .
- bandwidth_hzfloat
The width of each band in Hz.
- orderint, optional
Order for the bandpass filters. Default: 8.
- zero_phasebool, optional
When True, zero-phase filtering is applied. Default: False.
- Returns:
- Spectrum
Magnitude spectrum
- dsptoolbox.transforms.stereo_mid_side(signal: Signal, forward: bool) Signal¶
This function converts a left-right stereo signal to its mid-side representation or the other way around. It is only available for two-channels signals.
- Parameters:
- signalSignal
Signal with two channels, i.e., left and right (in that order) or mid and side.
- forwardbool
When True, left-right is converted to mid-side. When False, mid-side is turned into left-right.
- Returns:
- new_sigSignal
Converted signal. Left (or mid) are always the first channel.
- dsptoolbox.transforms.vqt(signal: Signal, channel: ndarray[tuple[Any, ...], dtype[int64]] | None = None, q: float = 1, gamma: float = 50, octaves: list = [1, 5], bins_per_octave: int = 24, a4_tuning: int = 440, window: str | tuple = 'hann') tuple[ndarray[tuple[Any, ...], dtype[float64]], ndarray[tuple[Any, ...], dtype[complex128]]]¶
Variable-Q Transform. This is a special case of the continuous wavelet transform with complex morlet wavelets for the time-frequency analysis. Constant-Q Transform can be obtained by setting gamma = 0.
- Parameters:
- signalSignal
Signal for which to compute the cqt coefficients.
- channelNDArray[np.float64] or int, optional
Channel(s) for which to compute the cqt coefficients. If None, all channels are computed. Default: None.
- qfloat, optional
Q-factor. 1 would be the optimal value but setting it to something lower might increase temporal resolution at the expense of frequency resolution. Default: 1.
- gammafloat, optional
This is the factor for the bandwidth adaptation (in Hz). This extends the bandwidth of each kernel. Set to 0 for obtaining the Constant-Q Transform. Default: 50.
- octaveslist with length 2, optional
Range of musical octaves for which to compute the cqt coefficients. [1, 4] computes all corresponding frequencies from C1 up until B4. Exact frequencies are adapted from the a4-tuning parameter. Default: [1, 5].
- bins_per_octaveint, optional
Number of frequency bins to divide an octave. Default: 24.
- a4_tuningint, optional
Frequency for A4 in Hz. Default: 440.
- windowstr or tuple, optional
Type of window to use for the kernels. This is directly passed to scipy.signal.get_window(), so that a tuple containing a window type and an additional parameter can be used. Default: ‘hann’.
- Returns:
- fNDArray[np.float64]
Frequency vector.
- vqtNDArray[np.complex128]
VQT coefficients with shape (frequency, time samples, channel).
References
Schörkhuber and Klapuri: CONSTANT-Q TRANSFORM TOOLBOX FOR MUSIC PROCESSING.
Schörkhuber et. al.: A Matlab Toolbox for Efficient Perfect Reconstruction Time-Frequency Transforms with Log-Frequency Resolution.
- dsptoolbox.transforms.warp(ir: Signal, warping_factor: float | str, shift_ir: bool, total_length: int | None = None) Signal | tuple[Signal, float]¶
Compute a warped signal as explained by [1]. This operation corresponds to computing a warped FIR-Filter (WFIR).
To pre-warp a signal, pass a negative warping_factor. To de-warp it, use the same positive warping_factor. See notes for details.
- Parameters:
- irSignal
Impulse response to (de)warp.
- warping_factorfloat, str, {“bark”, “erb”, “bark-”, “erb-“}
Warping factor. It has to be in the range ]-1; 1[. If a string is provided, warping the frequency axis to (or from) an approximation of the psychoacoustically motivated Bark or ERB scales is performed according to [4]. Pass “-” in the end for the dewarping (backwards) stage.
- shift_irbool
Since the warping of an IR is not shift-invariant (see [2]), it is recommended to place the start of the IR at the first index. When True, the first sample to surpass -20 dBFS (relative to peak) is shifted to the beginning and the previous samples are sent to the end of the signal. False avoids any manipulation.
- total_lengthint, optional
Total length to use for the warped signal. If None, the original length is maintained. Default: None.
- Returns:
- warped_irSignal
The same IR with warped or dewarped time vector.
- float
Warping factor. Only returned in case “bark” or “erb” was passed.
Notes
Depending on the signal length, this might be a slow computation.
Frequency-dependent windowing can be easily done in the warped domain. This is not the approach used in window_frequency_dependent(), but it can be achieved with this function. See [2] for more details.
In general, warping_factor < 0. shifts the frequency axis towards nyquist, i.e., increases the resolution of the lower frequencies while lowering that of higher frequencies. See [1] and [3] for the frequency mapping of warping.
warping_factor will have a frequency-warping where a single frequency point has the same group delay as the unwarped version. The formula for this is [1]:
\[\frac{f_s}{2\pi}\arccos(\lambda)\]where lambda is the warping_factor and f_s the sampling rate.
Warping poles and zeros in the rational transfer function can be done by replacing the \(z^{-1}\) with \((z^{-1} - \lambda)/(1 - \lambda z^{-1})\). This leads, for instance, to transforming a pole \(p_0\) to a new pole \(p\) with:
\[p = \frac{\lambda + p_0}{1 + p_0 \lambda}\]while appending the factor
\[\left(1 + \lambda z^{-1}\right)^{M_p - N_z}\]to the transfer function, where Mp is the total number of poles and Nz the total number of zeros.
The frequency scale approximation to the Bark scale presented in [4] is more accurate than for the ERB scale.
References
[1]: Härmä, Aki & Karjalainen, Matti & Avioja, Lauri & Välimäki, Vesa & Laine, Unto & Huopaniemi, Jyri. (2000). Frequency-Warped Signal Processing for Audio Applications. Journal of the Audio Engineering Society. 48. 1011-1031.
[2]: M. Karjalainen and T. Paatero, “Frequency-dependent signal windowing,” Proceedings of the 2001 IEEE Workshop on the Applications of Signal Processing to Audio and Acoustics (Cat. No.01TH8575), New Platz, NY, USA, 2001, pp. 35-38, doi: 10.1109/ASPAA.2001.969536.
[3]: Bank, B. (2022). Warped, Kautz, and Fixed-Pole Parallel Filters: A Review. Journal of the Audio Engineering Society.
[4]: III, J.O. & Abel, Jonathan. (1999). Bark and ERB Bilinear Transforms. Speech and Audio Processing, IEEE Transactions on. 7. 697 - 708. 10.1109/89.799695.
- dsptoolbox.transforms.warp_filter(filter: Filter, warping_factor: float) Filter¶
Apply warping to a filter by transforming its poles and zeros. See references for details on warping.
- Parameters:
- filterFilter
Filter to be warped.
- warping_factorfloat
Warping factor. See warp() for details.
- Returns:
- Filter
Warped filter.
Notes
The overall filter gain of the filter is not modified by this function.
Warping poles and zeros in the rational transfer function can be done by replacing the \(z^{-1}\) with \((z^{-1} - \lambda)/(1 - \lambda z^{-1})\). This leads, for instance, to transforming a pole \(p_0\) to a new pole \(p\) with:
\[p = \frac{\lambda + p_0}{1 + p_0 \lambda}\]while appending the factor
\[\left(1 + \lambda z^{-1}\right)^{M_p - N_z}\]to the transfer function, where Mp is the total number of poles and Nz the total number of zeros.
Warping filters with orders above 100 is not recommended due to numerical errors when finding their polynomial roots. This does not apply if the filter has the zeros and poles from which its coefficients were computed.
References
[1]: Härmä, Aki & Karjalainen, Matti & Avioja, Lauri & Välimäki, Vesa & Laine, Unto & Huopaniemi, Jyri. (2000). Frequency-Warped Signal Processing for Audio Applications. Journal of the Audio Engineering Society. 48. 1011-1031.
[2]: M. Karjalainen and T. Paatero, “Frequency-dependent signal windowing,” Proceedings of the 2001 IEEE Workshop on the Applications of Signal Processing to Audio and Acoustics (Cat. No.01TH8575), New Platz, NY, USA, 2001, pp. 35-38, doi: 10.1109/ASPAA.2001.969536.
[3]: Bank, B. (2022). Warped, Kautz, and Fixed-Pole Parallel Filters: A Review. Journal of the Audio Engineering Society.
[4]: III, J.O. & Abel, Jonathan. (1999). Bark and ERB Bilinear Transforms. Speech and Audio Processing, IEEE Transactions on. 7. 697 - 708. 10.1109/89.799695.