spafe.fbanks.linear_fbanks#
Description : Linear filter banks implementation.
Copyright (c) 2019-2024 Ayoub Malek. This source code is licensed under the terms of the BSD 3-Clause License. For a copy, see <https://github.com/SuperKogito/spafe/blob/master/LICENSE>.
- 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")