2015-09-07 06:08:57 +08:00
|
|
|
# Copyright (C) 2014, 2015 Robert Jordens <jordens@gmail.com>
|
|
|
|
|
2015-04-05 13:40:27 +08:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
from artiq.wavesynth import compute_samples
|
|
|
|
|
|
|
|
|
|
|
|
class TestSynthesizer(unittest.TestCase):
|
|
|
|
program = [
|
|
|
|
[
|
|
|
|
# frame 0
|
|
|
|
{
|
|
|
|
# frame 0, segment 0, line 0
|
|
|
|
"dac_divider": 1,
|
|
|
|
"duration": 100,
|
|
|
|
"channel_data": [
|
|
|
|
{
|
|
|
|
# channel 0
|
|
|
|
"dds": {"amplitude": [0.0, 0.0, 0.01],
|
|
|
|
"phase": [0.0, 0.0, 0.0005],
|
|
|
|
"clear": False}
|
|
|
|
}
|
|
|
|
],
|
2015-04-05 17:54:02 +08:00
|
|
|
"trigger": True
|
2015-04-05 13:40:27 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
# frame 0, segment 0, line 1
|
|
|
|
"dac_divider": 1,
|
|
|
|
"duration": 100,
|
|
|
|
"channel_data": [
|
|
|
|
{
|
|
|
|
# channel 0
|
|
|
|
"dds": {"amplitude": [49.5, 1.0, -0.01],
|
|
|
|
"phase": [0.0, 0.05, 0.0005],
|
|
|
|
"clear": False}
|
|
|
|
}
|
|
|
|
],
|
2015-04-05 17:54:02 +08:00
|
|
|
"trigger": False
|
2015-04-05 13:40:27 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
[
|
|
|
|
# frame 1
|
|
|
|
{
|
|
|
|
# frame 1, segment 0, line 0
|
|
|
|
"dac_divider": 1,
|
|
|
|
"duration": 100,
|
|
|
|
"channel_data": [
|
|
|
|
{
|
|
|
|
# channel 0
|
|
|
|
"dds": {"amplitude": [100.0, 0.0, -0.01],
|
|
|
|
"phase": [0.0, 0.1, -0.0005],
|
|
|
|
"clear": False}
|
|
|
|
}
|
|
|
|
],
|
2015-04-05 17:54:02 +08:00
|
|
|
"trigger": True
|
2015-04-05 13:40:27 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
# frame 1, segment 0, line 1
|
|
|
|
"dac_divider": 1,
|
|
|
|
"duration": 100,
|
|
|
|
"channel_data": [
|
|
|
|
{
|
|
|
|
# channel 0
|
|
|
|
"dds": {"amplitude": [50.5, -1.0, 0.01],
|
|
|
|
"phase": [0.0, 0.05, -0.0005],
|
|
|
|
"clear": False}
|
|
|
|
}
|
|
|
|
],
|
2015-04-05 17:54:02 +08:00
|
|
|
"trigger": False
|
2015-04-05 13:40:27 +08:00
|
|
|
}
|
|
|
|
],
|
|
|
|
[
|
|
|
|
# frame 2
|
|
|
|
{
|
|
|
|
# frame 2, segment 0, line 0
|
|
|
|
"dac_divider": 1,
|
|
|
|
"duration": 84,
|
|
|
|
"channel_data": [
|
|
|
|
{
|
|
|
|
# channel 0
|
|
|
|
"dds": {"amplitude": [100.0],
|
|
|
|
"phase": [0.0, 0.05],
|
|
|
|
"clear": False}
|
|
|
|
}
|
|
|
|
],
|
2015-04-05 17:54:02 +08:00
|
|
|
"trigger": True
|
2015-04-05 13:40:27 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
# frame 2, segment 1, line 0
|
|
|
|
"dac_divider": 1,
|
|
|
|
"duration": 116,
|
|
|
|
"channel_data": [
|
|
|
|
{
|
|
|
|
# channel 0
|
|
|
|
"dds": {"amplitude": [100.0],
|
|
|
|
"phase": [0.0, 0.05],
|
|
|
|
"clear": True}
|
|
|
|
}
|
|
|
|
],
|
2015-04-05 17:54:02 +08:00
|
|
|
"trigger": True
|
2015-04-05 13:40:27 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
]
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
self.dev = compute_samples.Synthesizer(1, self.program)
|
|
|
|
self.t = list(range(600))
|
|
|
|
|
|
|
|
def drive(self):
|
|
|
|
s = self.dev
|
2015-04-05 17:54:02 +08:00
|
|
|
y = []
|
|
|
|
for f in 0, 2, None, 1:
|
|
|
|
if f is not None:
|
|
|
|
s.select(f)
|
|
|
|
y += s.trigger()[0]
|
2015-04-05 13:40:27 +08:00
|
|
|
x = list(range(600))
|
|
|
|
return x, y
|
|
|
|
|
|
|
|
def test_run(self):
|
|
|
|
x, y = self.drive()
|
2015-04-05 18:24:44 +08:00
|
|
|
|
|
|
|
@unittest.skip("manual/visual test")
|
|
|
|
def test_plot(self):
|
2016-04-07 21:36:30 +08:00
|
|
|
from matplotlib import pyplot as plt
|
2015-04-05 18:24:44 +08:00
|
|
|
x, y = self.drive()
|
2016-04-07 21:36:30 +08:00
|
|
|
plt.plot(x, y)
|
|
|
|
plt.show()
|