Skip to content

Window Functions

Window function wrappers from mechestim. These generate window arrays used in signal processing (e.g., for windowed FFTs).

Cost Summary

Operation Cost Formula Notes
bartlett \(n\) Linear taper
hamming \(n\) One cosine term
hanning \(n\) One cosine term
blackman \(3n\) Three cosine terms
kaiser \(3n\) Bessel function evaluation

Examples

import mechestim as me

with me.BudgetContext(flop_budget=1_000_000) as budget:
    win = me.hamming(256)   # 256 FLOPs
    win2 = me.kaiser(256)   # 768 FLOPs (3 * 256)
    print(f"Window cost: {budget.flops_used}")  # 1024

API Reference

mechestim._window

Window function wrappers with FLOP counting.

bartlett_cost(n)

FLOP cost of Bartlett window generation.

Parameters:

Name Type Description Default
n int

Window length.

required

Returns:

Type Description
int

Estimated FLOP count: n.

Notes

One linear evaluation per sample.

Source code in src/mechestim/_window.py
def bartlett_cost(n: int) -> int:
    """FLOP cost of Bartlett window generation.

    Parameters
    ----------
    n : int
        Window length.

    Returns
    -------
    int
        Estimated FLOP count: n.

    Notes
    -----
    One linear evaluation per sample.
    """
    return max(n, 1)

blackman_cost(n)

FLOP cost of Blackman window generation.

Parameters:

Name Type Description Default
n int

Window length.

required

Returns:

Type Description
int

Estimated FLOP count: 3n.

Notes

Three cosine terms per sample.

Source code in src/mechestim/_window.py
def blackman_cost(n: int) -> int:
    """FLOP cost of Blackman window generation.

    Parameters
    ----------
    n : int
        Window length.

    Returns
    -------
    int
        Estimated FLOP count: 3n.

    Notes
    -----
    Three cosine terms per sample.
    """
    return max(3 * n, 1)

hamming_cost(n)

FLOP cost of Hamming window generation.

Parameters:

Name Type Description Default
n int

Window length.

required

Returns:

Type Description
int

Estimated FLOP count: 2n.

Notes

One cosine evaluation plus one linear combination per sample.

Source code in src/mechestim/_window.py
def hamming_cost(n: int) -> int:
    """FLOP cost of Hamming window generation.

    Parameters
    ----------
    n : int
        Window length.

    Returns
    -------
    int
        Estimated FLOP count: 2n.

    Notes
    -----
    One cosine evaluation plus one linear combination per sample.
    """
    return max(2 * n, 1)

hanning_cost(n)

FLOP cost of Hanning window generation.

Parameters:

Name Type Description Default
n int

Window length.

required

Returns:

Type Description
int

Estimated FLOP count: 2n.

Notes

One cosine evaluation plus one linear combination per sample.

Source code in src/mechestim/_window.py
def hanning_cost(n: int) -> int:
    """FLOP cost of Hanning window generation.

    Parameters
    ----------
    n : int
        Window length.

    Returns
    -------
    int
        Estimated FLOP count: 2n.

    Notes
    -----
    One cosine evaluation plus one linear combination per sample.
    """
    return max(2 * n, 1)

kaiser_cost(n)

FLOP cost of Kaiser window generation.

Parameters:

Name Type Description Default
n int

Window length.

required

Returns:

Type Description
int

Estimated FLOP count: 3n.

Notes

Bessel function evaluation per sample.

Source code in src/mechestim/_window.py
def kaiser_cost(n: int) -> int:
    """FLOP cost of Kaiser window generation.

    Parameters
    ----------
    n : int
        Window length.

    Returns
    -------
    int
        Estimated FLOP count: 3n.

    Notes
    -----
    Bessel function evaluation per sample.
    """
    return max(3 * n, 1)