The Matlab function 'tsa' allows to compute the phase-average of a signal with varying cycles length.
As an avid user of this Matlab function, I was frustrated not to find an equivalent with Python.
Time-domain method (pyTSA_TimeDomain function):
- Divide the signal into segments corresponding to the different cycles
- Interpolate the signals in each segment on the same number of samples
- Compute the average of all the resampled segments
Frequency-domain method (py_TSA_fft function):
- Divide the signal into segments corresponding to the different cycles
- Compute the fft of each segment
- Truncate the results on each segment so that all fft have the same length as the one of the shortest cycle
- Average all the spectra
- Compute the inverse fft to obtain the phase-averaged signal in the time domain.
The code 'pyTSA_example.py' presents an example of use of the TSA algorithms for the computation of the time-synchronous average of the position of a fan blade as it slows down after switchoff. This example is inspired by the Matlab example presented in the 'tsa' function help page.
The scipy.signal 'find_peaks' is first used to detect the beginning of each cycle:

The pyTSA module is then tested to compute the phase-averaged position of the the fan blade during one cycle:

Bechhoefer, Eric, and Michael Kingsley. "A Review of Time-Synchronous Average Algorithms." Proceedings of the Annual Conference of the Prognostics and Health Management Society, San Diego, CA, September-October, 2009.