forked from M-Labs/artiq
interpolate: refactor discrete_compensate
This commit is contained in:
parent
75dfa95b4d
commit
9fd4594c53
|
@ -6,13 +6,16 @@ import struct
|
||||||
|
|
||||||
import serial
|
import serial
|
||||||
|
|
||||||
|
from artiq.wavesynth.interpolate import discrete_compensate
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Segment:
|
class Segment:
|
||||||
max_time = 1 << 16 # uint16 timer
|
max_time = 1 << 16 # uint16 timer
|
||||||
max_val = 1 << 15 # int16 DAC
|
max_val = 1 << 15 # int16 DAC
|
||||||
max_out = 10. # Volt
|
max_out = 10. # Volt
|
||||||
out_scale = max_val/max_out
|
out_scale = max_val/max_out
|
||||||
cordic_gain = 1.
|
cordic_gain = 1.
|
||||||
for i in range(16):
|
for i in range(16):
|
||||||
|
@ -53,24 +56,13 @@ class Segment:
|
||||||
values, widths, ud, fmt, e)
|
values, widths, ud, fmt, e)
|
||||||
raise 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):
|
def bias(self, amplitude=[], **kwargs):
|
||||||
"""Append a bias line to this segment.
|
"""Append a bias line to this segment.
|
||||||
|
|
||||||
Amplitude in volts
|
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)
|
data = self.pack([0, 1, 2, 2], coef)
|
||||||
self.line(typ=0, data=data, **kwargs)
|
self.line(typ=0, data=data, **kwargs)
|
||||||
|
|
||||||
|
@ -83,7 +75,8 @@ class Segment:
|
||||||
phase[2] in turns*(sample_rate/2**shift)**2
|
phase[2] in turns*(sample_rate/2**shift)**2
|
||||||
"""
|
"""
|
||||||
scale = self.out_scale/self.cordic_gain
|
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:
|
if phase:
|
||||||
assert len(amplitude) == 4
|
assert len(amplitude) == 4
|
||||||
coef += [p*self.max_val*2 for p in phase]
|
coef += [p*self.max_val*2 for p in phase]
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
from copy import copy
|
from copy import copy
|
||||||
from math import cos, pi
|
from math import cos, pi
|
||||||
|
|
||||||
|
from artiq.wavesynth.interpolate import discrete_compensate
|
||||||
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]
|
|
||||||
|
|
||||||
|
|
||||||
class Spline:
|
class Spline:
|
||||||
|
|
|
@ -23,7 +23,15 @@ def _interpolate(time, data, sample_times, order=3):
|
||||||
return coeffs
|
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):
|
for tc in zip(times, *channels):
|
||||||
yield {
|
yield {
|
||||||
"duration": tc[0],
|
"duration": tc[0],
|
||||||
|
|
Loading…
Reference in New Issue