MideTechnology / endaq-python

A comprehensive, user-centric Python API for working with enDAQ data and devices
MIT License
25 stars 12 forks source link

remove numerical instability in `shock_spectrum` for `damp` values near zero #182

Open CrepeGoat opened 2 years ago

CrepeGoat commented 2 years ago

The coefficient generation functions are written to perform the verbatim calculations described in ISO 18431-4. These formulas are written in terms of the quality factor Q, which is related to the damping coefficient: ζ = 1 / (2Q) -> Q = 1 / (2ζ) Notably, the damping coefficient can take any value in the range ζ ∈ [0, 1], which means the quality factor lies in the infinite range Q ∈ [1/2, ∞], which can exhibit numerical instabilities in the higher value range, i.e., when ζ -> 0.

However, because these formulas exclusively use Q as an inverted factor (1 / Q), the equations could be equivalently expressed in terms of the damping coefficient (1 / Q) = 2ζ, which would remove the numerical instabilities from computations involving near-infinite-valued Q. This would make our shock_spectrum calculations more resilient to numerical errors in the (admittedly uncommon) use case where ζ -> 0.

pscheidler commented 2 years ago

It looks like damping is always set as named parameter (not sure if that's the right term, but you need to call endaq.calc.shock.shock_spectrum(accel, damp=0.05). So it seems safe if you can add a named parameter for quality, have it override damp if it is explicitly set. Not sure if you can check if the user explicitly sets damp, but it would be great to have a deprecation warning if they do.