Skip to content

WindowSelector

WindowSelector(window, scheme, segment_size)

Selects and returns a specific window function based on the given parameters.

This function retrieves a window function based on the window type, applies an adaptation based on scheme, and returns the corresponding Window object.

Parameters:

Name Type Description Default
window str

The type of window function to apply. Supported values include: [ bartlett50, bartlett75, blackman67, kaiser85, hamming50, hamming75, hann50, hann75, rectangular0 ]

required
scheme str

The adaptation scheme to use. Supported values: [ ola, wola, analysis ]

required
segment_size int

The size of the segment/window.

required

Returns:

Name Type Description
Window Window

A Window object containing the selected window function and its corresponding hop size.

Raises:

Type Description
ValueError

If an unknown window type or scheme is provided.

Source code in src/libsegmenter/WindowSelector.py
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
def WindowSelector(window: str, scheme: str, segment_size: int) -> Window:
    """
    Selects and returns a specific window function based on the given parameters.

    This function retrieves a window function based on the `window` type, applies
    an adaptation based on `scheme`, and returns the corresponding `Window` object.

    Args:
        window (str): The type of window function to apply. Supported values include:
            [
             `bartlett50`,
             `bartlett75`,
             `blackman67`,
             `kaiser85`,
             `hamming50`,
             `hamming75`,
             `hann50`,
             `hann75`,
             `rectangular0`
            ]
        scheme (str): The adaptation scheme to use. Supported values:
            [
             `ola`,
             `wola`,
             `analysis`
            ]
        segment_size (int): The size of the segment/window.

    Returns:
        Window: A `Window` object containing the selected window function and its
            corresponding hop size.

    Raises:
        ValueError: If an unknown window type or scheme is provided.

    """
    if window == "bartlett50":
        from libsegmenter.windows.bartlett import bartlett50

        return _adapt_window(*bartlett50(segment_size), scheme)

    if window == "bartlett75":
        from libsegmenter.windows.bartlett import bartlett75

        return _adapt_window(*bartlett75(segment_size), scheme)

    if window == "blackman67":
        from libsegmenter.windows.blackman import blackman67

        return _adapt_window(*blackman67(segment_size), scheme)

    if window == "kaiser85":
        from libsegmenter.windows.kaiser import kaiser85

        return _adapt_window(*kaiser85(segment_size), scheme)

    if window == "hamming50":
        from libsegmenter.windows.hamming import hamming50

        return _adapt_window(*hamming50(segment_size), scheme)

    if window == "hamming75":
        from libsegmenter.windows.hamming import hamming75

        return _adapt_window(*hamming75(segment_size), scheme)

    if window == "hann50":
        from libsegmenter.windows.hann import hann50

        return _adapt_window(*hann50(segment_size), scheme)

    if window == "hann75":
        from libsegmenter.windows.hann import hann75

        return _adapt_window(*hann75(segment_size), scheme)

    if window == "rectangular0":
        from libsegmenter.windows.rectangular import rectangular0

        return _adapt_window(*rectangular0(segment_size), scheme)

    if window == "rectangular50":
        from libsegmenter.windows.rectangular import rectangular50

        return _adapt_window(*rectangular50(segment_size), scheme)

    raise ValueError(f"The '{window}' window is not known.")