interpolate: refactor discrete_compensate

This commit is contained in:
Robert Jördens 2015-04-05 04:32:23 -06:00
parent 75dfa95b4d
commit 9fd4594c53
3 changed files with 18 additions and 23 deletions

View File

@ -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]

View File

@ -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:

View File

@ -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],