Same doc with math equations properly displayed can be found in github page
Python implementation of all-pole Gammatone filter. The filtering part of code is written in c.
Basic idea of implementation 1
Gammatone filter can be regarded as low-pass filter with frequency shitfted by cf(center freuqency of filter). Equalently, we can
- Shift the frequency of input signal by -cf(center frequency of filter);
- Filter shifted signal with corresponding lowpass filter
- Shift the frequency of filtered signal back by cf.
Detly has published a python module of gammatone filterbank. Using the sample settings, outputs of Detly module and current module are as follow:
fs=16kHz
cfs = [100 393 948 2000]
Detly | |
Current |
Difference
In Delty's code, given the low and high frequencies(
n=4 | n=8 | n=16 | n=32 |
In this module, there are two ways to ways to specified the frequency range:
-
freq_low, freq_high: the frequency range of ERB
-
cf_low, cf_hight: the frequency range of center frequencies
eg, frequency range [70, 7000], n=4
Taking filter with
amp & phase | amp & delay |
As shown in figure,
- $ \phi(f_c)\approx 0 $;
- Amplitude of
$$\phi(f)$$ increase as$$f$$ move away from$$f_c$$ ;
Gain and delay at cf as function of cf
## Gain normalizationGammatone filter is normalized by scaling filter gain at fc to 1
- IRs before gain normalization
Phase compensation is actually to align the peaks of all filter impulse response2.
The impulse response of Gammatone filter is given as
- Envelope parts:
$$\quad g_{amp}(t) = a\frac{t^{n-1}}{e^{2\pi b t}}$$ - Fine structure part:
$$\quad g_{fine}(t) = \cos(2\pi f_ct+\phi)$$
The peak position
$$
\begin{equation}
\begin{aligned}
\frac{\partial g_{amp}(t)}{\partial t} &= \frac{(n-1)t^{n-2}}{e^{2\pi bt}}-\frac{t^{n-1}2\pi b}{e^{2\pi bt}}\
&=\frac{t^{n-2}}{e^{2\pi bt}}(n-1-2\pi bt) \triangleq 0\
\Rightarrow& \quad t_{peak}=\frac{(n-1)}{2\pi b}
\end{aligned}
\end{equation}
$$
Delay
Example of
$$ \begin{equation} \begin{aligned} & \cos(2\pi f_ct+\phi)|{t=t{max}} \triangleq 1\ \Rightarrow& \quad \phi = -\frac{(n-1)f_c}{b}+i2\pi, \quad i=0,\pm 1,\cdots \end{aligned} \end{equation} $$
### Illustration of purpose of alignmentFor a stimulus of impulse, what if we add up all filter outpus ? Ideally, a impulse is expected
Not aligned | Envelope aligned | Envelop & fine structure aligned |
python .\efficiency.py
#time consumed(s) for filtering signal with length of 16e3 samples
# c :0.11
# python :11.81
Corresponding to above-mentioned tests
validate.py
efficiency.py
filter_spectrum.py
gain_normalization.py
phase_compensation.py
stimulus_restore.py