Reassign - reassign transform for STFT
- class audioflux.Reassign(radix2_exp=12, samplate=32000, window_type=WindowType.HANN, slide_length=None, re_type=ReassignType.ALL, thresh=0.001, is_padding=False)
Reassign - reassign transform for STFT
- Parameters
- radix2_exp: int
fft_length=2**radix2_exp
- samplate: int
Sampling rate of the incoming audio
- window_type: WindowType
Window type for each frame.
See:
type.WindowType
- slide_length: int or None
Window sliding length.
- re_type: ReassignType
Reassign type
- thresh: float
thresh
- is_padding: bool
Whether to use padding
Examples
Read 220Hz audio data
>>> import audioflux as af >>> audio_path = af.utils.sample_path('220') >>> audio_arr, sr = af.read(audio_path)
Create Reassign object
>>> from audioflux.type import ReassignType, WindowType >>> obj = af.Reassign(radix2_exp=12, samplate=sr, window_type=WindowType.HANN, >>> slide_length=None, re_type=ReassignType.ALL)
Extract spectrogram
>>> import numpy as np >>> re_spec_arr, bft_spec_arr = obj.reassign(audio_arr) >>> re_spec_arr = np.abs(re_spec_arr) >>> bft_spec_arr = np.abs(bft_spec_arr)
Show spectrogram plot
>>> import matplotlib.pyplot as plt >>> from audioflux.display import fill_spec >>> audio_len = audio_arr.shape[-1] >>> # Show BFT/STFT Spectrogram >>> fig, ax = plt.subplots() >>> img = fill_spec(bft_spec_arr, axes=ax, >>> x_coords=obj.x_coords(audio_len), >>> y_coords=obj.y_coords(), >>> x_axis='time', y_axis='log', >>> title='BFT/STFT Spectrogram') >>> fig.colorbar(img, ax=ax) >>> >>> # Show Reassign Spectrogram >>> fig, ax = plt.subplots() >>> img = fill_spec(re_spec_arr, axes=ax, >>> x_coords=obj.x_coords(audio_len), >>> y_coords=obj.y_coords(), >>> x_axis='time', y_axis='log', >>> title='Reassign Spectrogram') >>> fig.colorbar(img, ax=ax)
Methods
cal_time_length
(data_length)Calculate the length of a frame from audio data.
reassign
(data_arr[, result_type])Get reassign matrix
set_order
(order)Set order
set_result_type
(result_type)Set result type.
x_coords
(data_length)Get the X-axis coordinate
y_coords
()Get the Y-axis coordinate
- cal_time_length(data_length)
Calculate the length of a frame from audio data.
- Parameters
- data_length: int
The length of the data to be calculated.
- Returns
- out: int
- set_result_type(result_type)
Set result type.
- Parameters
- result_type: int, 0 or 1
If 0, then the result is a matrix of complex numbers.
If 1, then the result is a matrix of real numbers.
- set_order(order)
Set order
- Parameters
- order: int
order >= 1
- reassign(data_arr, result_type=0)
Get reassign matrix
- Parameters
- data_arr: np.ndarray [shape=(…, n)]
Input audio data
- result_type: int, 0 or 1
If 0, then the result is a matrix of complex numbers.
If 1, then the result is a matrix of real numbers.
- Returns
- m_arr1: np.ndarray [shape=(…, fre, time), dtype=(np.complex or np.float32)]
The matrix of reassign
- m_arr2: np.ndarray [shape=(…, fre, time), dtype=np.complex]
The matrix of origin(BFT/STFT)
- y_coords()
Get the Y-axis coordinate
- Returns
- out: np.ndarray [shape=(fre,)]
- x_coords(data_length)
Get the X-axis coordinate
- Parameters
- data_length: int
The length of the data to be calculated.
- Returns
- out: np.ndarray [shape=(time,)]