WPT - Wave Packet Transform

class audioflux.WPT(num=None, radix2_exp=12, samplate=32000, wavelet_type=WaveletDiscreteType.SYM, t1=4, t2=0)

Wave Packet Transform (WPT)

Parameters
num: int or None

Number of frequency bins is 2**num

If num is None, then num = radix2_exp - 1

radix2_exp: int

fft_length=2**radix2_exp

wavelet_type: WaveletDiscreteType

Wavelet discrete type

See: type.WaveletDiscreteType

Note

t1/t2 settings for wavelet_type:

  • DB: t1
    • 2~10/20/30/40

  • SYM: t1
    • 2~10/20/30

  • COIF: t1
    • 1/2/3/4/5

  • FK: t1
    • 4/6/8/14/18/22

  • BIOR/DMEY: t1.t2
    • 1.1/1.3/1.5

    • 2.2/2.4/2.6/2.8

    • 3.1/3.3/3.5/3.7/3.9

    • 4.4/5.5/6.8

t1: int

t1 value

t2: int

t2 value

See also

CQT
ST
FST
DWT
SWT

Examples

Read 880Hz audio data

>>> import audioflux as af
>>> audio_path = af.utils.sample_path('880')
>>> audio_arr, sr = af.read(audio_path)
>>> audio_arr = audio_arr[..., :4096]

Create WPT object

>>> from audioflux.type import WaveletDiscreteType
>>> obj = af.WPT(num=7, radix2_exp=12, samplate=sr,
>>>              wavelet_type=WaveletDiscreteType.SYM,
>>>              t1=4, t2=0)

Extract WPT data

>>> import numpy as np
>>> coef_arr, m_data_arr = obj.wpt(audio_arr)
>>> m_data_arr = np.abs(m_data_arr)

Show plot

>>> import matplotlib.pyplot as plt
>>> from audioflux.display import fill_spec, fill_plot
>>> fig, ax = plt.subplots(nrows=2)
>>> fill_spec(m_data_arr, axes=ax[0],
>>>           x_coords=obj.x_coords(), y_coords=obj.y_coords(),
>>>           x_axis='time', y_axis='log',
>>>           title='WPT')
>>> fill_plot(np.arange(coef_arr.shape[-1]), coef_arr,
>>>           axes=ax[1], label='WPT-coef')
../_images/wpt-1.png

Methods

wpt(data_arr)

Get wpt matrix

x_coords()

Get the X-axis coordinate

y_coords()

Get the Y-axis coordinate

get_fre_band_arr

wpt(data_arr)

Get wpt matrix

Parameters
data_arr: np.ndarray [shape=(…, 2**radix2_exp)]

Input audio data

Returns
coef_arr: np.ndarray [shape=(…, time), dtype=np.float32]
m_data_arr: np.ndarray [shape=(…, fre, time), dtype=np.float32]
y_coords()

Get the Y-axis coordinate

Returns
out: np.ndarray [shape=(fre,)]
x_coords()

Get the X-axis coordinate

Returns
out: np.ndarray [shape=(time,)]