From 9fd4594c5363954f58122418f8f51a320392f747 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Sun, 5 Apr 2015 04:32:23 -0600 Subject: [PATCH] interpolate: refactor discrete_compensate --- artiq/devices/pdq2/driver.py | 23 ++++++++--------------- artiq/wavesynth/compute_samples.py | 8 +------- artiq/wavesynth/interpolate.py | 10 +++++++++- 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/artiq/devices/pdq2/driver.py b/artiq/devices/pdq2/driver.py index c6d3ad566..851adb5c8 100644 --- a/artiq/devices/pdq2/driver.py +++ b/artiq/devices/pdq2/driver.py @@ -6,13 +6,16 @@ import struct import serial +from artiq.wavesynth.interpolate import discrete_compensate + + logger = logging.getLogger(__name__) class Segment: max_time = 1 << 16 # uint16 timer max_val = 1 << 15 # int16 DAC - max_out = 10. # Volt + max_out = 10. # Volt out_scale = max_val/max_out cordic_gain = 1. for i in range(16): @@ -53,24 +56,13 @@ class Segment: values, widths, ud, fmt, e) raise e - @staticmethod - def compensate(coef): - """compensates higher order spline coefficients for integrator chain - latency""" - order = len(coef) - if order > 2: - coef[1] += coef[2]/2. - if order > 3: - coef[1] += coef[3]/6. - coef[2] += coef[3] - return coef - def bias(self, amplitude=[], **kwargs): """Append a bias line to this segment. Amplitude in volts """ - coef = self.compensate([self.out_scale*a for a in amplitude]) + coef = [self.out_scale*a for a in amplitude] + discrete_compensate(coef) data = self.pack([0, 1, 2, 2], coef) self.line(typ=0, data=data, **kwargs) @@ -83,7 +75,8 @@ class Segment: phase[2] in turns*(sample_rate/2**shift)**2 """ scale = self.out_scale/self.cordic_gain - coef = self.compensate([scale*a for a in amplitude]) + coef = [scale*a for a in amplitude] + discrete_compensate(coef) if phase: assert len(amplitude) == 4 coef += [p*self.max_val*2 for p in phase] diff --git a/artiq/wavesynth/compute_samples.py b/artiq/wavesynth/compute_samples.py index 31a345480..debe393a6 100644 --- a/artiq/wavesynth/compute_samples.py +++ b/artiq/wavesynth/compute_samples.py @@ -1,13 +1,7 @@ from copy import copy from math import cos, pi - -def discrete_compensate(c): - if len(c) > 2: - c[1] += c[2]/2 - if len(c) > 3: - c[1] += c[3]/6 - c[2] += c[3] +from artiq.wavesynth.interpolate import discrete_compensate class Spline: diff --git a/artiq/wavesynth/interpolate.py b/artiq/wavesynth/interpolate.py index 39cdf4bf0..8e133c1c7 100644 --- a/artiq/wavesynth/interpolate.py +++ b/artiq/wavesynth/interpolate.py @@ -23,7 +23,15 @@ def _interpolate(time, data, sample_times, order=3): return coeffs -def _zip_program(times, channels, target=): +def discrete_compensate(c): + if len(c) > 2: + c[1] += c[2]/2 + if len(c) > 3: + c[1] += c[3]/6 + c[2] += c[3] + + +def _zip_program(times, channels, target): for tc in zip(times, *channels): yield { "duration": tc[0],