Implement STFT with Hann Windowing (STFT) #22
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Step 7: Applying Short-Time Fourier Transform (STFT)
The code performs STFT on each signal to extract frequency-domain features.
Explanation:
Visual Representation of STFT Output for One Case:
Step 8: Loading STFT Data from CSV Files
The saved STFT data is loaded back into DataFrames for further processing.
Visual Representation:
(Each DataFrame represents the STFT features for one case and one sensor.)
Step 9: Combining STFT DataFrames into Lists
All STFT DataFrames are stored in lists for each sensor.
Step 10: Concatenating DataFrames to Form Feature Matrices
DataFrames from all cases are concatenated to create feature matrices for each sensor.
Resulting Feature Matrix (
x1orx2):Step 11: Creating Labels for Each Sample
The code assigns labels to each sample based on the case it belongs to.
Visual Representation:
For Case 1:
Step 12: Concatenating Labels into a Single Array
All label arrays are concatenated to form a single target vector.
Resulting Label Vector (
y):ymatches the number of samples in the feature matrix (x1orx2).Step 13: Splitting Data into Training and Testing Sets
The data is split into training and testing sets to evaluate the models.
random_state=2: Ensures reproducibility.Visual Representation:
x)y)x_train1orx_train2y_trainx_test1orx_test2y_testStep 14: Data Prepared for Modeling
At this stage, the data is prepared and ready for training machine learning models.
Summary of Prepared Data:
x_train1x_train2y_trainx_test1x_test2y_testx_train1,x_test1,x_train2,x_test2): Contain the STFT features.y_train,y_test): Contain the corresponding case labels.Data Shapes:
Assuming the total number of samples is
Nand the number of features isF:x_train1.shape=(0.8 * N, F)x_test1.shape=(0.2 * N, F)y_train.shape=(0.8 * N,)y_test.shape=(0.2 * N,)Visual Summary of Data Preparation Steps
Raw Data:
df1,df2, ...,df16.Data Cleaning:
['sensor 1', 'sensor 2'].Signal Extraction:
signal_sensor1,signal_sensor2.Feature Extraction with STFT:
Feature Matrices:
ready_data1,ready_data2.x1,x2.Label Creation:
y_datafor each case.y.Data Splitting:
x_train1,x_train2,y_train.x_test1,x_test2,y_test.Conclusion
The data preparation process transforms raw vibration signals into a structured format suitable for machine learning:
By following these steps, the code ensures that the machine learning models have high-quality data to learn from, which is crucial for accurate bolt loosening detection.
Note: This explanation focuses on the data preparation steps, providing visual representations and detailed descriptions to help you understand how the code transforms raw data into features and labels suitable for machine learning models.