paddlets.analysis.frequency_domain
Implementation of different frequency domain and time-frequency domain analysis operators, including FFT, STFT, CWT.
- class FFT(fs: float = 0, norm: bool = True, half: bool = True, **kwargs)[source]
Bases:
AnalyzerFast Fourier transform (FFT) analysis operator performs FFT on a signal(1-D) to obtain the amplitude spectrum and phase spectrum of the signal at different frequencies.
This operator returns both X and Y coordinates for visual display. Where X represents frequency and Y represents amplitude spectrum or phase spectrum.
- Parameters
fs (float) – The sampling frequency of the signal(default=0), when the fs is not specified, the range of x coordinate defaults to the length of the data. If the data to be analyzed is multiple columns, the default frequency of all columns is the same. If the fs of different columns is different, it is recommended to call this operator separately for each column.
norm (bool) – Whether to normalize the amplitude or phase after FFT transformation, default=True.
half (bool) – Whether to take half of the amplitude or phase after FFT transform(when the signal is a real signal, its frequency domain signal after Fourier transform is symmetrical about the 0-frequency axis), default=True.
kwargs – Other parameters.
- Returns
None
- analyze(X: Union[Series, DataFrame]) DataFrame[source]
Implementation logic of fast Fourier transform analysis operator
- Parameters
X (pd.Series|pd.DataFrame) – X to be analyzed
- Returns
The result of fft, each column to be analyzed returns 3 keys
- Return type
fft_result(DataFrame)
Examples
#Given: X = pd.DataFrame(np.array(range(100)), columns=['a']) #Returns: 1. 'a_x': np.ndarray(1-D), Representative frequency), 2. 'a_amplitude': np.ndarray(1-D), Representative cwt of amplitude spectrum 3. 'a_phase': np.ndarray(1-D), Representative phase spectrum
- Raises
ValueError –
- class STFT(fs: float = 1.0, window: Union[str, Tuple[str], List[str]] = 'hann', nperseg: int = 256, noverlap: Union[None, int] = None, nfft: Union[None, int] = None, detrend: Union[str, bool] = False, return_onesided: bool = True, boundary: Optional[str] = 'zeros', padded: bool = True, axis: int = - 1, **kwargs)[source]
Bases:
AnalyzerShort time Fourier transform (STFT) is used to analyze non-stationary signals because the waveform of non-stationary signal changes irregularly and there is no concept of instantaneous frequency. In this case, the effect of using fast Fourier transform analysis is poor.
In STFT, the windowing mechanism is used to stabilize the signal(truncated in time, so that the waveform does not change significantly in a short time), and then FFT can be used for windowed signal segmentation. STFT obtains the spectrum of n-segment signals arranged in time sequence.
The length of the window determines the time resolution and frequency resolution of the spectrum. The longer the window is, the higher the frequency resolution is, the lower the time resolution is. Conversely, the lower the frequency resolution is, the higher the time resolution is. For time-varying unsteady signals, high frequency is suitable for small windows, and low frequency is suitable for large windows.
In order to improve the time-domain characteristics on the basis of ensuring the frequency-domain characteristics, Often choose to overlap between segments to improve the time-domain analysis ability. However, the more overlapping points will greatly increase the amount of calculation, resulting in low efficiency.
- Parameters
fs (float) – The sampling frequency of the signal(default=1.0). If the data to be analyzed is multiple columns, the default frequency of all columns is the same. If the fs of different columns is different, it is recommended to call this operator separately for each column.
window (str|tuple|array_like) – Desired window to use, default=”hann”.
nperseg (int) – Length of each segment, default=256.
noverlap (None|int) – Number of points to overlap between segments. If None, noverlap = nperseg // 2, default=None
nfft (None|int) – Length of the FFT used, if a zero padded FFT is desired. If None, the FFT length is nperseg, default=None.
detrend (str|function|False) – Specifies how to detrend each segment, default=False.
return_onesided (bool) – If True, return a one-sided spectrum for real data. If False return a two-sided spectrum. default=True.
boundary (None|str) – Specifies whether the input signal is extended at both ends, and how to generate the new values, default=’zeros’.
padded (bool) – Specifies whether the input signal is zero-padded at the end to make the signal fit exactly into an integer number of window segments, default=True.
axis (int) – Axis along which the STFT is computed, default=-1.
kwargs – Other parameters.
For more details about parameters, please refer to: https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.stft.html?highlight=stft#scipy.signal.stft
- Returns
None
- analyze(X: Union[Series, DataFrame]) Dict[source]
Implementation logic of short-time Fourier transform analysis operator
- Parameters
X (pd.Series|pd.DataFrame) – X to be analyzed
- Returns
The result of stft, each column to be analyzed returns 3 keys
- Return type
stft_result(Dict)
Examples
#Given: X = pd.DataFrame(np.array(range(100)), columns=['a']) #Returns: 1. 'a_f': np.ndarray(1-D), Representative frequency 2. 'a_t': np.ndarray(1-D), Representative time 3. 'a_Zxx': np.ndarray(2-D), Representative stft of x
- Raises
ValueError –
- class CWT(scales: int = 64, wavelet: str = 'cgau8', fs: float = 1.0, method: str = 'conv', axis: int = - 1, **kwargs)[source]
Bases:
AnalyzerFast Fourier transform (FFT) can only get the frequency domain information of a signal, and it is impossible to know the frequency information of the signal at different times. Short time Fourier transform (STFT) solves this problem to a certain extent by introducing the windowing mechanism, but the effect of STFT is affected by the size of the window. The window is too small, the frequency resolution is low, the window is too large, and the time resolution is low.
Continuous wavelet transform(CWT) can solve the above problems. It inherits and develops the idea of localization of short-time Fourier transform, and overcomes the shortcomings that the window size does not change with frequency. It can provide a “time-frequency” window that changes with frequency. It is an ideal tool for signal time-frequency analysis and processing.
- Parameters
scales (int) – The wavelet scales to use, It can be set to half the length of the data. It should be noted that when the half of the data is relatively large (such as greater than 1000), the larger wavelet scale will cause the calculation to be more time-consuming and you can change the wavelet scale into a value of 100, 200 or other small number.
wavelet (str) – Wavelet to use, options include [‘cgau1’, ‘cgau2’, ‘cgau3’, ‘cgau4’, ‘cgau5’, ‘cgau6’, ‘cgau7’, ‘cgau8’, ‘cmor’, ‘fbsp’, ‘gaus1’, ‘gaus2’, ‘gaus3’, ‘gaus4’, ‘gaus5’, ‘gaus6’, ‘gaus7’, ‘gaus8’, ‘mexh’, ‘morl’, ‘shan’], default=’cgau8’.
fs (float) – The sampling frequency of the signal(default=1.0). If the data to be analyzed is multiple columns, the default frequency of all columns are considered the same. If the fs of different columns is different, it is recommended to call this operator separately for each column.
method (str) – The method used to compute the CWT, options include [‘conv’, ‘fft’, ‘auto’], default=’conv’.
axis (int) – Axis along which the STFT is computed, default=-1.
kwargs – Other parameters.
For more details about parameters, please refer to: https://pywavelets.readthedocs.io/en/latest/ref/cwt.html?highlight=cwt
- Returns
None
- analyze(X: Union[Series, DataFrame]) Dict[source]
Implementation logic of continuous wavelet transform
- Parameters
X (pd.Series|pd.DataFrame) – X to be analyzed
- Returns
The result of cwt, each column to be analyzed returns 3 keys
- Return type
cwt_result(Dict)
Examples
#Given: X = pd.DataFrame(np.array(range(100)), columns=['a']) #Returns: 1. 'a_t': np.ndarray(1-D), Representative time 2. 'a_coefs': np.ndarray(2-D), Representative cwt of x 3. 'a_frequencies': np.ndarray(1-D), Representative frequency
- Raises
ValueError –