Skip to content

openstb.simulator.system.signal_windows

Windows that can be applied to transmitted signals.

This module is designed to be similar in nature to the scipy.signal.windows module in SciPy. The function get_window_func looks up a window function by name. In SciPy, the windows are created from the number of coefficients. Here, the windows are created from the times of the signal samples and the signal duration, and values outside the signal are set to a fill value.

Classes:

Name Description
BlackmanHarrisWindow

A Blackman-Harris window.

BlackmanWindow

A Blackman window.

GeneralisedCosineWindow

A generalised cosine window.

HammingWindow

A Hamming window.

HannWindow

A Hann window.

NuttallWindow

A Nuttall window.

TukeyWindow

A Tukey window.

BlackmanHarrisWindow

BlackmanHarrisWindow()

Bases: GeneralisedCosineWindow

A Blackman-Harris window.

The Blackman-Harris window is a four-term generalised cosine window with coefficients a0=0.35875, a1=0.48829, a2=0.14128 and a3 = 0.01168.

Source code in openstb/simulator/system/signal_windows.py
96
97
def __init__(self):
    super().__init__(coefficients=[0.35875, 0.48829, 0.14128, 0.01168])

BlackmanWindow

BlackmanWindow()

Bases: GeneralisedCosineWindow

A Blackman window.

The Blackman window is a three-term generalised cosine window with coefficients a0=0.42, a1=0.5 and a2 = 0.08.

Source code in openstb/simulator/system/signal_windows.py
84
85
def __init__(self):
    super().__init__(coefficients=[0.42, 0.5, 0.08])

GeneralisedCosineWindow

GeneralisedCosineWindow(coefficients)

Bases: SignalWindow

A generalised cosine window.

The generalised cosine window is the weighted sum of a series of harmonic cosines. Many common windows can be implemented as generalised cosine windows.

Notes

For a list of coefficients a of length K, the generalised cosine window is given by

.. math::

w(t) = \sum_{k=0}^{K-1} (-1)^k a[k] \cos\frac{2\pi k t}{T}

for :math:0 \leq t \leq T where :math:T is the signal duration.

Parameters:

Name Type Description Default
coefficients list of floats

The coefficients of the cosines.

required
Source code in openstb/simulator/system/signal_windows.py
41
42
43
44
45
46
47
48
49
50
51
52
53
def __init__(self, coefficients: list[float]):
    """
    Parameters
    ----------
    coefficients : list of floats
        The coefficients of the cosines.

    """
    if not coefficients:
        raise ValueError(
            _("at least one coefficient needed for a generalised cosine window")
        )
    self.coefficients = coefficients

HammingWindow

HammingWindow(mode='optimal')

Bases: GeneralisedCosineWindow

A Hamming window.

The Hamming window is a two-term generalised cosine window. The first term is raised above the axis, resulting in a window that does not reach zero but places a zero-crossing in a position which cancels the first sidelobe of a Hann (raised cosine) window.

Parameters:

Name Type Description Default
mode (optimal, original, scipy)

If "optimal", use the optimal cosine coefficients a0=0.53836 and a1=0.46164 which result in the lowest sidelobes. If "original", use Hamming's original parameters a0=25/46 and a1=21/46. If "scipy", use the same parameters as scipy.signal.window.hamming a0=0.54 and a1=0.46.

"optimal"
Source code in openstb/simulator/system/signal_windows.py
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
def __init__(self, mode: str = "optimal"):
    """
    Parameters
    ----------
    mode : {"optimal", "original", "scipy"}
        If "optimal", use the optimal cosine coefficients a0=0.53836 and a1=0.46164
        which result in the lowest sidelobes. If "original", use Hamming's original
        parameters a0=25/46 and a1=21/46. If "scipy", use the same parameters as
        `scipy.signal.window.hamming` a0=0.54 and a1=0.46.

    """
    if mode == "optimal":
        a0 = 0.53836
    elif mode == "original":
        a0 = 25 / 46
    elif mode == "scipy":
        a0 = 0.54
    else:
        raise ValueError(_("unknown Hamming mode {name:s}").format(name=mode))
    super().__init__(coefficients=[a0, 1 - a0])

HannWindow

HannWindow()

Bases: GeneralisedCosineWindow

A Hann window.

Also known as a raised cosine window or von Hann window, and sometimes incorrectly as a Hanning window, presumably due to the similarity with the Hamming window.

Source code in openstb/simulator/system/signal_windows.py
140
141
def __init__(self):
    super().__init__(coefficients=[0.5, 0.5])

NuttallWindow

NuttallWindow()

Bases: GeneralisedCosineWindow

A Nuttall window.

The Nuttall (sometimes called the Blackman-Nutall) window is a four-term generalised cosine window with coefficients a0=0.3635819,, a1=0.4891775, a2=0.1365995 and a3=0.0106411.

Source code in openstb/simulator/system/signal_windows.py
153
154
def __init__(self):
    super().__init__(coefficients=[0.3635819, 0.4891775, 0.1365995, 0.0106411])

TukeyWindow

TukeyWindow(alpha)

Bases: SignalWindow

A Tukey window.

The Tukey or cosine-tapered window has a taper formed by half a cosine at either end of the window covering a given fraction of the window.

Parameters:

Name Type Description Default
alpha float

The fraction of the window that is tapered, 0 ≤ alpha ≤ 1. Note that this is the total fraction used for tapering; alpha/2 of either end of the window is tapered. alpha = 0 results in a rectangular window and alpha = 1 in a Hann window.

required
Source code in openstb/simulator/system/signal_windows.py
165
166
167
168
169
170
171
172
173
174
175
176
177
178
def __init__(self, alpha):
    """
    Parameters
    ----------
    alpha : float
        The fraction of the window that is tapered, 0 ≤ alpha ≤ 1. Note that this is
        the total fraction used for tapering; alpha/2 of either end of the window is
        tapered. alpha = 0 results in a rectangular window and alpha = 1 in a Hann
        window.

    """
    if not 0 <= alpha <= 1:
        raise ValueError(_("alpha must be between 0 and 1 for a Tukey window"))
    self.alpha = alpha