Open jimchen90 opened 4 years ago
sox might be using doubles - so this won't match the performance. However, float32 is used more widely and can get us better performance.
Should we consider returning normalized coefficients by default? If yes, how do we choose the normalization coefficient? What are the most common downstream tasks these coefficients are used for and do those dependent on the relative or absolute size of the coefficients?
Maybe we can just normalize them to be within -1 and 1 just like our waveforms and then add a flag to allow the user to turn this off. Do other libraries do this?
I'd like to quote @yoyololicon's comment here as reference for potential future work.
"""
Currently, the custom backward function is actually just filter the gradients in reversed direction with the same parameters. If there is numerical problems in forward pass, it's very likely to happen in backward.
The instability of lfilter in torchaudio can be a result of:
scipy.signal.sosfilt
instead of scipy.signal.lfilter
in their documentation.In future I would recommend implementing a custom second-order filter using Transposed Form II, and factorize the filter coefficients using root finding algorithm when higher order filter is needed.
"""
🐛 Bug
When using
lfilter
function intorchaudio/functional.py
, I input two groups of biquad coefficient parameters (one group is normalized by a0, and the other is unnormalized). The maximum error between two output waveforms is 6e-4.To Reproduce
Steps to reproduce the behavior:
I have a group of coefficients calculated from the bass biquad filter:
After normalization by a0:
The details of coefficient calculation are shown in Additional Test (list below). Then I compare the output waveforms and the number of elements that has error (absolute difference of output values) larger than 1e-4 is 12603. The maximum error between two waveforms is 6e-4.
output result: 12603 6e-4
Expected behavior
There is negligible error between two output waveforms.
Environment
Additional context
The maximum error deceases when gain decreases. The method to calculate the coefficients of bass (biquad) filter: