This module defines some convenience functions of time.
linear_interp : a Formula for a linearly interpolated function of time
step_function : a Formula for a step function of time
events : a convenience function to generate sums of events
blocks : a convenience function to generate sums of blocks
convolve_functions : numerically convolve two functions of time
fourier_basis : a convenience function to generate a Fourier basis
Convolve fn1 with fn2.
| Parameters: | fn1 : sympy expr
fn2 : sympy expr
interval : [float, float]
dt : float
padding_f : float, optional
name : None or str, optional
|
|---|---|
| Returns: | f : sympy expr
|
Examples
>>> import sympy
>>> t = sympy.Symbol('t')
>>> # This is a square wave on [0,1]
>>> f1 = (t > 0) * (t < 1)
>>> # The convolution of with itself is a triangular wave on [0,2], peaking at 1 with height 1
>>> tri = convolve_functions(f1, f1, [0,2], 1.0e-03, name='conv')
>>> print tri
conv(t)
>>> ftri = vectorize(tri)
>>> x = np.linspace(0,2,11)
>>> y = ftri(x)
>>> # This is the resulting y-value (which seem to be numerically off by dt
>>> y
array([ -3.90255908e-16, 1.99000000e-01, 3.99000000e-01,
5.99000000e-01, 7.99000000e-01, 9.99000000e-01,
7.99000000e-01, 5.99000000e-01, 3.99000000e-01,
1.99000000e-01, 6.74679706e-16])
>>>
Return a sum of functions based on a sequence of times.
| Parameters: | times : sequence
amplitudes : None or sequence length $N$, optional
f : sympy.Function, optional
g : sympy.Basic, optional
|
|---|---|
| Returns: | sum_expression : Sympy.Add
|
Examples
>>> events([3,6,9])
DiracDelta(-9 + t) + DiracDelta(-6 + t) + DiracDelta(-3 + t)
>>> h = Symbol('hrf')
>>> events([3,6,9], f=h)
hrf(-9 + t) + hrf(-6 + t) + hrf(-3 + t)
>>> events([3,6,9], amplitudes=[2,1,-1])
-DiracDelta(-9 + t) + 2*DiracDelta(-3 + t) + DiracDelta(-6 + t)
>>> b = [Symbol('b%d' % i, dummy=True) for i in range(3)]
>>> a = Symbol('a')
>>> p = b[0] + b[1]*a + b[2]*a**2
>>> events([3,6,9], amplitudes=[2,1,-1], g=p)
(2*_b1 + 4*_b2 + _b0)*DiracDelta(-3 + t) + (-_b1 + _b0 + _b2)*DiracDelta(-9 + t) + (_b0 + _b1 + _b2)*DiracDelta(-6 + t)
>>> h = Symbol('hrf')
>>> events([3,6,9], amplitudes=[2,1,-1], g=p, f=h)
(2*_b1 + 4*_b2 + _b0)*hrf(-3 + t) + (-_b1 + _b0 + _b2)*hrf(-9 + t) + (_b0 + _b1 + _b2)*hrf(-6 + t)
Formula for Fourier drift, consisting of sine and cosine waves of given frequencies.
| Parameters: | freq : [float]
|
|---|
Examples
>>> f=fourier_basis([1,2,3])
>>> f.terms
array([cos(2*pi*t), sin(2*pi*t), cos(4*pi*t), sin(4*pi*t), cos(6*pi*t),
sin(6*pi*t)], dtype=object)
>>> f.mean
_b0*cos(2*pi*t) + _b1*sin(2*pi*t) + _b2*cos(4*pi*t) + _b3*sin(4*pi*t) + _b4*cos(6*pi*t) + _b5*sin(6*pi*t)
>>>
Linear interpolation function of t given times and values
Imterpolator such that:
f(times[i]) = values[i]
| Parameters: | times : ndarray
values : ndarray
fill : float, optional
name : None or str, optional
**kw : keyword args, optional
|
|---|---|
| Returns: | f : sympy expression
|
Examples
>>> s=linear_interp([0,4,5.],[2.,4,6], bounds_error=False)
>>> tval = np.array([-0.1,0.1,3.9,4.1,5.1]).view(np.dtype([('t', np.float)]))
>>> s.design(tval)
array([(nan,), (2.0499999999999998,), (3.9500000000000002,),
(4.1999999999999993,), (nan,)],
dtype=[('interp0(t)', '<f8')])
Right-continuous step function such that
f(times[i]) = values[i]
| Parameters: | times : ndarray
values : ndarray
fill : float
name : str
|
|---|---|
| Returns: | f : Formula
|
Examples
>>> s=step_function([0,4,5],[2,4,6])
>>> tval = np.array([-0.1,3.9,4.1,5.1]).view(np.dtype([('t', np.float)]))
>>> s.design(tval)
array([(0.0,), (2.0,), (4.0,), (6.0,)],
dtype=[('step0(t)', '<f8')])
>>>