Introduction
Determination of the life of a mechanical system subject to vibrational loading is often of critical importance. One source of vibrational loading is due to vehicle transport on a bumpy road. To simulate a transportation cycle, which may last for hours or even days, one must utilize a statistical method, leading to the necessity of conducting a random vibration analysis (RV), which requires a power spectral density (PSD) of a given time-series of the load profile, which is often displacement, velocity or acceleration; industry and government standards often provide PSDs for loads that a mechanical system must withstand. However, it is often desirable to convert lab-generated time-series data to a PSD for a proprietary RV analysis. In this article, we will see how to compute a PSD for time-series data using Python; and we will compute the same PSD in nCode in order to verify the accuracy of the Python result.
Time-series Dataset
The exemplar time-series dataset that we will use is that of acceleration (in g's) versus time (in seconds). The sampling rate of the signal occurs at 4 kHz for a duration of slightly over 4 secs. The plot of the time-series is shown here:
Power Spectral Density (PSD)
An explanation of how a PSD is defined for continuous time signals is available here. For discrete signals, such as those that are obtained by sampling in industrial applications, the PSD is typically estimated using the Welch's method, where the time-series is divided into overlapping segments (frames) of a chosen size, for which the PSD is calculated, followed by an averaging process.
The process of selecting segments from the signal is called windowing. Depending on the window type, effects of spectral leakage can be minimized, thus producing a more accurate PSD estimate. Discussion of the many types of windows is beyond the scope of this article. However, we will utilize the hamming window as it reduces spectral leakage well.
Finally, the choice of segment size and overlap affects the accuracy and smoothness of the PSD. It is often required to use trial-and-error to obtain a good PSD estimate. Here, we will explore an adaptive method that adjusts the segment length automatically based on signal properties.
PSD Computation Using Python
The process of computing the PSD in Python requires only a few functions from SciPy.Signal and NumPy. On top of those, we import Matplotlib for plotting and Pandas for data management.
Functions for Adaptive and Hamming Windows PSD Calculations
The following two user-defined functions, based on code from here, provides methods of computing adaptive and hamming window PSDs. Note that the adaptive PSD estimator using the default (Hanning, different from hamming) window:
Read in Time-series and Compute PSD
The time-series CSV file has a specific format in order to work for both Python and nCode import, where the first row contains variable names, and the second row contains units:
The code to read in the file, run adaptive, hamming window and manual PSD calculations is shown here:
After running these functions and plotting them, the three resulting PSDs align very well:
Note that for a real-world dataset, curves as smooth as these may require several iterations on segment (frame) size and window choice.
PSD Computation using nCode
Now, we will verify the Python PSD result using a corresponding calculation in nCode DesignLife. The nCode workspace is displayed here:
As seen from the graph in the upper right corner, we have achieved the same PSD in nCode as in Python. The settings for the FrequencySpectrum and HistogramManipulation glyphs are shown here:
![]() |
![]() |
Notice that the WindowType and BufferSize settings match those in Python, thus resulting in the two PSDs being virtually identical; the Python PSD image is repeated here for ease of comparison:
![]() |
![]() |
Conclusion
In conclusion, using standard Python libraries, one may very easily compute the PSD for time-series data, requisite input for random vibration analyses. Finally, computing the PSD in Python was verified by computing the same PSD in nCode.
Downloadable Resources
- Python 3.13 script and example dataset
- Ansys 2025 R2 Workbench archive containing nCode DesignLife system
Ozen Engineering Expertise
Ozen Engineering Inc. leverages its extensive consulting expertise in CFD, FEA, optics, photonics, and electromagnetic simulations to achieve exceptional results across various engineering projects, addressing complex challenges such as antenna design, signal integrity, electromagnetic interference (EMI), and electric motor analysis using Ansys software.
We offer support, mentoring, and consulting services to enhance the performance and reliability of your electronics systems. Trust our proven track record to accelerate projects, optimize performance, and deliver high-quality, cost-effective results. For more information, please visit https://ozeninc.com.
If you want to learn more about our consulting services, please visit: https://www.ozeninc.com/consulting/
CFD: https://www.ozeninc.com/consulting/cfd-consulting/
FEA: https://www.ozeninc.com/consulting/fea-consulting/
Optics: https://www.ozeninc.com/consulting/optics-photonics/
Photonics: https://www.ozeninc.com/consulting/optics-photonics/
Electromagnetic Simulations: https://www.ozeninc.com/consulting/electromagnetic-consulting/
Thermal Analysis & Electronics Cooling: https://www.ozeninc.com/consulting/thermal-engineering-electronics-cooling/
Tags:
Python, FEA, linear Dynamics, Transient Structural Analysis, ANSYS Mechanical, nCode, DesignLifeSep 5, 2025 12:12:36 PM