Skip to content

Instantly share code, notes, and snippets.

@mattfoster
Created November 5, 2008 14:02
Show Gist options
  • Save mattfoster/22338 to your computer and use it in GitHub Desktop.
Save mattfoster/22338 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from enthought.traits.api \
import HasTraits, Array, Range, Float, Enum, on_trait_change, Property
from enthought.traits.ui.api import View, Item
from enthought.chaco.chaco_plot_editor import ChacoPlotItem
from numpy import arange
from numpy import sin,pi
class Data(HasTraits):
tt = Array
yy = Property(Array, depends_on=['amplitude', 'carrier_frequency',
'mod_frequency', 'mod_depth'])
amplitude = Range(low=0,high=50.0,value=20.0)
carrier_frequency = Range(low=.01,high=100.0,value=20)
mod_frequency = Range(low=.01, high=10.0,value=1)
mod_depth = Range(low=0.01, high=2, val=0.5)
plot_type = Enum("line", "scatter")
traits_view = View(ChacoPlotItem("tt", "yy",
type_trait='plot_type',
resizable=True,
x_label="time",
y_label="amplitude",
x_bounds=(0,10),
x_auto=False,
y_bounds=(-50,50),
y_auto=False,
color="blue",
bgcolor="white",
border_visible=True,
border_width=1,
title='AM Demo',
padding_bg_color="lightgray"),
Item(name='amplitude'),
Item(name='carrier_frequency'),
Item(name='mod_frequency'),
Item(name='mod_depth'),
Item(name='plot_type'),
resizable = True,
buttons = ["OK"],
title='AM Demo',
width=900, height=800)
def _tt_default(self):
""" Default handler for volume Trait Array. """
return arange(0, 100, 0.01)
def _get_yy(self):
"""Recalculate when one a trait the property depends on changes."""
w_c = 2*pi*(self.carrier_frequency)
w_m = 2*pi*(self.mod_frequency)
return (self.amplitude * sin(self.tt*w_c) +
(self.amplitude * self.mod_depth)/2 *
(sin(self.tt*(w_c + w_m)) +
sin(self.tt*(w_c + w_m))))
if __name__ == '__main__':
viewer = Data()
viewer.configure_traits()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment