Exemplo n.º 1
0
def main():
    """Run example."""
    T = 10
    fs = 100
    x, t = harm(
        length=T,
        sample_rate=fs,
        amp=1,
        freq=1,
    )
    plt.plot(t, x)
    x, t = harm(length=T, sample_rate=fs, amp=2, freq=1, noise_amp=noise)
    plt.plot(t, x)
    x, t = harm(length=T, sample_rate=fs, amp=2, freq=1, noise_ph=noise)
    plt.plot(t, x)
    plt.show()
Exemplo n.º 2
0
 def test_noised_amplitude(self):
     xs = mod.harm(length=60,
                   sample_rate=50,
                   amp=1,
                   freq=1,
                   noise_amp=lambda: 1)[0]
     self.assertAlmostEqual(max(xs), 2)
     self.assertAlmostEqual(min(xs), -2)
Exemplo n.º 3
0
 def test_noised_phase(self):
     xs = mod.harm(length=60,
                   sample_rate=1,
                   amp=1,
                   freq=1,
                   noise_ph=lambda: np.pi / 2)[0]
     self.assertAlmostEqual(sum(xs), 0)
     self.assertAlmostEqual(max(xs), 0)
     self.assertAlmostEqual(min(xs), 0)
Exemplo n.º 4
0
    def test_amplitude_and_rate(self):
        rate = 50
        length = 120
        amp = 2.5

        xs, ts = mod.harm(length=length, sample_rate=rate, amp=amp, freq=1)
        self.assertEqual(len(xs), len(ts))
        self.assertEqual(len(xs), length * rate)
        self.assertAlmostEqual(max(xs), amp)
        self.assertAlmostEqual(min(xs), -amp)
        self.assertAlmostEqual(sum(xs), 0)
        self.assertAlmostEqual(ts[1] - ts[0], 1 / rate)
Exemplo n.º 5
0
 def test_frequency(self):
     xs = mod.harm(length=60, sample_rate=1, amp=1, freq=1)[0]
     self.assertAlmostEqual(sum(xs), 60)