Synsq - reassign data use CWT data

class audioflux.Synsq(num, radix2_exp=12, samplate=32000, order=1, thresh=0.001)

Synsq algorithm

Parameters
num: int

Number of frequency bins to generate

radix2_exp: int

fft_length=2**radix2_exp

samplate: int

Sampling rate of the incoming audio

order: int

order value

thresh: float

thresh value

See also

Reassign
WSST

Examples

Read 220Hz audio data

>>> import audioflux as af
>>> audio_path = af.utils.sample_path('220')
>>> audio_arr, sr = af.read(audio_path)
>>> # WSST can only input fft_length data
>>> # For radix2_exp=12, then fft_length=4096
>>> audio_arr = audio_arr[..., :4096]

Create CWT object of octave

>>> from audioflux.type import SpectralFilterBankScaleType, WaveletContinueType
>>> from audioflux.utils import note_to_hz
>>> cwt_obj = af.CWT(num=84, radix2_exp=12, samplate=sr, low_fre=note_to_hz('C1'),
>>>                  bin_per_octave=12, wavelet_type=WaveletContinueType.MORLET,
>>>                  scale_type=SpectralFilterBankScaleType.OCTAVE)

Extract CWT spectrogram

>>> import numpy as np
>>> cwt_spec_arr = cwt_obj.cwt(audio_arr)

Create Synsq object

>>> synsq_obj = af.Synsq(num=cwt_obj.num,
>>>                      radix2_exp=cwt_obj.radix2_exp,
>>>                      samplate=cwt_obj.samplate)

Extract Synsq data

>>> synsq_arr = synsq_obj.synsq(cwt_spec_arr,
>>>                             filter_bank_type=cwt_obj.scale_type,
>>>                             fre_arr=cwt_obj.get_fre_band_arr())

Show spectrogram plot

>>> import matplotlib.pyplot as plt
>>> from audioflux.display import fill_spec
>>> # Show CWT
>>> fig, ax = plt.subplots()
>>> img = fill_spec(np.abs(cwt_spec_arr), axes=ax,
>>>                 x_coords=cwt_obj.x_coords(),
>>>                 y_coords=cwt_obj.y_coords(),
>>>                 x_axis='time', y_axis='log',
>>>                 title='CWT')
>>> fig.colorbar(img, ax=ax)
>>>
>>> # Show Synsq
>>> fig, ax = plt.subplots()
>>> img = fill_spec(np.abs(synsq_arr), axes=ax,
>>>                 x_coords=cwt_obj.x_coords(),
>>>                 y_coords=cwt_obj.y_coords(),
>>>                 x_axis='time', y_axis='log',
>>>                 title='Synsq')
>>> fig.colorbar(img, ax=ax)
../_images/synsq-1_00.png
../_images/synsq-1_01.png

Methods

synsq(m_data_arr, filter_bank_type, fre_arr)

Get synsq data

synsq(m_data_arr, filter_bank_type, fre_arr)

Get synsq data

Parameters
m_data_arr: np.ndarray [shape=(…, fre, time), dtype=np.complex]

spectrogram data

filter_bank_type: SpectralFilterBankScaleType

bank type,need to correspond to m_data_arr.

See: type.SpectralFilterBankScaleType

fre_arr: np.ndarray [shape=(fre,)]

fre band arr,need to correspond to m_data_arr. Use get_fre_band_arr method to get

Returns
out: np.ndarray [shape=(…, fre, time), dtype=np.complex]