audioflux.bark_spectrogram

audioflux.bark_spectrogram(X, num=128, radix2_exp=12, samplate=32000, low_fre=None, high_fre=None, window_type=WindowType.HANN, slide_length=None, style_type=SpectralFilterBankStyleType.SLANEY, normal_type=SpectralFilterBankNormalType.NONE, data_type=SpectralDataType.POWER)

Bark-scale spectrogram.

Note

We recommend using the BFT class, you can use it more flexibly and efficiently.

Parameters
X: np.ndarray [shape=(…, n)]

audio time series.

num: int

Number of bark frequency bins to generate, starting at low_fre.

radix2_exp: int

fft_length=2**radix2_exp.

samplate: int

Sampling rate of the incoming audio.

low_fre: float

Lowest frequency.

high_fre: float or None

Highest frequency. Default is 16000 (samplate / 2).

window_type: WindowType

Window type for each frame.

See: type.WindowType

slide_length: int or None

Window sliding length.

If slide_length is None, then slide_length = fft_length / 4

style_type: SpectralFilterBankStyleType

Spectral filter bank style type. It determines the bank type of window.

see: type.SpectralFilterBankStyleType

normal_type: SpectralFilterBankNormalType

Spectral filter normal type. It determines the type of normalization.

See: type.SpectralFilterBankNormalType

data_type: SpectralDataType

Spectrogram data type.

It cat be set to mag or power. If you needs db type, you can set power type and then call the power_to_db method.

See: type.SpectralDataType

Returns
spectrogram: np.ndarray [shape=(…, fre, time)]

The matrix of BARK

fre_band_arr: np:ndarray [shape=(fre,)]

The array of frequency bands

Examples

Read 220Hz audio data

>>> import audioflux as af
>>> audio_path = af.utils.sample_path('220')
>>> audio_arr, sr = af.read(audio_path)

Extract spectrogram of dB

>>> low_fre = 0
>>> spec_arr, fre_band_arr = af.bark_spectrogram(audio_arr, samplate=sr, low_fre=low_fre)
>>> spec_dB_arr = af.utils.power_to_db(spec_arr)

Show spectrogram plot

>>> import matplotlib.pyplot as plt
>>> from audioflux.display import fill_spec
>>> import numpy as np
>>>
>>> # calculate x/y-coords
>>> audio_len = audio_arr.shape[-1]
>>> x_coords = np.linspace(0, audio_len/sr, spec_arr.shape[-1] + 1)
>>> y_coords = np.insert(fre_band_arr, 0, low_fre)
>>>
>>> fig, ax = plt.subplots()
>>> img = fill_spec(spec_dB_arr, axes=ax,
>>>                 x_coords=x_coords,
>>>                 y_coords=y_coords,
>>>                 x_axis='time', y_axis='log',
>>>                 title='Bark Spectrogram')
>>> fig.colorbar(img, ax=ax, format="%+2.0f dB")
../_images/audioflux-bark_spectrogram-1.png