FilterbanksBestPractices
Tips for best practices with filterbanks
Install / Use
/learn @lixilinx/FilterbanksBestPracticesQuality Score
Category
DesignSupported Platforms
Tags
README
Best practices with filterbanks
Filterbank is versatile but also tricky. Here, I’d like to share what I have learned from my many years of practice (mainly for audio processing). The math and design methods are from my paper. It is a straightforward time domain design framework that can cover most cases (DFT and DCT filterbanks, DWT and complex DWT, constraints like latency, symmetry and phase linearity, control on sidelobe tails, ...).
Topics:
MIRROR symmetry if latency is unconcerned
SAME symmetry if low latency is crucial
Symmetries and least squares reconstruction
Designs with lower aliasing do not necessarily performs better for tasks like AEC
Squeezing synthesis filter does not help low latency filterbank design
Replacing STFT with filterbank
Frequency shift with analytic signal
Remove the systemic phase biases
DCT filterbank for tasks like AEC?
Optimization of discrete design freedoms
Exact phase linearity, a luxury or a must-have?
Fine balance between resolution and leakage
Note: there are some issues rendering bold math symbols, say a bold 𝐚 maybe rendered as a or aa in the equation.
What is a filterbank
This script generates the following plot illustrating what is a DCT-IV modulated filterbank.
<img src="https://github.com/lixilinx/Best-practices-for-filterbanks/blob/main/what_is_a_filterbank.svg" width="500" />From top to bottom, we have 1) the prototype filter; 2) the four cosine modulation sequences; 3) the four modulated filters, i.e., element-wise products between the prototype filter and modulation sequences; 4) frequency responses of the four modulated filters. We see that these four filters cover the whole frequency range nicely.
These examples illustrate a few special designs. The wavelet and complex wavelet examples also are good for explaining the concept of filterbank due to their simplicity.
Here, I mainly focus on the DFT modulated filterbanks. Still, all these modulated filterbanks share the same math, and only difference in modulation sequences. Notably,
- The periodicity of modulation sequences induces the polyphase structure.
- Trigonometric modulation series make FFT like fast algorithms possible.
MIRROR symmetry if latency is unconcerned
MIRROR symmetry imposes constraint $\pmb h = {\rm flip}(\pmb g)$, where $\pmb h$ and $\pmb g$ are the prototype analysis and synthesis filters, respectively. This script generates the following design for applications insensitive to latency. With latency+1=filter length and symmetry setting either [1;0;0] or [0;0;0], the code finds this optimal design where analysis and synthesis filters mirror each other. Forcing symmetry=[-1;0;0] (analysis filter equals synthesis filter) leads to noticeable less sidelobe suppression as the resultant filter itself is symmetric, thus halves the continuous design freedoms.
MIRROR symmetry leads to the least aliasing and also the least squares solution for signal reconstruction, but brings two possible drawbacks:
- Generally it is not good for low latency design as here, latency+1 must equal filter length.
- Typically neither the analysis nor the synthesis filter has good linear phase property (surely, their combined phase is linear as the analysis-synthesis filter is symmetric).
SAME symmetry if low latency is crucial
SAME symmetry imposes constraint $\pmb h=\pmb g$. This script generates the following low latency (latency+1 < filter length) design with symmetry=[-1;0;0], which suits realtime processings like acoustic echo cancellation (AEC), beamforming (BF), noise suppression (NS), etc. Clearly, MIRROR symmetry is incompatible with the low latency requirement.
I gradually increase filter length until overshoot, i.e., bumpy mainlobe, arises. Another strategy is to start from a large filter length, and then gradually increase $\lambda$ to damp the overshoot if there is.
Setting symmetry=[0;0;0] releases all the design freedoms, and typically finds solutions with much lower aliasing. Lowering aliasing benefits certain applications like low, high or band pass filtering (LPF/HPF/BPF), sample-rate conversion (SRC), etc. However, symmetric design has nicer numerical properties and better fits other tasks like AEC. Another merit of the SAME symmetry is that both the analysis and synthesis filters must have approximately linear phase in the pass band as otherwise, nearly perfect reconstruction (NPR) is not possible. In the extreme case of latency+1 = filter length, the SAME symmetry leads to exactly linear phase prototype filters.
<img src="https://github.com/lixilinx/Best-practices-for-filterbanks/blob/main/low_latency_design_for_aec.svg" width="400" />Symmetries and least squares reconstruction
Symmetry is important due to the following numerical property:
- With the MIRROR symmetry, filterbank synthesis gives the least squares solution for fitting a given set of analysis results, whether consistent or not.
Synthesis with the SAME symmetry generally only approximates the least squares solution for fitting a given set of analysis results due to the phase linearity in the pass band, not necessarily the stop band. If the phase also is linear in the stop band, then the DFT filterbank has both the MIRROR and SAME symmetries.
To show this property, let's consider a STFT with analysis and synthesis prototype filters $\pmb h=[h(0), h(1), \ldots]^T$ and $\pmb g=[g(0), g(1), \ldots]^T$, respectively. With $\pmb F$ being the normalized DFT matrix ($\pmb F^{H}\pmb F=\pmb I$), the STFT of a time signal $\pmb x=[x(0), x(1), \ldots]^T$ is given by
$$ \pmb X = \begin{bmatrix} \pmb F {\rm diag}({\rm flip}(\pmb h)) & & \ & \pmb F {\rm diag}({\rm flip}(\pmb h)) & \ & & \ddots \ \end{bmatrix} \pmb x = \pmb H \pmb x, \qquad ( {\rm what \, shown \, is \, not\, a \, block \,matrix, \, just \, the \, layout \, of \, rows }) $$
The inverse STFT (ISTFT) on STFT results $\pmb Y$ is
$$ \pmb y = \begin{bmatrix} {\rm diag}(\pmb g) \pmb F^{-1} & & \ & {\rm diag}(\pmb g) \pmb F^{-1} & \ & & \ddots \ \end{bmatrix} \pmb Y = \pmb G \pmb Y, \qquad ( {\rm what \, shown \, is \, not\, a \, block \,matrix, \, just \, the \, layout \, of \, columns }) $$
By design, $\pmb G\pmb H = \pmb I$ (ignoring the delay and reconstruction errors). Now, let's consider the linear system $\pmb H x = \pmb X$ with $\pmb x$ unknown. It is over-determined when $B < T $, and the least squares solution is given by $\hat{x}=(\pmb H^H \pmb H)^{-1} \pmb H^H \pmb X$. Is this $\hat{x}$ the same as $\pmb G \pmb X$? Not always. But, when $\pmb g = {\rm flip}(\pmb h)$, then indeed synthesis gives the least squares solution as shown by
$$ (\pmb H^H \pmb H)^{-1} H^H = (\pmb G\pmb H )^{-1} \pmb G = \pmb G $$
In general, we can show that with the MIRROR symmetry, $\pmb G$ is the Moore–Penrose inverse of $\pmb H$, and synthesis $\hat{x} = \pmb G \pmb X$ gives the least squares solution for $\pmb x$ fitting equations $\pmb H \pmb x = \pmb X$.
One application of this property is signal reconstruction from magnitude spectra $\pmb A \ge 0$. We are to solve the following optimization problem
$$ \min_{\pmb s, \, \pmb \phi} || \pmb H \pmb s - e^{\sqrt{-1} \pmb \phi} \pmb A ||^2
Related Skills
clearshot
Structured screenshot analysis for UI implementation and critique. Analyzes every UI screenshot with a 5×5 spatial grid, full element inventory, and design system extraction — facts and taste together, every time. Escalates to full implementation blueprint when building. Trigger on any digital interface image file (png, jpg, gif, webp — websites, apps, dashboards, mockups, wireframes) or commands like 'analyse this screenshot,' 'rebuild this,' 'match this design,' 'clone this.' Skip for non-UI images (photos, memes, charts) unless the user explicitly wants to build a UI from them. Does NOT trigger on HTML source code, CSS, SVGs, or any code pasted as text.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
openpencil
2.1kThe world's first open-source AI-native vector design tool and the first to feature concurrent Agent Teams. Design-as-Code. Turn prompts into UI directly on the live canvas. A modern alternative to Pencil.
ui-ux-pro-max-skill
60.9kAn AI SKILL that provide design intelligence for building professional UI/UX multiple platforms
