Skip to content

K80960/dm-on-device-training-fan-anomaly-on-mcxn947

 
 

Repository files navigation

NXP Application Code Hub

On-device training fan anomaly detection on MCXN947

On-device trainable anomaly detection based on the MCX platform. Train the SVM model on-device with normal accelerometer data and inference SVM model on-device too. Support the Inc-training, which means that we can define one-feature and train the model firs, then define second feature and train the model again. The final model can classify both the feature. To achieve this, click the Train, then at the training page, click the IncTrain first, then start. The model will try to learn both the feature.

Because data patterns are often very different or vary among the device life cycle.

During the whole life cycle of a device, learning may need to be done multiple times.

The GUI is implemented by LVGL.

Boards: FRDM-MCXN947

Categories: AI/ML, Anomaly Detection

Peripherals: DISPLAY, I2C

Toolchains: MCUXpresso IDE, VS Code

Table of Contents

  1. Software
  2. Hardware
  3. Setup
  4. Results
  5. FAQs
  6. Support
  7. Release Notes

1. Software

2. Hardware

  • 3.5" Low Cost NXP LCD (Default)
  • FRDM-MCXN947(SCH-90818_REV B) board
  • IMU(Inertial Measurement Unit) Sensor: MPU6050 module or FXLS8974 ACCEL-4-CLICK
  • FAN
  • Type-C USB cable

3. Setup

3.1 Step 1 Setup hardware

  • Connect board with LCD

  • Stick the IMU Sensor on the FAN like:

  • Connect IMU with FRDM-MCXN947 board, connection is shown in the table:

  • Connect LCD Panel with J8 FRDM-MCXN947 board.

  • Secure all components in place on the acrylic base using double-sided tape, ensuring the fan’s stable operation

  • The whole system is shown as:

Connect the debug port on board with the laptop.

3.2 Step 2

Develop in MCUXpresso IDE

Import the project into MCUXpresso IDE, click 'Import project from Application Code Hub', search 'on-device training fan anomaly on mcxn947' example, and clone to the local workspace.

Build the project, after compilation is complete, use the GUI Flash Tool (2 in the following figure) to write the program to the board.

Develop in VS code

In VS code, select the 'MCUXpresso For VScode' plugin, and click 'Application Code Hub' in the QUICKSTART PANEL.

Search 'on-device training fan anomaly on mcxn947' example, clone to local workspace.

After a while, the project is shown in the 'Projects'.

Build the project, after compile complete flash the board.

4. Results

Reset board, the main windows showing as:

4.1 Normal state training

Turn on the fan, click Train button, enter Trainer window. Click Start button and Wait for the progress bar to complete.

Click return button, then the real-time state of fan is shown in the Main window.

4.2 Anomaly use case

1 Object intruding into the fan, disrupting the operation of the fan blades.

2 Blocking the fan's air intake.

3 Lifting the base, causing the fan to tilt.

4 Tapping the base to introduce abnormal vibrations.

5. FAQs

The 'Param' setting in training windows.

The Gam is “Gamma (γ)”, Nu is “Nu (ν)”, they are two parameters to tune the trade-off between sensitivity and tolerance of the trained model.

For most demo settings, the default values (Gam:0050, Nu:0.1) often lead to a reasonable tradeoff between sensitivity and tolerance.

  • With larger Nu, the model is more sensitive to data change, but very large Nu (such as >=0.4) can make the model treating some training samples that are far from average as abnormal! So if you want a high sensitivity and quick-response demo, you should use larger Nu (such as 0.1 to 0.4); but if you want the demo more tolerant to random or accidental disturb, you should use smaller Nu (such as 0.03 to 0.1)

  • With larger Gamma, the model tends to treat the training data to multiple clusters (each training sample’s effective range gets smaller), So if your normal state contains multiple sub-states (such as both fan-off and fan-on are normal), then you should use larger Gamma (such as 20 to 200); but larger Gamma also makes the model less robust to the randomness in training data, so if your demo environment is heavily disturbed (such as by the vibration of a working computer, the air vibration by nearby fans, walking persons nearby), you should use smaller gamma (such as 5 to 20).

2D color contour visualization of the model’s decision boundary on the LCD, the color in green to blue are normal region, while the color in yellow-red-purple are abnormal regions. Default setting such as

  • Example 1: Two normal sub-states that are significantly different

  • Example 2: One normal sub-state, but data variance is large (due to disturbances)

Note: The model is the “one-class Support Vector Machine”, below are some more technical-oriented explanation of Gamma and Nu: Gamma (γ): Gamma is a parameter of the kernel function that determines the distribution of data after it is mapped to a higher-dimensional space. In the Radial Basis Function (RBF), a larger gamma value implies a smaller decision boundary, making the model more focused on the local characteristics of the training data; whereas a smaller gamma value suggests a larger decision boundary, resulting in a smoother model that is less sensitive to local fluctuations in the training data.

Nu (ν): Nu is a user-defined parameter that represents the upper limit of the proportion of error data points and the lower limit of the margin. This parameter helps control the ratio of support vectors as well as the looseness of the decision boundary. Simply put, a smaller nu value makes the model more inclined to ignore more outliers, leading to a wider decision boundary; conversely, a larger nu value makes the model more inclined to include more data points, resulting in a narrower decision boundary.

6. Support

Please contact NXP for additional support.

Project Metadata

Board badge

Category badge Category badge

Peripheral badge Peripheral badge

Toolchain badge

Questions regarding the content/correctness of this example can be entered as Issues within this GitHub repository.

Warning: For more general technical questions regarding NXP Microcontrollers and the difference in expected funcionality, enter your questions on the NXP Community Forum

Follow us on Youtube Follow us on LinkedIn Follow us on Facebook Follow us on Twitter

7. Release Notes

Version Description / Update Date
1.0 Initial release on Application Code Hub January 30 th 2024

About

On-device trainable anomaly detection base on MCX platform

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 99.4%
  • Other 0.6%