Onyx logo

Table Of Contents

Previous topic

onyx.lexicon.lexicon – A module for maintaining and using word and pronunciation collections.

Next topic

onyx.signalprocessing.cepstrum – Cepstral calculation.

This Page

Signal Processing

onyx.signalprocessing – Signal Processing

This package supports a wide variety of signal processing objects.

onyx.signalprocessing.msec2nsec(msec)

Convert a numerical value with units of milliseconds to the corresponding value with units of nanoseconds.

>>> msec2nsec(25)
25000000
onyx.signalprocessing.rate2nsec(sample_rate)

Convert a sample rate in Hertz (sec^-1) into the sample period in nanoseconds

>>> rate2nsec(8000)
125000
class onyx.signalprocessing.sigprocbase(options=None)

Bases: onyx.dataflow.processor, onyx.containers.serializable.Serializable

Baseclass for signal processing objects that adhere to string, list, or dict constructor options.

>>> def printit(spobj):
...   for key in sorted(spobj.init_options.iterkeys()):
...     print key, ':', spobj.init_options[key]
...   print spobj.init_args

String initialization:

>>> obj = sigprocbase('foo=23 bar=update 23 56 75')
>>> printit(obj)
bar : update
foo : 23
['23', '56', '75']

List-of-string initialization:

>>> obj = sigprocbase(['foo=44', 'bar=reset', 'period=2300*usec', '19', '45', 'attack-decay'])
>>> printit(obj)
bar : reset
foo : 44
period : 2300*usec
['19', '45', 'attack-decay']

Dict initialization:

>>> obj = sigprocbase({'3dB': '1500*hz'})
>>> printit(obj)
3dB : 1500*hz
[]
>>> obj
sigprocbase({'3dB': '1500*hz'})

Subclass with defaults and then a string-based override example:

>>> class myfilter(sigprocbase):
...   def __init__(self, options=None):
...     self.init_options = attrdict({'cutoff': '25*hz', 'slope': '50*dB/oct'})
...     super(myfilter, self).__init__(options)
>>> printit(myfilter())
cutoff : 25*hz
slope : 50*dB/oct
[]
>>> printit(myfilter('cutoff=50hz foo'))
cutoff : 50hz
slope : 50*dB/oct
['foo']
>>> obj = sigprocbase(23)
Traceback (most recent call last):
   ...
ValueError: expected options to be an instance of str, tuple, list, or dict, but got 'int'
>>> sigprocbase().configure()
Traceback (most recent call last):
  ...
  File "<doctest __main__.sigprocbase[12]>", line 1, in <module>
    sigprocbase().configure()
  File "<stdin>", line 110, in configure
NotImplementedError: subclass must override this method

Updates self.init_options dictionary with option values, creating the dictionary if it doesn’t exist.

check_serial_version(version)
configure(**kwargs)
get_serial_factory_args()
get_serial_factory_name()
get_serial_module_name()
get_serial_version()
process_one(item)
process_some(items)

Process each of the elements of ‘items’. Return a list of results.

send_many(inputs)
serialize()

Return a serialized version of this object as a tuple of strings. The form of the tuple is: (module_name, factory_name, version, arg0, arg1, ...) where the version and the args will be passed to the factory to construct the object.