madmom.audio.stft¶
This module contains Short-Time Fourier Transform (STFT) related functionality.
-
madmom.audio.stft.
fft_frequencies
(num_fft_bins, sample_rate)[source]¶ Frequencies of the FFT bins.
Parameters: num_fft_bins : int
Number of FFT bins (i.e. half the FFT length).
sample_rate : float
Sample rate of the signal.
Returns: fft_frequencies : numpy array
Frequencies of the FFT bins [Hz].
-
madmom.audio.stft.
stft
(frames, window, fft_size=None, circular_shift=False)[source]¶ Calculates the complex Short-Time Fourier Transform (STFT) of the given framed signal.
Parameters: frames : numpy array or iterable, shape (num_frames, frame_size)
Framed signal (e.g.
FramedSignal
instance)window : numpy array, shape (frame_size,)
Window (function).
fft_size : int, optional
FFT size (should be a power of 2); if ‘None’, the ‘frame_size’ given by the frames is used; if the given fft_size is greater than the ‘frame_size’, the frames are zero-padded accordingly.
circular_shift : bool, optional
Circular shift the individual frames before performing the FFT; needed for correct phase.
Returns: stft : numpy array, shape (num_frames, frame_size)
The complex STFT of the framed signal.
-
madmom.audio.stft.
phase
(stft)[source]¶ Returns the phase of the complex STFT of a signal.
Parameters: stft : numpy array, shape (num_frames, frame_size)
The complex STFT of a signal.
Returns: phase : numpy array
Phase of the STFT.
-
madmom.audio.stft.
local_group_delay
(phase)[source]¶ Returns the local group delay of the phase of a signal.
Parameters: phase : numpy array, shape (num_frames, frame_size)
Phase of the STFT of a signal.
Returns: lgd : numpy array
Local group delay of the phase.
-
madmom.audio.stft.
lgd
(phase)¶ Returns the local group delay of the phase of a signal.
Parameters: phase : numpy array, shape (num_frames, frame_size)
Phase of the STFT of a signal.
Returns: lgd : numpy array
Local group delay of the phase.
-
class
madmom.audio.stft.
PropertyMixin
[source]¶ Mixin which provides num_frames, num_bins properties to classes.
-
num_frames
¶ Number of frames.
-
num_bins
¶ Number of bins.
-
-
class
madmom.audio.stft.
ShortTimeFourierTransform
(frames, window=<function hanning>, fft_size=None, circular_shift=False, **kwargs)[source]¶ ShortTimeFourierTransform class.
Parameters: frames :
audio.signal.FramedSignal
instanceFramedSignal instance.
window : numpy ufunc or numpy array, optional
Window (function); if a function (e.g. np.hanning) is given, a window of the given shape of size of the frames is used.
fft_size : int, optional
FFT size (should be a power of 2); if ‘None’, the frame_size given by the frames is used, if the given fft_size is greater than the frame_size, the frames are zero-padded accordingly.
circular_shift : bool, optional
Circular shift the individual frames before performing the FFT; needed for correct phase.
kwargs : dict, optional
If no
audio.signal.FramedSignal
instance was given, one is instantiated with these additional keyword arguments.Notes
If the
Signal
(wrapped in theFramedSignal
) has an integer dtype, it is automatically scaled as if it has a float dtype with the values being in the range [-1, 1]. This results in same valued STFTs independently of the dtype of the signal. On the other hand, this prevents extra memory consumption since the data-type of the signal does not need to be converted (and if no decoding is needed, the audio signal can be memory mapped).-
spec
(**kwargs)[source]¶ Returns the magnitude spectrogram of the STFT.
Parameters: kwargs : dict, optional
Keyword arguments passed to
audio.spectrogram.Spectrogram
.Returns: spec :
audio.spectrogram.Spectrogram
audio.spectrogram.Spectrogram
instance.
-
-
madmom.audio.stft.
STFT
¶ alias of
ShortTimeFourierTransform
-
class
madmom.audio.stft.
ShortTimeFourierTransformProcessor
(window=<function hanning>, fft_size=None, circular_shift=False, **kwargs)[source]¶ ShortTimeFourierTransformProcessor class.
Parameters: window : numpy ufunc, optional
Window function.
fft_size : int, optional
FFT size (should be a power of 2); if ‘None’, it is determined by the size of the frames; if is greater than the frame size, the frames are zero-padded accordingly.
circular_shift : bool, optional
Circular shift the individual frames before performing the FFT; needed for correct phase.
-
process
(data, **kwargs)[source]¶ Perform FFT on a framed signal and return the STFT.
Parameters: data : numpy array
Data to be processed.
kwargs : dict, optional
Keyword arguments passed to
ShortTimeFourierTransform
.Returns: stft :
ShortTimeFourierTransform
ShortTimeFourierTransform
instance.
-
static
add_arguments
(parser, window=None, fft_size=None)[source]¶ Add STFT related arguments to an existing parser.
Parameters: parser : argparse parser instance
Existing argparse parser.
window : numpy ufunc, optional
Window function.
fft_size : int, optional
Use this size for FFT (should be a power of 2).
Returns: argpase argument group
STFT argument parser group.
Notes
Parameters are included in the group only if they are not ‘None’.
-
-
madmom.audio.stft.
STFTProcessor
¶ alias of
ShortTimeFourierTransformProcessor
-
class
madmom.audio.stft.
Phase
(stft, **kwargs)[source]¶ Phase class.
Parameters: stft :
ShortTimeFourierTransform
instanceShortTimeFourierTransform
instance.kwargs : dict, optional
If no
ShortTimeFourierTransform
instance was given, one is instantiated with these additional keyword arguments.-
local_group_delay
(**kwargs)[source]¶ Returns the local group delay of the phase.
Parameters: kwargs : dict, optional
Keyword arguments passed to
LocalGroupDelay
.Returns: lgd :
LocalGroupDelay
instanceLocalGroupDelay
instance.
-
lgd
(**kwargs)¶ Returns the local group delay of the phase.
Parameters: kwargs : dict, optional
Keyword arguments passed to
LocalGroupDelay
.Returns: lgd :
LocalGroupDelay
instanceLocalGroupDelay
instance.
-
-
class
madmom.audio.stft.
LocalGroupDelay
(phase, **kwargs)[source]¶ Local Group Delay class.
Parameters: stft :
Phase
instancePhase
instance.kwargs : dict, optional
If no
Phase
instance was given, one is instantiated with these additional keyword arguments.
-
madmom.audio.stft.
LGD
¶ alias of
LocalGroupDelay