forked from M-Labs/artiq
1
0
Fork 0

wavesynth/compute_samples: use set_coefficients

This commit is contained in:
Sebastien Bourdeauducq 2015-03-15 16:48:24 +01:00
parent 0d8260af6e
commit 327448977c
1 changed files with 24 additions and 18 deletions

View File

@ -5,8 +5,8 @@ import cairoplot
class Spline: class Spline:
def __init__(self, c): def __init__(self):
self.set_coefficients(c) self.c = [0.0]
def set_coefficients(self, c): def set_coefficients(self, c):
self.c = copy(c) self.c = copy(c)
@ -19,17 +19,17 @@ class Spline:
class SplinePhase: class SplinePhase:
def __init__(self, c): def __init__(self):
self.c = [0.0] self.c = [0.0]
self.set_coefficients(c) self.c0 = 0.0
def clear(self):
self.c[0] = 0.0
def set_coefficients(self, c): def set_coefficients(self, c):
self.c = self.c[0:1] + c[1:] self.c = self.c[0:1] + c[1:]
self.c0 = self.c[0] self.c0 = self.c[0]
def clear(self):
self.c[0] = 0.0
def next(self): def next(self):
r = self.c[0] + self.c0 r = self.c[0] + self.c0
for i in range(len(self.c)-1): for i in range(len(self.c)-1):
@ -38,32 +38,38 @@ class SplinePhase:
class DDS: class DDS:
def __init__(self, c_amplitude, c_phase): def __init__(self):
self.amplitude = Spline(c_amplitude) self.amplitude = Spline()
self.phase = SplinePhase(c_phase) self.phase = SplinePhase()
def next(self): def next(self):
return self.amplitude.next()*cos(2*pi*self.phase.next()) return self.amplitude.next()*cos(2*pi*self.phase.next())
class Wave: class Wave:
def __init__(self, c_bias, c_dds_amplitude, c_dds_phase): def __init__(self):
self.bias = Spline(c_bias) self.bias = Spline()
self.dds = DDS(c_dds_amplitude, c_dds_phase) self.dds = DDS()
def next(self): def next(self):
return self.bias.next() + self.dds.next() return self.bias.next() + self.dds.next()
if __name__ == "__main__": if __name__ == "__main__":
w = Wave([0.0, 0.0, 0.0], [0.0, 0.0, 0.01], [0.0, 0.0, 0.0005])
x = list(range(400)) x = list(range(400))
w = Wave()
w.dds.amplitude.set_coefficients([0.0, 0.0, 0.01])
w.dds.phase.set_coefficients([0.0, 0.0, 0.0005])
y = [w.next() for i in range(100)] y = [w.next() for i in range(100)]
w.dds.amplitude.c[2] = -0.01
w.dds.amplitude.set_coefficients([49.5, 1.0, -0.01])
y += [w.next() for i in range(100)] y += [w.next() for i in range(100)]
w.dds.amplitude.c[2] = -0.01
w.dds.phase.c[2] = -0.0005 w.dds.phase.set_coefficients([0.0, 0.1, -0.0005])
y += [w.next() for i in range(100)] y += [w.next() for i in range(100)]
w.dds.amplitude.c[2] = 0.01
w.dds.amplitude.set_coefficients([50.5, -1.0, 0.01])
y += [w.next() for i in range(100)] y += [w.next() for i in range(100)]
cairoplot.scatter_plot("plot.png", [x, y]) cairoplot.scatter_plot("plot.png", [x, y])