Skip to content

Commit

Permalink
Add unit tests for noise_bandwidth()
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Jul 19, 2024
1 parent 4102cfb commit 4b9c09b
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
Empty file added tests/dsp/filter/__init__.py
Empty file.
89 changes: 89 additions & 0 deletions tests/dsp/filter/test_noise_bandwidth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
References:
- https://www.gaussianwaves.com/2020/09/equivalent-noise-bandwidth-enbw-of-window-functions/
"""

import pytest
import scipy.signal

import sdr


def test_boxcar():
n = 128
h = scipy.signal.windows.get_window("boxcar", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(1.000, rel=1e-3)


def test_barthann():
n = 128
h = scipy.signal.windows.get_window("barthann", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(1.456, rel=1e-3)


def test_bartlett():
n = 128
h = scipy.signal.windows.get_window("bartlett", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(1.333, rel=1e-3)


def test_blackman():
n = 128
h = scipy.signal.windows.get_window("blackman", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(1.727, rel=1e-3)


def test_blackmanharris():
n = 128
h = scipy.signal.windows.get_window("blackmanharris", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(2.004, rel=1e-3)


def test_bohman():
n = 128
h = scipy.signal.windows.get_window("bohman", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(1.786, rel=1e-3)


def test_flattop():
n = 128
h = scipy.signal.windows.get_window("flattop", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(3.770, rel=1e-3)


def test_hamming():
n = 128
h = scipy.signal.windows.get_window("hamming", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(1.363, rel=1e-3)


def test_hann():
n = 128
h = scipy.signal.windows.get_window("hann", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(1.500, rel=1e-3)


def test_nuttall():
n = 128
h = scipy.signal.windows.get_window("nuttall", n)
fir = sdr.FIR(h)
B_n = fir.noise_bandwidth(n)
assert B_n == pytest.approx(1.976, rel=1e-3)

0 comments on commit 4b9c09b

Please sign in to comment.