Miscellaneous¶
Tools for 2nd order systems¶
A collection of modules and methods that are used throughout the whole package. Methods specialized for second order dynamic systems, such as the ones used for high-class accelerometers.
-
PyDynamic.misc.SecondOrderSystem.
sos_FreqResp
(S, d, f0, freqs)[source]¶ Calculation of the system frequency response
The frequency response is calculated from the continuous physical model of a second order system given by
\(H(f) = \frac{4S\pi^2f_0^2}{(2\pi f_0)^2 + 2jd(2\pi f_0)f - f^2}\)
If the provided system parameters are vectors then \(H(f)\) is calculated for each set of parameters. This is helpful for Monte Carlo simulations by using draws from the model parameters
Parameters: - S (float or ndarray shape (K,)) – static gain
- d (float or ndarray shape (K,)) – damping parameter
- f0 (float or ndarray shape (K,)) – resonance frequency
- freqs (ndarray shape (N,)) – frequencies at which to calculate the freq response
Returns: H – complex frequency response values
Return type: ndarray shape (N,) or ndarray shape (N,K)
-
PyDynamic.misc.SecondOrderSystem.
sos_phys2filter
(S, d, f0)[source]¶ Calculation of continuous filter coefficients from physical parameters.
If the provided system parameters are vectors then the filter coefficients are calculated for each set of parameters. This is helpful for Monte Carlo simulations by using draws from the model parameters
Parameters: - S (float) – static gain
- d (float) – damping parameter
- f0 (float) – resonance frequency
Returns: b,a – analogue filter coefficients
Return type: ndarray
-
PyDynamic.misc.SecondOrderSystem.
sos_absphase
(S, d, f0, uS, ud, uf0, f, runs=10000)[source]¶ Propagation of uncertainty from physical parameters to real and imaginary part of system’s transfer function using GUM S2 Monte Carlo.
Parameters: - S (float) – static gain
- d (float) – damping
- f0 (float) – resonance frequency
- uS (float) – uncertainty associated with static gain
- ud (float) – uncertainty associated with damping
- uf0 (float) – uncertainty associated with resonance frequency
- f (ndarray, shape (N,)) – frequency values at which to calculate amplitue and phase
Returns: - Hmean (ndarray, shape (N,)) – best estimate of complex frequency response values
- Hcov (ndarray, shape (2N,2N)) – covariance matrix [ [u(abs,abs), u(abs,phase)], [u(phase,abs), u(phase,phase)] ]
-
PyDynamic.misc.SecondOrderSystem.
sos_realimag
(S, d, f0, uS, ud, uf0, f, runs=10000)[source]¶ Propagation of uncertainty from physical parameters to real and imaginary part of system’s transfer function using GUM S2 Monte Carlo.
Parameters: - S (float) – static gain
- d (float) – damping
- f0 (float) – resonance frequency
- uS (float) – uncertainty associated with static gain
- ud (float) – uncertainty associated with damping
- uf0 (float) – uncertainty associated with resonance frequency
- f (ndarray, shape (N,)) – frequency values at which to calculate real and imaginary part
Returns: - Hmean (ndarray, shape (N,)) – best estimate of complex frequency response values
- Hcov (ndarray, shape (2N,2N)) – covariance matrix [ [u(real,real), u(real,imag)], [u(imag,real), u(imag,imag)] ]
Tools for digital filters¶
A collection of methods which are related to filter design.
-
PyDynamic.misc.filterstuff.
grpdelay
(b, a, Fs, nfft=512)[source]¶ Calculation of the group delay of a digital filter
Parameters: - b (ndarray) – IIR filter numerator coefficients
- a (ndarray) – IIR filter denominator coefficients
- Fs (float) – sampling frequency of the filter
- nfft (int) – number of FFT bins
Returns: - group_delay (np.ndarray) – group delay values
- frequencies (ndarray) – frequencies at which the group delay is calculated
References * Smith, online book [Smith]
-
PyDynamic.misc.filterstuff.
kaiser_lowpass
(L, fcut, Fs, beta=8.0)[source]¶ Design of a FIR lowpass filter using the window technique with a Kaiser window.
This a filter type which is often used as an FIR low-pass filter due to its linear phase.
Parameters: - L (int) – filter order (window length)
- fcut (float) – desired cut-off frequency
- Fs (float) – sampling frequency
- beta (float) – scaling parameter for the Kaiser window
Returns: - blow (ndarray) – FIR filter coefficients
- shift (int) – delay of the filter (in samples)
-
PyDynamic.misc.filterstuff.
isstable
(b, a, ftype='digital')[source]¶ Determine whether IIR filter (b,a) is stable
Parameters: - b (ndarray) – filter numerator coefficients
- a (ndarray) – filter denominator coefficients
- ftype (string) – type of filter (digital or analog)
Returns: stable – whether filter is stable or not
Return type: bool
-
PyDynamic.misc.filterstuff.
savitzky_golay
(y, window_size, order, deriv=0, rate=1)[source]¶ Smooth (and optionally differentiate) data with a Savitzky-Golay filter.
The Savitzky-Golay filter removes high frequency noise from data. It has the advantage of preserving the original shape and features of the signal better than other types of filtering approaches, such as moving averages techniques.
Source obtained from scipy cookbook (online), downloaded 2013-09-13
Parameters: - y (ndarray, shape (N,)) – the values of the time history of the signal
- window_size (int) – the length of the window. Must be an odd integer number
- order (int) – the order of the polynomial used in the filtering. Must be less then window_size - 1.
- deriv (int) – the order of the derivative to compute (default = 0 means only smoothing)
Returns: ys – the smoothed signal (or it’s n-th derivative).
Return type: ndarray, shape (N,)
Notes
The Savitzky-Golay is a type of low-pass filter, particularly suited for smoothing noisy data. The main idea behind this approach is to make for each point a least-square fit with a polynomial of high order over a odd-sized window centered at the point.
References
- Savitzky et al. [Savitzky]
- Numerical Recipes [NumRec]
Test signals¶
-
PyDynamic.misc.testsignals.
shocklikeGaussian
(time, t0, m0, sigma, noise=0.0)[source]¶ Generates a signal that resembles a shock excitation as a Gaussian followed by a smaller Gaussian of opposite sign.
Parameters: - time (np.ndarray) – time instants (equidistant)
- t0 (float) – time instant of signal maximum
- m0 (float) – signal maximum
- sigma (float) – std of main pulse
- noise (float, optional) – std of simulated signal noise
Returns: x – signal amplitudes at time instants
Return type: np.ndarray
-
PyDynamic.misc.testsignals.
GaussianPulse
(time, t0, m0, sigma, noise=0.0)[source]¶ Generates a Gaussian pulse at t0 with height m0 and std sigma
Parameters: - time (np.ndarray) – time instants (equidistant)
- t0 (float) – time instant of signal maximum
- m0 (float) – signal maximum
- sigma (float) – std of pulse
- noise (float, optional) – std of simulated signal noise
Returns: x – signal amplitudes at time instants
Return type: np.ndarray
-
PyDynamic.misc.testsignals.
rect
(time, t0, t1, height=1, noise=0.0)[source]¶ Rectangular signal of given height and width t1-t0
Parameters: - time (np.ndarray) – time instants (equidistant)
- t0 (float) – time instant of rect lhs
- t1 (float) – time instant of rect rhs
- height (float) – signal maximum
- noise (float, optional) – std of simulated signal noise
Returns: x – signal amplitudes at time instants
Return type: np.ndarray
-
PyDynamic.misc.testsignals.
squarepulse
(time, height, numpulse=4, noise=0.0)[source]¶ Generates a series of rect functions to represent a square pulse signal
Parameters: - time (np.ndarray) – time instants
- height (float) – height of the rectangular pulses
- numpulse (int) – number of pulses
- noise (float, optional) – std of simulated signal noise
Returns: x – signal amplitude at time instants
Return type: np.ndarray