artiq/artiq/test/coefficients.py
Robert Jordens 01416bb0be copyright: claim contributions
These are contributions of >= 30% or >= 20 lines (half-automated).

I hereby resubmit all my previous contributions to the ARTIQ project
under the following terms:

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

Closes #130

Signed-off-by: Robert Jordens <jordens@gmail.com>
2015-09-06 16:08:57 -06:00

41 lines
1.1 KiB
Python

# Copyright (C) 2014, 2015 Robert Jordens <jordens@gmail.com>
import unittest
import numpy as np
from artiq.wavesynth import coefficients, compute_samples
class TestSplineCoef(unittest.TestCase):
def setUp(self):
self.x = np.arange(5.)
self.y = np.sin(2*np.pi*self.x/5) + np.arange(2)[:, None]
self.s = coefficients.SplineSource(self.x, self.y, order=4)
def test_get_segment(self):
return list(self.s.get_segment_data(start=1.5, stop=3.2, scale=.01))
def test_synth(self):
d = self.test_get_segment()
d[0]["trigger"] = True
return compute_samples.Synthesizer(self.y.shape[0], [d, d + d])
def drive(self, s):
y = []
for f in 0, 1, None, 0:
if f is not None:
s.select(f)
y += s.trigger()[0]
return y
def test_run(self):
return self.drive(self.test_synth())
@unittest.skip("manual/visual test")
def test_plot(self):
import matplotlib.pyplot as plt
y = self.test_run()
plt.step(np.arange(len(y)), y)
plt.show()