jatinchowdhury18 / audio_dspy

@@ -21,29 +21,45 @@
Loading
21 21
22 22
    def run_block(self, func, gain, exp):
23 23
        block = np.zeros(_N_)
24 -
        block[:int(_N_/2)] = gain
25 -
        block[int(_N_/2):] = -gain
24 +
        block[:_N_//3] = gain
25 +
        block[_N_//3:2*_N_//3] = 0
26 +
        block[2*_N_//3:] = -gain
26 27
        out = func(block)
27 -
        self.assertTrue(np.abs(out[0] - exp) < _tolerance_,
28 -
                        'Expected: {}. Actual: {}'.format(exp, out[0]))
29 -
        self.assertTrue(np.abs(out[_N_-1] + exp) < _tolerance_,
30 -
                        'Expected: -{}. Actual: {}'.format(exp, out[_N_-1]))
28 +
        self.assertTrue(np.abs(out[0] - exp[0]) < _tolerance_,
29 +
                        'Expected: {}. Actual: {}'.format(exp[0], out[0]))
30 +
        self.assertTrue(np.abs(out[_N_//2] - exp[1]) < _tolerance_,
31 +
                        'Expected: {}. Actual: {}'.format(exp[1], out[_N_//2]))
32 +
        self.assertTrue(np.abs(out[_N_-1] - exp[2]) < _tolerance_,
33 +
                        'Expected: -{}. Actual: {}'.format(exp[2], out[_N_-1]))
31 34
32 35
    def test_soft_clipper(self):
33 36
        self.run_samples(lambda x: adsp.soft_clipper(
34 37
            x, 5), 10000, [0.8, 0, -0.8])
35 38
36 39
    def test_soft_clipper_block(self):
37 -
        self.run_block(lambda x: adsp.soft_clipper(x, 5), 10000, 0.8)
40 +
        self.run_block(lambda x: adsp.soft_clipper(
41 +
            x, 5), 10000, [0.8, 0.0, -0.8])
38 42
39 43
    def test_hard_clipper(self):
40 44
        self.run_samples(adsp.hard_clipper, 10000, [1.0, 0, -1.0])
41 45
42 46
    def test_hard_clipper_block(self):
43 -
        self.run_block(adsp.hard_clipper, 10000, 1.0)
47 +
        self.run_block(adsp.hard_clipper, 10000, [1.0, 0, -1.0])
44 48
45 49
    def test_dropout(self):
46 50
        self.run_samples(adsp.dropout, 0.2, [0.064, 0, -0.064])
47 51
48 52
    def test_dropout_block(self):
49 -
        self.run_block(adsp.dropout, 0.2, 0.064)
53 +
        self.run_block(adsp.dropout, 0.2, [0.064, 0, -0.064])
54 +
55 +
    def test_hwr(self):
56 +
        self.run_samples(adsp.halfWaveRect, 1.0, [1.0, 0.0, 0.0])
57 +
58 +
    def test_hwr_block(self):
59 +
        self.run_block(adsp.halfWaveRect, 1.0, [1.0, 0.0, 0.0])
60 +
61 +
    def test_dioderect(self):
62 +
        self.run_samples(adsp.diodeRect, 1.0, [0.997, 0.0, -0.167])
63 +
64 +
    def test_dioderect_block(self):
65 +
        self.run_block(adsp.diodeRect, 1.0, [0.997, 0.0, -0.167])

@@ -61,3 +61,41 @@
Loading
61 61
    return np.where(x > B, x - B + (B/width)**3,
62 62
                    np.where(x < -B, x + B - (B/width)**3,
63 63
                             (x/width)**3))
64 +
65 +
66 +
def halfWaveRect(x):
67 +
    """Implementation of an ideal half wave rectifier
68 +
69 +
    Parameters
70 +
    ----------
71 +
    x: {float, ndarray}
72 +
        input signal
73 +
74 +
    Returns
75 +
    -------
76 +
    y: {float, ndarray}
77 +
        output signal
78 +
    """
79 +
    return np.where(x < 0, 0, x)
80 +
81 +
82 +
def diodeRect(x, alpha=1.79, beta=0.2):
83 +
    """Implementation of a simple Schottky diode rectifier
84 +
85 +
    Parameters
86 +
    ----------
87 +
    x: {float, ndarray}
88 +
        input signal
89 +
90 +
    alpha: float
91 +
        input scale factor
92 +
93 +
    beta: float
94 +
        output scale factor
95 +
96 +
    Returns
97 +
    -------
98 +
    y: {float, ndarray}
99 +
        output signal
100 +
    """
101 +
    return beta * (np.exp(alpha*x) - 1.0)
Files Coverage
audio_dspy 83.26%
tests 100.00%
setup.py 100.00%
Project Totals (23 files) 89.56%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading