Math Utilities
Useful math functions for LWA work
-
lsl.misc.mathutil.regrid(x, y, newx, allow_extrapolation=False, method='spline')
Regrid data from x,y onto newx. If allow_extrapolation is True,
extrapolation is attempted if the method supports it. Supported
methods are:
Use of this function may require the scipy extension package.
-
lsl.misc.mathutil.downsample(vector, factor, rescale=True)
- Downsample (i.e. co-add consecutive numbers) a vector by an integer
factor. Trims the input timeseries to be a multiple of the downsample
factor, if needed. If rescale == True, then divides each sum by factor
to produce a mean value, otherwise just adds the values in the vector.
-
lsl.misc.mathutil.smooth(x, window_len=10, window='hanning')
Smooth the data using a window with requested size. Stolen from SciPy
Cookbook at http://www.scipy.org/Cookbook/SignalSmooth
This method is based on the convolution of a scaled window with the signal.
The signal is prepared by introducing reflected copies of the signal
(with the window size) in both ends so that transient parts are minimized
in the begining and end part of the output signal.
- Input:
- x: the input signal
- window_len: the dimension of the smoothing window
- window: the type of window from ‘flat’, ‘hanning’, ‘hamming’, ‘bartlett’, ‘blackman’
flat window will produce a moving average smoothing.
- Output:
-
- Example:
>>> from numpy import *
>>> t=linspace(-2,2,0.1)
>>> x=sin(t)+randn(len(t))*0.1
>>> y=smooth(x)
See also
numpy.hanning, numpy.hamming, numpy.bartlett, numpy.blackman, numpy.convolve
scipy.signal.lfilter
TODO: the window parameter could be the window itself if an array instead of a string
-
lsl.misc.mathutil.cmagnitude(cmplx)
- Return the polar magnitudes of complex values.
-
lsl.misc.mathutil.cphase(cmplx)
Return the polar phases of complex values as radians.
-
lsl.misc.mathutil.cpolar(cmplx)
- Return the polar (magnitude, phase) representation of complex
values (real, imaginary). The return value is an array of shape (N,2),
where N is the length of the cmplx input array.
-
lsl.misc.mathutil.crect(cmplx)
- Return the rectilinear (real, imaginary) representation of complex
values (magnitude, phase).
-
lsl.misc.mathutil.creal(cmplx)
- Return the real rectilinear component from complex values
expressed in polar form (magnitude, phase).
-
lsl.misc.mathutil.cimag(cmplx)
- Return the imaginary rectilinear component from complex values
expressed in polar form (magnitude, phase).
-
lsl.misc.mathutil.to_dB(factor)
- Convert from linear units to decibels.
-
lsl.misc.mathutil.from_dB(dB)
- Convert from decibels to linear units.
-
lsl.misc.mathutil.robustmean(arr)
Take the robust mean of an array, normally a small section of a
spectrum, over which the mean can be assumed to be constant. Makes two
passes discarding outliers >3 sigma ABOVE (not below) the mean.