# A Fault Detection Framework for Rotating Machinery with a Spectrogram and Convolutional Autoencoder
## 3 Proposed Framework
### Short-Time Fourier Transform (STFT)  
To derive the frequency information from raw time-domain signals, Fourier transform-based techniques can be adopted [60; 61; 62]. Among these Fourier transform-based techniques, a short-time Fourier transform (STFT) can be used to deal with the nonstationary signals. The STFT is the most widely used signal processing method for nonstationary signal analysis by capturing localized frequency properties from the signal. The STFT procedure is depicted in Figure 2. The STFT method first divides the signal into smaller consecutive segments, assuming that the signal might be locally stationary within a short time interval. However, the discontinuity at either end point of a split signal may result in the spectral leakage problem, in which the power at one frequency component erroneously leaks into other frequency components [63].  
To address the spectral leakage problem, adjacent signal segments should be continuous at their end points, and thus each signal segment is multiplied with a nonzero window function whose value changes gradually toward zero at the end points. Subsequently, fast Fourier transformation (FFT) is applied to each windowed segment, and thereby, the power spectrum of each windowed segment is obtained.  
Figure 2: An illustration of the STFT procedure.  
The power spectrum is a representation of the power distribution across frequency components present within a windowed segment, referred to as power spectral density (PSD), and the set of spectrums of all segments comprises a spectrogram. Thus, the spectrogram provides time-frequency representation, which displays the changing patterns of frequency components over time. To this end, we firstly transform raw time-domain signals into the spectrogram by using the STFT. The continuous time signal \(x(t)\) can be transformed into a spectrum component of time \(t\) and frequency \(f\) pairs, \(STFT_{x}(t\prime)\), as follows:  
\[STFT_{x}(t,\ f)=\int_{-\infty}^{\infty}x(\tau)h(\tau-t)^{*}e^{-j2\pi ft}d\tau, \tag{1}\]  
where \(x(\tau)\) is the signal to be analyzed and \(h(\tau-t)\) is a nonzero window function sliding over time. As for the nonzero window function, we used the Hann window function in order to mitigate the spectral leakage problem. The Hann window function, \(h(t)\), is defined as follows:  
\[h(t)=0.5-0.5\text{cos}\left(\frac{2\pi t}{M-1}\right),\ 0\leq t\leq M-1, \tag{2}\]  
where \(M\) denotes the length of the signal to which the window function is applied. Then, the spectrogram is derived by taking the square of \(STFT_{x}(t\prime)\).  
\[Spectrogram_{x}(t,f)=|STFT_{x}(t,\ f)|^{2}=\left|\int_{-\infty}^{\infty}x(\tau )h(\tau-t)e^{-j2\pi/t}d\tau\right|^{2}. \tag{3}\]  
Because the collected raw time-domain signals are not completely continuous, we used the discrete STFT technique. In the discrete STFT, the discrete time signal \(x[n]\) can be transformed into a spectrum component of time point \(n\) and frequency \(f\) pairs, \(STFT_{x}(n\prime f)\), as follows:  
\[STFT_{x}(n,\ f)=\sum_{m=-\infty}^{\infty}x[m]h[m-n]e^{-j2\pi fn}, \tag{4}\]  
where \(x[n]\) is the signal to be analyzed and \(h[m-n]\) is the window function with discrete points. Finally, the spectrogram of the discrete time signal can be obtained as follows:  
\[Spectrogram_{x}(n,f)=|STFT_{x}(n,\ f)|^{2}=\left|\sum_{m=-\infty}^{\infty}x[m ]h[m-n]e^{-j2\pi fn}\right|^{2}. \tag{5}\]  
Once the spectrogram is obtained, features of signals are extracted in the next step. The spectrogram involves information on both time and frequency, and hence, intrinsic features of raw time-domain vibration signals can be more successfully revealed. The spectrogram is represented as two-dimensional image-formatted data, and hence, we adopted the 2D-CAE model to draw meaningful features from the spectrogram in further steps.