Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: m-labs/artiq
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: bba434e9518e
Choose a base ref
...
head repository: m-labs/artiq
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 03139808bd46
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 24, 2015

  1. Copy the full SHA
    6a0bc19 View commit details
  2. [WIP] wavesynth/interpolate: wavesynth programming tools

    * interpolate(t, v) will generate the channel data subset of a wavesynth
    program
    
    * still broken
    jordens committed Mar 24, 2015
    1
    Copy the full SHA
    0313980 View commit details
Showing with 56 additions and 0 deletions.
  1. +11 −0 artiq/devices/pdq2/driver.py
  2. +45 −0 artiq/wavesynth/interpolate.py
11 changes: 11 additions & 0 deletions artiq/devices/pdq2/driver.py
Original file line number Diff line number Diff line change
@@ -66,11 +66,22 @@ def compensate(coef):
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])
data = self.pack([0, 1, 2, 2], coef)
self.line(typ=0, data=data, **kwargs)

def dds(self, amplitude=[], phase=[], **kwargs):
"""Append a dds line to this segment.
Amplitude in volts,
phase[0] in turns,
phase[1] in turns*sample_rate,
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])
if phase:
45 changes: 45 additions & 0 deletions artiq/wavesynth/interpolate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import numpy as np
from scipy.interpolate import splrep, splev


def _round_times(times, sample_times=None):
times = np.asanyarray(times)
if sample_times is None:
sample_times = np.rint(times)
duration = np.diff(sample_times)
sample_times = sample_times[:-1]
assert np.all(duration >= 0)
assert np.all(duration < (1 << 16))
return times, sample_times, duration


def _interpolate(time, data, sample_times, order=3):
# FIXME: this does not ensure that the spline does not clip
spline = splrep(time, data, k=order or 1)
# FIXME: this could be faster but needs k knots outside t_eval
# dv = np.array(spalde(t_eval, s))
coeffs = np.array([splev(sample_times, spline, der=i, ext=0)
for i in range(order + 1)]).T
return coeffs


def _zip_program(times, channels, target=):
for tc in zip(times, *channels):
yield {
"duration": tc[0],
"channel_data": tc[1:],
}
# FIXME: this does not handle:
# `clear` (clearing the phase accumulator)
# `silence` (stopping the dac clock)


def interpolate_channels(times, data, sample_times=None, **kwargs):
if len(times) == 1:
return _zip_program(np.array([1]), data[:, :, None])
data = np.asanyarray(data)
assert len(times) == len(data)
times, sample_times, duration = _round_times(times, sample_times)
channel_coeff = [_interpolate(sample_times, i, **kwargs) for i in data.T]
return _zip_program(duration, np.array(channel_coeff))
# v = np.clip(v/self.max_out, -1, 1)