toolbox/nt/transform/module_stft.py
def istft(
        stft_signal,
        size: int=1024,
        shift: int=256,
        *,
        window: typing.Callable=signal.blackman,
        fading: bool=True,
        window_length: int=None,
        symmetric_window: bool=False,
):
    """
    Calculated the inverse short time Fourier transform to exactly reconstruct
    the time signal.

    ..note::
        Be careful if you make modifications in the frequency domain (e.g.
        beamforming) because the synthesis window is calculated according to
        the unmodified! analysis window.

    :param stft_signal: Single channel complex STFT signal
        with dimensions (..., frames, size/2+1).
    :param size: Scalar FFT-size.
    :param shift: Scalar FFT-shift. Typically shift is a fraction of size.
    :param window: Window function handle.
    :param fading: Removes the additional padding, if done during STFT.
    :param window_length: Sometimes one desires to use a shorter window than
        the fft size. In that case, the window is padded with zeros.
        The default is to use the fft-size as a window size.
    :param symmetric_window: symmetric or periodic window. Assume window is
        periodic. Since the implementation of the windows in scipy.signal have a
        curious behaviour for odd window_length. Use window(len+1)[:-1]. Since
        is equal to the behaviour of MATLAB.
    :return: Single channel complex STFT signal
    :return: Single channel time signal.
    """
    # Note: frame_axis and frequency_axis would make this function much more
    #       complicated
    stft_signal = np.array(stft_signal)

    assert stft_signal.shape[-1] == size // 2 + 1, str(stft_signal.shape)

    if window_length is None:
        window_length = size

    if symmetric_window:
        window = window(window_length)
    else:
        window = window(window_length + 1)[:-1]

    window = _biorthogonal_window_fastest(window, shift)

    # window = _biorthogonal_window_fastest(
    #     window, shift, use_amplitude_for_biorthogonal_window)
    # if disable_sythesis_window:
    #     window = np.ones_like(window)

    time_signal = np.zeros(
        (*stft_signal.shape[:-2],
         stft_signal.shape[-2] * shift + window_length - shift))

    # Get the correct view to time_signal
    time_signal_seg = segment_axis_v2(
        time_signal, window_length, shift, end=None
    )

    # Unbuffered inplace add
    np.add.at(
        time_signal_seg,
        ...,
        window * np.real(irfft(stft_signal))[..., :window_length]
    )
    # The [..., :window_length] is the inverse of the window padding in rfft.

    # Compensate fade-in and fade-out
    if fading:
        time_signal = time_signal[
            ..., window_length - shift:time_signal.shape[-1] - (window_length - shift)]

    return time_signal

    Calculated the inverse short time Fourier transform to exactly reconstruct
    the time signal.

    ..note::
        Be careful if you make modifications in the frequency domain (e.g.
        beamforming) because the synthesis window is calculated according to
        the unmodified! analysis window.

    :param stft_signal: Single channel complex STFT signal
        with dimensions (..., frames, size/2+1).
    :param size: Scalar FFT-size.
    :param shift: Scalar FFT-shift. Typically shift is a fraction of size.
    :param window: Window function handle.
    :param fading: Removes the additional padding, if done during STFT.
    :param window_length: Sometimes one desires to use a shorter window than
        the fft size. In that case, the window is padded with zeros.
        The default is to use the fft-size as a window size.
    :param symmetric_window: symmetric or periodic window. Assume window is
        periodic. Since the implementation of the windows in scipy.signal have a
        curious behaviour for odd window_length. Use window(len+1)[:-1]. Since
        is equal to the behaviour of MATLAB.
    :return: Single channel complex STFT signal
    :return: Single channel time signal.
    
Calculated the inverse short time Fourier transform to exactly reconstruct
the time signal.

:
Be careful if you make modifications in the frequency domain  because the synthesis window is calculated according to
the unmodified. analysis window.
Calculated the inverse short time Fourier transform to exactly reconstruct the time signal . : Be careful if you make modifications in the frequency domain because the synthesis window is calculated according to the unmodified . analysis window .
def istft(
        stft_signal,
        size: int=1024,
        shift: int=256,
        *,
        window: typing.Callable=signal.blackman,
        fading: bool=True,
        window_length: int=None,
        symmetric_window: bool=False,
):
    stft_signal = np.array(stft_signal)
    assert stft_signal.shape[-1] == size // 2 + 1, str(stft_signal.shape)
    if window_length is None:
        window_length = size
    if symmetric_window:
        window = window(window_length)
    else:
        window = window(window_length + 1)[:-1]
    window = _biorthogonal_window_fastest(window, shift)
    time_signal = np.zeros(
        (*stft_signal.shape[:-2],
         stft_signal.shape[-2] * shift + window_length - shift))
    time_signal_seg = segment_axis_v2(
        time_signal, window_length, shift, end=None
    )
    np.add.at(
        time_signal_seg,
        ...,
        window * np.real(irfft(stft_signal))[..., :window_length]
    )
    if fading:
        time_signal = time_signal[
            ..., window_length - shift:time_signal.shape[-1] - (window_length - shift)]
    return time_signal
