This program essentially copies the pwelch
function from MATLAB. It will:
- Remove mean from signal.
- Apply a Hanning window.
- Compute a Cooley-Tukey FFT on an n-length sample, where
n
is the power of 2 that results in the closest possible window to 1 second. - Compute the PSD up to the Nyquist frequency of the signal.
- Convert to 1/6-octave band (1/3 and 1/6 OB are by convention in vibration analysis).
- Compute a final envelope for the entire signal.
My sample time series were free and came from Mide, whose blog also provides a great into to vibration analysis.
My PSD and scale factor calculation came from equation 23 of this paper.
Modify the file path in your main.rs
to point to a CSV file with time in the first column and signal in the second. This program makes the following assumptions:
- Time is in seconds and all points are evenly spaced.
- Signal is stochastic and stationary.
- Data has been cleaned (viz, all time points have a corresponding signal point that can be read as an
f64
). - Signal is in unit acceleration (g), although this is mostly related to plots.
cargo build --release
cargo run --release
The --release
build will run significantly faster than the debug build.
- Make this a Parity Substrate off-chain worker.
- Change this to a library that accepts a
Vec<_>
and returns the envelope. - Add traits to allow more input types.
- Add more error handling (e.g. if signal contains
NaN
values). - Add more features (e.g. input different units, plot options, window options).
- Implement FFT algorithms that accept non-power-of-two signal lengths.
- Performance comparisons against Python, MATLAB, etc.
This has not been peer-reviewed at all. I have compared FFT results to other libraries and compared time-based and PSD-based RMS results, and everything looks reasonable. However, this was much more about learning more Rust and eventually integrating into Substrate as a demo.