spafe.fbanks.bark_fbanks#

spafe.fbanks.bark_fbanks.Fm(fb: float, fc: float) float[source]#

Compute a Bark filter around a certain center frequency in bark [Hermansky].

Parameters
  • fb (float) – frequency in Bark.

  • fc (float) – center frequency in Bark.

Returns

associated Bark filter value/amplitude.

Return type

(float)

spafe.fbanks.bark_fbanks.bark_filter_banks(nfilts: int = 24, nfft: int = 512, fs: int = 16000, low_freq: float = 0, high_freq: Optional[float] = None, scale: Literal['ascendant', 'descendant', 'constant'] = 'constant', conversion_approach: Literal['Wang', 'Tjomov', 'Schroeder', 'Terhardt', 'Zwicker', 'Traunmueller'] = 'Wang')[source]#

Compute Bark filter banks. The filters are stored in the rows, the columns correspond to fft bins.

Parameters
  • nfilts (int) – the number of filters in the filter bank. (Default is 20).

  • nfft (int) – the FFT size. (Default is 512).

  • fs (int) – sample rate/ sampling frequency of the signal. (Default 16000 Hz).

  • low_freq (float) – lowest band edge of mel filters. (Default 0 Hz).

  • high_freq (float) – highest band edge of mel filters. (Default is fs/2).

  • scale (str) – monotonicity behavior of the filter banks. (Default is “constant”).

  • conversion_approach (str) – bark scale conversion approach. (Default is “Wang”).

Returns

  • (numpy.ndarray) : array of size nfilts * (nfft/2 + 1) containing filter bank. Each row holds 1 filter.

  • (numpy.ndarray) : array of center frequencies

Return type

(tuple)

Raises

ParameterError –

  • if low_freq < 0 OR high_freq > (fs / 2)

Tip

  • scale : can take the following options [“constant”, “ascendant”, “descendant”].

  • conversion_approach : can take the following options [“Tjomov”,”Schroeder”, “Terhardt”, “Zwicker”, “Traunmueller”, “Wang”]. Note that the use of different options than the ddefault can lead to unexpected behavior/issues.

References

Hermansky

Hermansky, H. “Perceptual linear predictive (PLP) analysis of speech.” The Journal of the Acoustical Society of America 87 4 (1990): 1738-52 doi: 10.1121/1.399423. PMID: 2341679.

Examples

import numpy as np
from spafe.utils.converters import bark2hz
from spafe.utils.vis import show_fbanks
from spafe.fbanks.bark_fbanks import bark_filter_banks

# init var
fs = 8000
nfilt = 7
nfft = 1024
low_freq = 0
high_freq = fs / 2

# compute freqs for xaxis
bhz_freqs = np.linspace(low_freq, high_freq, nfft //2+1)

for scale, label in [("constant", ""), ("ascendant", "Ascendant "), ("descendant", "Descendant ")]:
    # bark fbanks
    bark_fbanks_mat, bark_freqs = bark_filter_banks(nfilts=nfilt,
                                                    nfft=nfft,
                                                    fs=fs,
                                                    low_freq=low_freq,
                                                    high_freq=high_freq,
                                                    scale=scale)

    # visualize filter bank
    show_fbanks(
        bark_fbanks_mat,
        [bark2hz(freq) for freq in bark_freqs],
        bhz_freqs,
        label + "Bark Filter Bank",
        ylabel="Weight",
        x1label="Frequency / Hz",
        x2label="Frequency / bark",
        figsize=(14, 5),
        fb_type="bark",
    )
../_images/bark_fbanks-1_00.png
../_images/bark_fbanks-1_01.png
../_images/bark_fbanks-1_02.png