fonsim.wave package

Submodules

fonsim.wave.custom module

Class CustomWave

2020, September 5

class fonsim.wave.custom.Custom(wave_array, time_notation='absolute', kind='previous')[source]

Bases: object

Custom wave

The argument for wave_array should be a 2D-indexable array-like object (List, Tuple, numpy.ndarray, etc.) and contain the time values and the corresponding output values. One dimension should have size two. The function is transpose-agnostic.

The argument for time_notation can be ‘absolute’ or ‘relative’. In case of relative, each time value is relative to the one before it.

The default argument ‘previous’ for ‘kind’ results in a rectangular wave (zero-order interpolation). The interpolation is handled using the Scipy method scipy.interpolate.interp1d and the available interpolation kinds therefore are those supported by this Scipy method. For a complete reference, see https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html. From above site (copied 2020, September 5):

Specifies the kind of interpolation as a string (‘linear’, ‘nearest’, ‘zero’, ‘slinear’, ‘quadratic’, ‘cubic’, ‘previous’, ‘next’, where ‘zero’, ‘slinear’, ‘quadratic’ and ‘cubic’ refer to a spline interpolation of zeroth, first, second or third order; ‘previous’ and ‘next’ simply return the previous or next value of the point) or as an integer specifying the order of the spline interpolator to use.

To readout the value (and therefore call the interpolation function), call the created object.

Example:

import fonsim

# Create Custom wave object
# times: 0.0, 1.0, 1.5 and values: 12, 18, 15
wave_array = [[0.0, 12], [1.0, 18], [1.5, 15]]
mywave = fonsim.wave.custom.Custom(wave_array, time_notation='absolute', kind='previous')

# Read it out by calling the object
y = mywave(1.2)  # y = array(18.)
Parameters
  • wave_array – indexable object, shape 2 x N or N x 2

  • time_notation – ‘absolute’ or ‘relative’

  • kind – interpolation kind

fonsim.wave.custom.isincreasing(arr)[source]

Helper function. Returns True if array strictly increasing, False otherwise.

fonsim.wave.wave module

Wave generator functionality.

Available wave functions:
  • square

  • sine

  • triangular

  • sawtooth

The input range is [0, 2*pi] and output range is [-1, 1]. These functions are static and thus can be placed outside of the class definition.

Other functionality:
  • Function time_to_angle: conversion elapsed time -> angle

  • Function wave_custom: for custom waves

2020, September 5

fonsim.wave.wave.sawtooth(angle)[source]
fonsim.wave.wave.sine(angle)[source]
fonsim.wave.wave.square(angle)[source]
fonsim.wave.wave.time_to_angle(time, frequency, phase=0)[source]

Convert an elapsed time to an angle. Designed to be used with the wave functions that take an anle as input.

Equation:

angle = ((time · frequency + phase/(2·pi)) % 1) · 2·pi
Parameters
  • time – elapsed time, in s

  • frequency – frequency, in Hz

  • phase – phase offset, in radians

Returns

angle, in radians

fonsim.wave.wave.triangle(angle)[source]
fonsim.wave.wave.unity(angle)[source]

Module contents

2020, September 18