SWT - Stationary Wavelet Transform
- class audioflux.SWT(num, fft_length, wavelet_type=WaveletDiscreteType.SYM, t1=4, t2=0)
Stationary Wavelet Transform (SWT)
- Parameters
- num: int
Number of frequency bins to generate.
- fft_length: int
fft length
- wavelet_type: WaveletDiscreteType
Wavelet discrete type
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
Examples
Read 220Hz audio data
>>> import audioflux as af >>> audio_path = af.utils.sample_path('220') >>> audio_arr, sr = af.read(audio_path) >>> audio_len = 4096 * 5 >>> audio_arr = audio_arr[:audio_len]
Create SWT object
>>> from audioflux.type import WaveletDiscreteType >>> obj = af.SWT(num=5, fft_length=audio_len, >>> wavelet_type=WaveletDiscreteType.DB, t1=4, t2=0)
Get SWT data
>>> data_arr1, data_arr2 = obj.swt(audio_arr)
Save SWT data
>>> save_data_arr1 = data_arr1[-1] # index `0~num-1` is the SWT data of different series >>> save_data_arr2 = data_arr2[-1] # index `0~num-1` is the SWT data of different series >>> # You can save SWT to audio file >>> # af.write('SAVE_PATH_1.wav', save_data_arr1) >>> # af.write('SAVE_PATH_2.wav', save_data_arr2)
Show wave plot
>>> import matplotlib.pyplot as plt >>> from audioflux.display import fill_wave >>> >>> n_num, n_time = data_arr2.shape >>> fig, ax = plt.subplots(nrows=n_num + 1, figsize=(8, 16), sharex=True, layout='tight') >>> _ax0 = fill_wave(audio_arr[:n_time], samplate=sr, axes=ax[0]) >>> _ax0.set_title('SWT arr2 origin') >>> for i in range(n_num): >>> _ax = fill_wave(data_arr2[i], samplate=sr, axes=ax[i + 1]) >>> _ax.set_title(f'SWT arr2 num={i}') >>> >>> n_num, n_time = data_arr1.shape >>> fig, ax = plt.subplots(nrows=n_num + 1, figsize=(8, 16), sharex=True, layout='tight') >>> _ax0 = fill_wave(audio_arr[:n_time], samplate=sr, axes=ax[0]) >>> _ax0.set_title('SWT arr1 origin') >>> for i in range(n_num): >>> _ax = fill_wave(data_arr1[i], samplate=sr, axes=ax[i + 1]) >>> _ax.set_title(f'SWT arr1 num={i}')
Methods
swt
(data_arr)Get swt matrix
- swt(data_arr)
Get swt matrix
- Parameters
- data_arr: np.ndarray [shape=(…, n)]
Input audio data
- Returns
- m_data_arr1: np.ndarray [shape=(…, fre, time)]
- m_data_arr2: np.ndarray [shape=(…, fre, time)]