Skip to content

check_cola

check_cola(window, hop_size, eps=1e-05)

Checks the Constant Overlap Add (COLA) condition for a given window function.

Parameters:

Name Type Description Default
window NDArray[T]

The window samples.

required
hop_size int

The hop size between frames.

required
eps float

Tolerance for checking the COLA condition. Defaults to 1e-5.

1e-05

Returns:

Type Description
Tuple[bool, float, float]

Tuple[bool, float, float]: A 3-tuple containing: (is_cola, normalization_value, epsilon)

Source code in src/libsegmenter/util/check_cola.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def check_cola(
    window: NDArray[T], hop_size: int, eps: float = 1e-5
) -> Tuple[bool, float, float]:
    """
    Checks the Constant Overlap Add (COLA) condition for a given window function.

    Args:
        window (NDArray[T]): The window samples.
        hop_size (int): The hop size between frames.
        eps (float): Tolerance for checking the COLA condition. Defaults to 1e-5.

    Returns:
        Tuple[bool, float, float]:
            A 3-tuple containing:
            (is_cola, normalization_value, epsilon)

    """
    dc_value = float(np.sum(window, dtype=np.float32)) / hop_size
    upper_bound = dc_value
    lower_bound = dc_value

    # loop over partial shifts
    fundamental_freq = 1.0 / hop_size
    for k in range(1, hop_size):
        harmonic_freq = fundamental_freq * k

        # complex sinusoids
        csin = np.exp(1j * 2.0 * np.pi * harmonic_freq * np.arange(window.size))

        # frequency domain representation of window
        dft_coeff = np.sum(window * np.conjugate(csin))
        upper_bound += np.abs(dft_coeff) / hop_size
        lower_bound -= np.abs(dft_coeff) / hop_size

    e = upper_bound - lower_bound
    return (e < eps, (upper_bound + lower_bound) / 2.0, e)