spafe.fbanks.linear_fbanks#

spafe.fbanks.linear_fbanks.linear_filter_banks(nfilts: int = 24, nfft: int = 512, fs: int = 16000, low_freq: float = 0, high_freq: Optional[float] = None, scale: typing_extensions.Literal[ascendant, descendant, constant] = 'constant')[source]#

Compute linear-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 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 linear filters. (Default 0 Hz).

  • high_freq (float) – highest band edge of linear filters. (Default samplerate/2).

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

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)

Tip

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

Examples

from spafe.utils.vis import show_fbanks
from spafe.fbanks.linear_fbanks import linear_filter_banks


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

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

for scale, label in [("constant", ""), ("ascendant", "Ascendant "), ("descendant", "Descendant ")]:
    # ascendant linear fbank
    linear_fbanks_mat, lin_freqs = linear_filter_banks(nfilts=nfilt,
                                                       nfft=nfft,
                                                       fs=fs,
                                                       low_freq=low_freq,
                                                       high_freq=high_freq,
                                                       scale=scale)

    # visualize fbanks
    show_fbanks(
        linear_fbanks_mat,
        lin_freqs,
        lhz_freqs,
        label + "Linear Filter Bank",
        ylabel="Weight",
        x1label="Frequency / Hz",
        figsize=(14, 5),
        fb_type="lin")
../_images/linear_fbanks-1_00.png
../_images/linear_fbanks-1_01.png
../_images/linear_fbanks-1_02.png