toolbox/nt/transform/module_stft.py
def sample_id_to_stft_frame_id(sample, window_length, shift, fading=True):
    """
    Calculates the best frame index for a given sample index
    :param sample: Sample index in time domain.
    :param size: FFT size.
    :param shift: Hop in samples.
    :return: Best STFT frame index.


    ## ## ## ##
       ## ## ## ##
          ## ## ## ##
             ## ## ## ##
    00 00 01 12 23 34 45


    ## ## ## ##
     # ## ## ## #
       ## ## ## ##
        # ## ## ## #
    00 00 01 23 5 ...
          12 34 6 ...

    ## ## ## #
       ## ## ## #
          ## ## ## #
             ## ## ## #
    ## ## ## #
    00 00 01 12 23 34 45

    >>> [sample_id_to_stft_frame_id(i, 8, 1, fading=False) for i in range(12)]
    [0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]
    >>> [sample_id_to_stft_frame_id(i, 8, 2, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 1, 2, 2, 3, 3]
    >>> [sample_id_to_stft_frame_id(i, 7, 2, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 1, 2, 2, 3, 3]
    >>> [sample_id_to_stft_frame_id(i, 7, 1, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 2, 3, 4, 5, 6]

    >>> [sample_id_to_stft_frame_id(i, 8, 1, fading=True) for i in range(12)]
    [7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    >>> [sample_id_to_stft_frame_id(i, 8, 2, fading=True) for i in range(10)]
    [3, 3, 3, 3, 4, 4, 5, 5, 6, 6]
    >>> [sample_id_to_stft_frame_id(i, 7, 2, fading=True) for i in range(10)]
    [3, 3, 3, 3, 4, 4, 5, 5, 6, 6]
    >>> [sample_id_to_stft_frame_id(i, 7, 1, fading=True) for i in range(10)]
    [6, 6, 6, 6, 7, 8, 9, 10, 11, 12]

    >>> stft(np.zeros([8]), size=8, shift=2).shape
    (7, 5)
    >>> stft(np.zeros([8]), size=8, shift=1).shape
    (15, 5)
    >>> stft(np.zeros([8]), size=8, shift=4).shape
    (3, 5)
    """

    if (window_length + 1) // 2 > sample:
        frame = 0
    else:
        frame = (sample - (window_length + 1) // 2) // shift + 1

    if fading:
        frame = frame + ceil((window_length - shift) / shift)

    return frame

    Calculates the best frame index for a given sample index
    :param sample: Sample index in time domain.
    :param size: FFT size.
    :param shift: Hop in samples.
    :return: Best STFT frame index.


    ## ## ## ##
       ## ## ## ##
          ## ## ## ##
             ## ## ## ##
    00 00 01 12 23 34 45


    ## ## ## ##
     # ## ## ## #
       ## ## ## ##
        # ## ## ## #
    00 00 01 23 5 ...
          12 34 6 ...

    ## ## ## #
       ## ## ## #
          ## ## ## #
             ## ## ## #
    ## ## ## #
    00 00 01 12 23 34 45

    >>> [sample_id_to_stft_frame_id(i, 8, 1, fading=False) for i in range(12)]
    [0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]
    >>> [sample_id_to_stft_frame_id(i, 8, 2, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 1, 2, 2, 3, 3]
    >>> [sample_id_to_stft_frame_id(i, 7, 2, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 1, 2, 2, 3, 3]
    >>> [sample_id_to_stft_frame_id(i, 7, 1, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 2, 3, 4, 5, 6]

    >>> [sample_id_to_stft_frame_id(i, 8, 1, fading=True) for i in range(12)]
    [7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    >>> [sample_id_to_stft_frame_id(i, 8, 2, fading=True) for i in range(10)]
    [3, 3, 3, 3, 4, 4, 5, 5, 6, 6]
    >>> [sample_id_to_stft_frame_id(i, 7, 2, fading=True) for i in range(10)]
    [3, 3, 3, 3, 4, 4, 5, 5, 6, 6]
    >>> [sample_id_to_stft_frame_id(i, 7, 1, fading=True) for i in range(10)]
    [6, 6, 6, 6, 7, 8, 9, 10, 11, 12]

    >>> stft(np.zeros([8]), size=8, shift=2).shape
    (7, 5)
    >>> stft(np.zeros([8]), size=8, shift=1).shape
    (15, 5)
    >>> stft(np.zeros([8]), size=8, shift=4).shape
    (3, 5)
    
Calculates the best frame index for a given sample index
Calculates the best frame index for a given sample index
def sample_id_to_stft_frame_id(sample, window_length, shift, fading=True):
    if (window_length + 1) // 2 > sample:
        frame = 0
    else:
        frame = (sample - (window_length + 1) // 2) // shift + 1
    if fading:
        frame = frame + ceil((window_length - shift) / shift)
    return frame
def sample_id_to_stft_frame_id ( sample , window_length , shift , fading = True ) : if ( window_length + 1 ) // 2 > sample : frame = 0 else : frame = ( sample - ( window_length + 1 ) // 2 ) // shift + 1 if fading : frame = frame + ceil ( ( window_length - shift ) / shift ) return frame
Calculates the best frame index for a given sample index
Calculates the best frame index for a given sample index
"""
    Calculates the best frame index for a given sample index
    :param sample: Sample index in time domain.
    :param size: FFT size.
    :param shift: Hop in samples.
    :return: Best STFT frame index.


    ## ## ## ##
       ## ## ## ##
          ## ## ## ##
             ## ## ## ##
    00 00 01 12 23 34 45


    ## ## ## ##
     # ## ## ## #
       ## ## ## ##
        # ## ## ## #
    00 00 01 23 5 ...
          12 34 6 ...

    ## ## ## #
       ## ## ## #
          ## ## ## #
             ## ## ## #
    ## ## ## #
    00 00 01 12 23 34 45

    >>> [sample_id_to_stft_frame_id(i, 8, 1, fading=False) for i in range(12)]
    [0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8]
    >>> [sample_id_to_stft_frame_id(i, 8, 2, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 1, 2, 2, 3, 3]
    >>> [sample_id_to_stft_frame_id(i, 7, 2, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 1, 2, 2, 3, 3]
    >>> [sample_id_to_stft_frame_id(i, 7, 1, fading=False) for i in range(10)]
    [0, 0, 0, 0, 1, 2, 3, 4, 5, 6]

    >>> [sample_id_to_stft_frame_id(i, 8, 1, fading=True) for i in range(12)]
    [7, 7, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15]
    >>> [sample_id_to_stft_frame_id(i, 8, 2, fading=True) for i in range(10)]
    [3, 3, 3, 3, 4, 4, 5, 5, 6, 6]
    >>> [sample_id_to_stft_frame_id(i, 7, 2, fading=True) for i in range(10)]
    [3, 3, 3, 3, 4, 4, 5, 5, 6, 6]
    >>> [sample_id_to_stft_frame_id(i, 7, 1, fading=True) for i in range(10)]
    [6, 6, 6, 6, 7, 8, 9, 10, 11, 12]

    >>> stft(np.zeros([8]), size=8, shift=2).shape
    (7, 5)
    >>> stft(np.zeros([8]), size=8, shift=1).shape
    (15, 5)
    >>> stft(np.zeros([8]), size=8, shift=4).shape
    (3, 5)
    """
Best STFT frame index.










Best STFT frame index .
sample
Sample index in time domain.
Sample index in time domain .
window_length
shift
Hop in samples.
Hop in samples .
fading
size
None