Python Time History Descriptive Statistics

Time History Descriptive Statistics

Utility

The scripts on this page require the utility module tompy.py

* * *

Statistics & Histogram

The descriptive statistics for a time history may be calculated using: signal_statistics.py

The output includes the mean, standard deviation, RMS, skewness, kurtosis, maximum, minimum and histogram.

The script also checks the time step and sample rate.

* * *

Tom Irvine

Python Signal Generation

The script generate.py outputs time histories for:

  • sine
  • cosine
  • damped sine
  • sine sweep
  • white noise
  • terminal sawtooth pulse
  • symmetric sawtooth pulse
  • half-sine pulse
  • versed sine pulse
  • wavelet
  • rectangular pulse

The script requires the utility function tompy.py

The time histories have many different uses. One is to test signal processing scripts.

Another is for use as a base input or forcing function in a structural dynamics model, particularly for a modal transient analysis.

* * *

Tom Irvine

Python Shock Response Spectrum

Introduction

Mechanical shock pulses are often analyzed in terms of shock response spectra (SRS). The shock response spectrum assumes that the shock pulse is applied as a common base input to an array of independent single-degree-of-freedom systems. The shock response spectrum gives the peak response of each system with respect to the natural frequency. Damping is typically fixed at a constant value, such as 5%, which is equivalent to an amplification factor of Q=10.

The following tutorial gives further information: srs_intr.pdf

* * *

Utility

The scripts on this page require the utility module tompy.py

* * *

Arbitrary Base Input – SRS Calculation

The SRS for an an arbitrary base input can be calculated via a digital recursive filtering relationship, which models the convolution integral.

The filtering relationship can be implemented in Python by importing the lfilter function from scipy.

from scipy.signal import lfilter

A script for doing this is given at: srs.py

A version for calculating and plotting the SRS in tripartite format is given at: srs_tripartite.py

A script for calculating the SRS via a convolution integral is given at: srs_conv.py

* * *

Arbitrary Base Input – SRS Calculation – GUI Version

A GUI version written using Tkinter is given at srs_gui.py

* * *

Arbitrary Base Input – Time Domain Response for a given SDOF System

Digital recursive filtering relationship method: arbit.py

GUI version using Tkinter: arbit_gui.py

Runge-Kutta fourth order method (for non-stiff systems): arbit_rk4.py

* * *

Half-sine Pulse

The response of an SDOF system to a half-sine base input can be calculated via a Laplace transform which yields a closed-form solution, as shown in sbase.pdf

A script is given at: half_sine_base.py

Note that the peak response may occur either during or after the half-sine pulse depending on the pulse duration, natural frequency, and damping ratio.

* * *

Terminal Sawtooth Pulse

The response of an SDOF system to a terminal sawtooth base input can also be calculated via a Laplace transform. terminal_sawtooth.pdf

A script is given at: terminal_sawtooth_base.py

* * *

Multi-pulse GUI

Here is a GUI for classical pulses which uses Tkinter: classical_base_gui.py

* * *

Fortran

A Fortran SRS program is given at: QSRS.F

* * *

Arbitrary Applied Force – Time Domain Response for a given SDOF System

A script for the response to an applied force is given at: arbit_force.py

* * *

External References

Vibrationdata SRS Page

Vibrationdata Blog SRS

Python Cross Power Spectral Density

Utilities

The scripts on this page require the utility module: tompy.py

* * *

Main Script

This script calculates the cross power spectral density of two signals: cross_psd.py

The script has an option to sub-divide the data into segments and then take an ensemble average. This tends to smooth the resulting magnitude and phase curves, but the spectral frequency resolution is widened as a trade-off.

The script also calculate the coherence function.

This method is best-suited for stationary data.

* * *

Alternate Script

Here is an alternate script set that calculates the cross spectral density as a single record using the entire signal.

This method would be appropriate for the case of transient pulses: CPSD_from_fourier.py

* * *

– Tom Irvine

Python Power Spectral Density

Utilities

The scripts on this page require the utility modules

tompy.py

signal_utilities.py

* * *

PSD of a Time History

The PSD of a time history may be calculated using psd.py

The psd.py script uses the FFT function.

from scipy.fftpack import fft

It includes options for retangular and Hanning windows.

A GUI version which uses Tkinter is given at: psd_gui.py

* * *

Spectrogram PSD

A script for a spectrogram PSD of a time history is given at: spectrogram.py

The script uses the Matplotlib function specgram.

