コード例 #1
0
def test_wrong_options_that_must_raise_value_error(khz_option, returns):
    if returns is None:
        with pytest.raises(ValueError):
            r468(1, khz_option)
    else:
        with pytest.raises(ValueError):
            r468(1, khz_option, returns)
コード例 #2
0
def test_value_lt_0_that_must_raise_value_error(hz, khz_option, returns):
    if returns is None:
        with pytest.raises(ValueError):
            r468(hz, khz_option)
    else:
        with pytest.raises(ValueError):
            r468(hz, khz_option, returns)
コード例 #3
0
def test_frequency_value_that_must_succeed(start, end, khz_option, returns):
    if returns is None:
        for i in range(start, end + 1):
            r468(i, khz_option)
    else:
        for i in range(start, end + 1):
            r468(i, khz_option, returns)
コード例 #4
0
def test_r468__against_itu_r_468_1khz_value_specs_tolerances(f):
    assert (
        round(f.expected_db - r468(f.frequency_hz, f.khz_option, "db"), 1)
        >= f.lower_tolerance
    )
    assert (
        round(f.expected_db - r468(f.frequency_hz, f.khz_option, "db"), 1)
        <= f.upper_tolerance
    )
コード例 #5
0
from itu_r_468_weighting.filter import r468
from tests.constants import GLOBAL_DB_TOLERANCE, ITU_R_468__FREQS_AND_EXP_VALS

# Example usage:
if __name__ == "__main__":

    print("\nSimple usage examples:\n")
    print("r468(1000, '1khz', 'db'):", r468(1000, "1khz", "db"))
    print("r468(1000, '2khz', 'db'):", r468(1000, "2khz", "db"))
    print("r468(1000, '1khz', 'factor'):", r468(1000, "1khz", "factor"))
    print("r468(1000, '2khz', 'factor'):", r468(1000, "2khz", "factor"))

    print("\nWith '1khz' and returns 'db' options:\n")
    for f in ITU_R_468__FREQS_AND_EXP_VALS:
        if f.khz_option is "1khz":
            print(f.frequency_hz, r468(f.frequency_hz, "1khz", "db"))

    print("\nWith '2khz' and returns 'db' options:\n")
    for f in ITU_R_468__FREQS_AND_EXP_VALS:
        if f.khz_option is "2khz":
            print(f.frequency_hz, r468(f.frequency_hz, "2khz", "db"))

    print("\nWith '1khz' and returns 'factor' options:\n")
    for f in ITU_R_468__FREQS_AND_EXP_VALS:
        if f.khz_option is "1khz":
            print(f.frequency_hz, r468(f.frequency_hz, "1khz", "factor"))

    print("\nWith '2khz' and returns 'factor' options:\n")
    for f in ITU_R_468__FREQS_AND_EXP_VALS:
        if f.khz_option is "2khz":
            print(f.frequency_hz, r468(f.frequency_hz, "2khz", "factor"))
コード例 #6
0
import matplotlib.pyplot as plt
from itu_r_468_weighting.filter import r468

if __name__ == "__main__":

    db_1k = []
    for i in range(24001):
        db_1k.append(r468(i, "1khz"))

    db_2k = []
    for i in range(24001):
        db_2k.append(r468(i, "2khz"))

    plt.plot(db_1k, "-b", label="1 kHz")
    plt.plot(db_2k, "-r", label="2 kHz")
    plt.legend(loc="upper left")
    plt.xscale("symlog", linthreshy=0.015)
    plt.grid(True)
    plt.xlabel("Frequency (Hz)")
    plt.ylabel("Gain (dB)")
    plt.axis([10, 100e3, -50, 20])
    plt.show()

    db_1k_norm = []
    for i in range(24001):
        db_1k_norm.append(r468(i, "1khz", "norm"))

    db_2k_norm = []
    for i in range(24001):
        db_2k_norm.append(r468(i, "2khz", "norm"))
コード例 #7
0
from itu_r_468_weighting.constants import (
    GLOBAL_DB_TOLERANCE,
    ITU_R_468__FREQS_AND_EXP_VALS__1KHZ,
    ITU_R_468__FREQS_AND_EXP_VALS__2KHZ,
)
from itu_r_468_weighting.filter import r468

ITU_R_468__FREQS = [f[0] for f in ITU_R_468__FREQS_AND_EXP_VALS__1KHZ]

# Example usage:
if __name__ == "__main__":

    print("\nSimple usage examples:\n")
    print("r468(1000, '1khz'):", r468(1000, "1khz"))
    print("r468(1000, '2khz'):", r468(1000, "2khz"))

    print("\nWith '1khz' option:\n")
    for f in ITU_R_468__FREQS:
        print(f, r468(f, "1khz"))

    print("\nWith '2khz' option:\n")
    for f in ITU_R_468__FREQS:
        print(f, r468(f, "2khz"))

    print("\nWith '1khz' and returns 'norm' options:\n")
    for f in ITU_R_468__FREQS:
        print(f, r468(f, "1khz", "norm"))

    print("\nWith '2khz' and returns 'norm' options:\n")
    for f in ITU_R_468__FREQS:
        print(f, r468(f, "2khz", "norm"))
コード例 #8
0
def test_value_of_0_that_must_return_inf(hz, khz_option, returns):
    if returns is None:
        assert r468(hz, khz_option) == inf
    else:
        assert r468(hz, khz_option, returns) == inf
コード例 #9
0
def test_r468__against_itu_r_468_2khz_value_specs_tolerances(freqs):
    assert round(freqs[1] - r468(freqs[0], "2khz"), 1) >= freqs[2][0]
    assert round(freqs[1] - r468(freqs[0], "2khz"), 1) <= freqs[2][1]
コード例 #10
0
def test_r468__against_itu_r_468_2khz_value_specs(freqs):
    assert abs(freqs[1] - r468(freqs[0], "2khz")) <= GLOBAL_DB_TOLERANCE
コード例 #11
0
def test_r468__against_itu_r_468_1khz_value_specs(f):
    assert (
        abs(f.expected_db - r468(f.frequency_hz, f.khz_option, "db"))
        <= GLOBAL_DB_TOLERANCE
    )
コード例 #12
0
def test_hz_value_of_0_must_return_0(hz, khz_option, returns):
    assert r468(hz, khz_option, returns) == 0.0
コード例 #13
0
import matplotlib.pyplot as plt

from itu_r_468_weighting.filter import r468

if __name__ == "__main__":

    db_1k = []
    for i in range(24001):
        db_1k.append(r468(i, "1khz", "db"))

    db_2k = []
    for i in range(24001):
        db_2k.append(r468(i, "2khz", "db"))

    plt.plot(db_1k, "-b", label="1 kHz")
    plt.plot(db_2k, "-r", label="2 kHz")
    plt.legend(loc="upper left")
    plt.xscale("symlog", linthreshy=0.015)
    plt.grid(True)
    plt.xlabel("Frequency (Hz)")
    plt.ylabel("Gain (dB)")
    plt.axis([10, 100e3, -50, 20])
    plt.show()

    db_1k_factor = []
    for i in range(24001):
        db_1k_factor.append(r468(i, "1khz", "factor"))

    db_2k_factor = []
    for i in range(24001):
        db_2k_factor.append(r468(i, "2khz", "factor"))