def istft ( stft_signal , size : int = 1024 , shift : int = 256 , * , window : typing . Callable = signal . blackman , fading : bool = True , window_length : int = None , symmetric_window : bool = False , ) : stft_signal = np . array ( stft_signal ) assert stft_signal . shape [ - 1 ] == size // 2 + 1 , str ( stft_signal . shape ) if window_length is None : window_length = size if symmetric_window : window = window ( window_length ) else : window = window ( window_length + 1 ) [ : - 1 ] window = _biorthogonal_window_fastest ( window , shift ) time_signal = np . zeros ( ( * stft_signal . shape [ : - 2 ] , stft_signal . shape [ - 2 ] * shift + window_length - shift ) ) time_signal_seg = segment_axis_v2 ( time_signal , window_length , shift , end = None ) np . add . at ( time_signal_seg , ... , window * np . real ( irfft ( stft_signal ) ) [ ... , : window_length ] ) if fading : time_signal = time_signal [ ... , window_length - shift : time_signal . shape [ - 1 ] - ( window_length - shift ) ] return time_signal
Calculated the inverse short time Fourier transform to exactly reconstruct
the time signal.
Calculated the inverse short time Fourier transform to exactly reconstruct the time signal .
"""
    Calculated the inverse short time Fourier transform to exactly reconstruct
    the time signal.

    ..note::
        Be careful if you make modifications in the frequency domain (e.g.
        beamforming) because the synthesis window is calculated according to
        the unmodified! analysis window.

    :param stft_signal: Single channel complex STFT signal
        with dimensions (..., frames, size/2+1).
    :param size: Scalar FFT-size.
    :param shift: Scalar FFT-shift. Typically shift is a fraction of size.
    :param window: Window function handle.
    :param fading: Removes the additional padding, if done during STFT.
    :param window_length: Sometimes one desires to use a shorter window than
        the fft size. In that case, the window is padded with zeros.
        The default is to use the fft-size as a window size.
    :param symmetric_window: symmetric or periodic window. Assume window is
        periodic. Since the implementation of the windows in scipy.signal have a
        curious behaviour for odd window_length. Use window(len+1)[:-1]. Since
        is equal to the behaviour of MATLAB.
    :return: Single channel complex STFT signal
    :return: Single channel time signal.
    """ # Note: frame_axis and frequency_axis would make this function much more #       complicated # window = _biorthogonal_window_fastest( #     window, shift, use_amplitude_for_biorthogonal_window) # if disable_sythesis_window: #     window = np.ones_like(window) # Get the correct view to time_signal # Unbuffered inplace add # The [..., :window_length] is the inverse of the window padding in rfft. # Compensate fade-in and fade-out
Single channel complex STFT signal
Single channel complex STFT signal
Single channel time signal.
Single channel time signal .
stft_signal
Single channel complex STFT signal
with dimensions (..., frames, size/2+1).
Single channel complex STFT signal with dimensions ( ... frames size / 2 + 1 ) .
size
int
None
shift
int
Scalar FFT-shift. Typically shift is a fraction of size.
Scalar FFT - shift . Typically shift is a fraction of size .
window
typing.Callable
Window function handle.
Window function handle .
fading
bool
Removes the additional padding, if done during STFT.
Removes the additional padding if done during STFT .
window_length
int
Sometimes one desires to use a shorter window than
the fft size. In that case, the window is padded with zeros.
The default is to use the fft-size as a window size.
Sometimes one desires to use a shorter window than the fft size . In that case the window is padded with zeros . The default is to use the fft - size as a window size .
symmetric_window
bool
symmetric or periodic window. Assume window is
periodic. Since the implementation of the windows in scipy.signal have a
curious behaviour for odd window_length.
symmetric or periodic window . Assume window is periodic . Since the implementation of the windows in scipy . signal have a curious behaviour for odd window_length .