This function is useful for tracking the frequency change with time.

* * *

Overall GRMS Level

The overall GRMS level for a PSD function can be calculated via: psdint.py

* * *

Synthesize a Time History to Satisfy a Specified PSD

A sample time history can be synthesized via: psd_syn.py

This script also requires: velox_correction.py

Note that a given PSD does not have a unique time history, because it discards the phase angle.

* * *

SDOF Response

This script calculates the response of a single-degree-of-freedom system to an acceleration PSD base input: sdof_ran.py

The method is more accurate than Miles equation, because it performs a point-by-point multiplication of the power transmissibility function times the base input PSD. It thus allows the PSD to vary with frequency.

This script calculates the vibration response spectrum (VRS) for a PSD base input: vrs.py

* * *
– Tom Irvine

Python Fourier Transform, FFT, Waterfall FFT, Cepstrum

Introduction

The Fourier transform is a method for representing a time domain signal in the frequency domain. This transform is discussed in the tutorial: Shock_and_Vibration_Signal_Analysis.pdf

* * *

Utility

The scripts on this page require the utility module tompy.py

* * *

Fourier Transform

An example of a Fourier transform script is fourier.py

The corresponding inverse Fourier transform script is invfourier.py

* * *

Fast Fourier Transform (FFT)

The processing time for taking the transform of a long time history can be dramatically decreased by using an FFT.

An FFT can be performed if the time history has 2^n coordinate points, where n is an integer. A time history can be truncated or zero-padded if necessary so that it meets this requirement.

Scipy has an FFT in its numerical library.

from scipy.fftpack import fft

An example of a script using this function is: fft.py

The corresponding inverse FFT script is: invfft.py

An FFT GUI version is given at: fft_gui.py

* * *

Waterfall FFT

The Waterfall script generates a 3D plot using:

from mpl_toolkits.mplot3d.art3d import Poly3DCollection

The script is: waterfall_FFT.py

A GUI version using Tkinter is: waterfall_FFT_gui.py

* * *

Cepstrum

The cepstrum function was originally developed for characterizing the seismic echoes resulting from earthquake and bomb explosions. It has also been used to determine the fundamental frequency of human speech, to analyze radar signal returns, and to evaluate machinery vibration.

Here is a cepstrum script: cepstrum.py

Here is a auto-cepstrum script: auto_cepstrum.py

Here is a GUI script for both cepstrum & auto-cepstrum: cepstrum_gui.py

* * *

Sound Pressure Level

Here is a GUI script for calculating a sound pressure level from a time history: spl_gui.py

* * *

Tom Irvine

Python Signal Analysis Package GUI

Here is a signal analysis package GUI written using Tkinter: vibrationdata_gui_python.zip

It is compatible with Python versions 2.7 to 3.3, and hopefully future 3.x versions.

vibrationdata.py is the main script.

The remaining scripts are supporting functions.

These scripts demonstrate the use of multiple windows.

* * *

The following signal analysis functions are currently available:

Statistics
Trend Removal & Scaling
Butterworth Filter
Bessel Filter
Fourier Transform
Fast Fourier Transform (FFT)
Waterfall FFT
Power Spectral Density (PSD)
SDOF Response to Base Input
Shock Response Spectrum (SRS)
Rainflow Cycle Counting
Differentiate Time History
Integrate Time History
Autocorrelation
Cross-correlation
Cepstrum & Auto Cepstrum
Sound Pressure Level (SPL)

The following PSD functions are also available:

Overall GRMS
SDOF Response to Base Input PSD
Vibration Response Spectrum (VRS)

The following miscellaneous functions are also available:

Sine Amplitude Conversion
SDOF Response: Peak Sigma for Random Base Input
SDOF Response to Classical Pulse Base Input

More will be added in future revisions…

* * *

– Tom Irvine

Python Digital Filtering

Utilities

The scripts on this page require the utility modules

tompy.py
signal_utilities.py

* * *

Butterworth Sixth-order Filter

The filtering relationship can be implemented in Python by importing the lfilter function from scipy.

from scipy.signal import lfilter

A script is given at filter.py

A GUI script using Tkinter is given at: Butterworth_filter_gui.py

See also: Butterworth Filter Blog Post

* * *

Bessel Two-pole Lowpass Filter

A script is given at  Bessel_lowpass_filter.py

See also: Bessel Filter Blog Post

* * *

Mean Filter

A script is given at mean_filter.py

* * *

– Tom Irvine