# Model Training This document explains how the TinyML model was trained using **Edge Impulse**, including dataset preparation, feature engineering, model architecture, optimizations, and export steps. This is a GitHub-friendly guideโ€”not a research paper version. --- ## ๐Ÿ“ 1. Dataset Preparation All raw datasets are located in the project: ``` Data/ โ”œโ”€โ”€ Data Final.zip โ””โ”€โ”€ Motor LAB 2.0 (with load using dynamometer).zip ``` Each dataset contains: - Three-phase voltage signals - Three-phase current signals - Temperature readings - Vibration sensor data - Labeled fault states ### **Classes Used in Training** - **Healthy** - **Single Phase Fault** - **Bearing Fault** - **Overcurrent / Overload** ### **Sampling Configuration** - **Sampling rate:** 200 Hz - **Window size:** 2 seconds (400 samples) - **7 total channels:** - Voltage A, Voltage B, Voltage C - Current A, Current B, Current C - Vibration --- ## ๐Ÿ” 2. Importing Data Into Edge Impulse ### Steps: 1. Create a new Edge Impulse project 2. Go to **Data Acquisition โ†’ Upload Data** 3. Upload all CSV/JSON/ZIP dataset files 4. Assign correct labels (Healthy, Phase Fault, etc.) 5. Verify data plots for any anomalies Your project dashboard should now show all classes with balanced sample counts. --- ## ๐Ÿ“Š 3. Creating the Impulse Go to **Create Impulse**. ### Impulse Structure ``` [Time Series Data] โ†’ [Spectral Analysis] โ†’ [Neural Network] ``` ### Settings - **Window size:** 2000 ms - **Window increase:** 2000 ms - **Frequency:** 200 Hz --- ## ๐Ÿงฎ 4. Feature Engineering Edge Impulse automatically extracts: ### **Time-Domain Features** - RMS - Mean - Peak - Standard deviation ### **Frequency-Domain (FFT) Features** - Magnitude spectrum - Energy distribution - Harmonic signatures - Important for: - Bearing faults (200โ€“800 Hz range) - Phase faults (low-frequency distortion) All spectral parameters were tuned using Edge Impulseโ€™s visual FFT preview. --- ## ๐Ÿค– 5. Neural Network Model A compact neural network was chosen to fit within ESP32-S3 memory constraints. ### Architecture ``` Input (FFT + Time features) โ†“ Dense 32 โ†“ Dense 16 โ†“ Dense 8 โ†“ Dropout 0.2 โ†“ Softmax Output (4 classes) ``` ### Training Config - **Epochs:** 50 - **Batch size:** 32 - **Learning rate:** 0.0005 - **Loss:** Categorical Crossentropy - **Optimizer:** Adam ### Achieved Metrics | Metric | Value | |--------|-------| | Accuracy | **94.3%** | | Precision | 0.96 | | Recall | 0.96 | | F1-score | 0.96 | --- ## ๐Ÿ”ง 6. Model Optimization ### Quantization Method The model was converted to: **TFLite Micro (int8 quantized)**. ### Benefits | Feature | Float32 Model | int8 Quantized Model | |---------|----------------|------------------------| | Classifier Latency | 24 ms | **4 ms** | | Flash Size | 551 KB | **164 KB** | | RAM Usage | 22.7 KB | **8.2 KB** | Quantized model chosen for deployment due to faster inference and lower memory footprint. --- ## ๐Ÿ“ฆ 7. Exporting the Model ### Steps 1. Go to **Deployment** in Edge Impulse 2. Select **Arduino Library** 3. Choose **Quantized (int8)** model variant 4. Download `.zip` 5. Extract to your project: ``` lib/ei-model/ ``` All generated files will be inside: ``` lib/ei-model/src/ ``` These files are used directly by the firmware. --- ## ๐Ÿงช 8. Testing the Model Using Edge Impulse **Model Testing**, run the test dataset. Expected output: - Accuracy ~94% - Confusion matrix showing strong separation among 4 classes - Minor confusion only in early fault stages --- ## ๐Ÿš€ 9. On-Device Inference Model runs on ESP32-S3 inside the FreeRTOS **TinyML Task**. ### Inference Cycle 1. Collect 400 samples 2. Run feature extraction (FFT + time-domain) 3. Execute TFLM forward pass 4. Display classification result on TFT + Web UI ### Average Inference Latency ``` 287 ms ``` Fits easily inside 2-second sampling window. --- ## ๐Ÿ“ˆ 10. Prognostic Trend Analysis After each inference, Softmax probabilities are passed through: - **Exponential Moving Average (EMA)** - **Trend slope detection** Predicts faults **before threshold crossing**. --- # โœ… Model Training Complete This model is ready for deployment via the ESP32-S3 TinyML runtime.