jatinchowdhury18 / audio_dspy
1 1
from unittest import TestCase
2 1
import numpy as np
3

4 1
import audio_dspy as adsp
5

6 1
_FS_ = 44100.0
7 1
_N_ = 1024
8

9

10 1
class TestHysteresis(TestCase):
11 1
    def test_hysteresis(self):
12 1
        freq = 100
13 1
        n = np.arange(_N_)
14 1
        x = np.sin(2 * np.pi * n * freq / _FS_) * (n/_N_)
15

16 1
        hysteresis = adsp.Hysteresis(1.0, 1.0, 1.0, _FS_, mode='RK4')
17 1
        y = hysteresis.process_block(x)
18

19 1
        hysteresis2 = adsp.Hysteresis(1.0, 1.0, 1.0, _FS_, mode='RK2')
20 1
        y2 = hysteresis2.process_block(x)
21

22 1
        hysteresis3 = adsp.Hysteresis(1.0, 1.0, 1.0, _FS_, mode='NR10')
23 1
        y3 = hysteresis3.process_block(x)
24

25 1
        self.assertTrue(np.sum(np.abs(y - y2)) / _N_ < 5.0e-6,
26
                        'RK2 Hysteresis response is incorrect!')
27

28 1
        self.assertTrue(np.sum(np.abs(y - y3)) / _N_ < 5.0e-6,
29
                        'NR10 Hysteresis response is incorrect!')

Read our documentation on viewing source code .

Loading