Technical newsheet

Design EngineeringDevice profile

Simulink Blocks Close the MATLAB–Edge Impulse TinyML Loop

A free Simulink library streams windowed, labeled data to Edge Impulse Studio and compiles its C++ runtime into a MEX binary for bit-exact software-in-the-loop testing against Simscape plants.

By Sophie Lindqvist4 min read894 words

Features

  • EI_Data_Logger streams 3 s, 5 s, or 10 s windows to Edge Impulse over HTTPS with auto 80/20 split and solver-adaptive sample-rate inheritance.
  • EI_Model compiles Edge Impulse DSP + TFLite Micro C++ SDK into a native C++20 MEX binary (ei_universal_mex) from a one-click .zip import.
  • Companion EV BMS showcase streamed 24 minutes of telemetry and hit 100% holdout accuracy across four simulated fault states.
  • MathWorks File Exchange and MATLAB Answers return zero results for 'Edge Impulse'; no prior documented two-way workflow existed.
  • Setup takes under two minutes: clone the repo and add the toolbox folder to the MATLAB path.
MATLAB Toolbox for Edge Impulse
Device photoMATLAB Toolbox for Edge Impulse — Unknown / The Met · CC0

A new open-source toolbox gives Simulink its first native two-way path to Edge Impulse: one drag-and-drop block streams labeled simulation data to the cloud, a second compiles the trained model's exact C++ runtime into a MEX binary that runs live in the loop. Until now, the documented workflow between MATLAB and Edge Impulse was a one-way trip through dozens of manually uploaded CSV files — and a search for "Edge Impulse" on MathWorks File Exchange or MATLAB Answers returns zero results.

The toolbox's author, who built the integration as a student after taking an Introduction to Embedded Machine Learning course, published it free with a companion showcase: a zero-hardware EV Battery Management System that simulated four fault states in Simscape, streamed 24 minutes of telemetry, hit 100% holdout accuracy, and ran live fault detection back inside Simulink.

What lands inside Simulink's Library Browser?

The toolbox registers two universal blocks, plus full MATLAB class and function support for scripting. The first, EI_Data_Logger, drops onto any signal wire — a 1-channel temperature probe, 3-axis accelerometer, 6-axis IMU, or multi-sensor EV battery bus. Its parameter mask handles ingestion without code:

  • Automatic sample-rate inheritance across ode45, stiff Simscape solvers (ode23t), and fixed-step models.
  • Windowed cloud streaming that chunks live data into fixed windows (3 s, 5 s, or 10 s) and uploads over HTTPS using your x-api-key — or saves locally if you leave the key blank.
  • Auto 80/20 train/test split via Edge Impulse's native endpoint, plus guards that skip unconnected wires and cap chunks per run.
  • Multi-modality through EdgeImpulseUploader.m: time-series, .png images, and .wav audio, using Edge Impulse's official ingestion schemas.

The same workflow accepts synthetic Simscape fault datasets or live hardware — Arduino, serial sensors, DAQ cards, webcams — through MATLAB matrices and streams. That flexibility is the point: you can build dangerous fault datasets in physics simulation, not on a physical test rig.

How does the trained model come back?

Export your trained impulse as a C++ library (.zip) and drop EI_Model into the canvas. Click "Browse & Build Edge Impulse .ZIP Model..." and the importer unpacks the archive, reads model_metadata.h to auto-detect input channels, window length, sampling frequency, class labels, and model type. It then patches MSVC portability edge cases — GCC-specific C99 compound literals in K-Means anomaly headers trip up Windows compilers — and compiles the full Edge Impulse DSP + TFLite Micro C++ SDK into a native C++20 MEX binary, ei_universal_mex.

Supported outputs include classification, regression, anomaly detection (K-Means/GMM), object detection (FOMO/YOLO/SSD), and uint8 RGB image packing. A Live Prediction Monitor HUD shows the predicted label, confidence percentage, rolling input window, and per-class probability bars while the simulation runs. That monitor matters because the runtime is bit-exact software-in-the-loop: the same quantized C++ code that will run on the target board, wired to your Simscape plant. If quantization, windowing, or sensor noise breaks a state transition, you catch it before flashing a single MCU.

Why not just train in MATLAB?

The author answers the obvious question directly. MATLAB's ML toolboxes train models easily, but deploying to a $3 Cortex-M4, ESP32, STM32, or nRF52 with int8 quantization, EON Compiler memory reduction, and RAM/flash/latency profiling typically requires paid add-ons — MATLAB Coder and Embedded Coder — plus manual tuning. Edge Impulse provides one-click, hardware-ready C++, Arduino, CMSIS-PACK, or TensorRT exports with exact on-device latency and RAM figures.

In MATLAB, a plain uint8 RGB image passed to ei_universal_mex returns a bounding_boxes struct array with label, x, y, width, height, and value. Inside Simulink, where wires need fixed dimensions, EI_Model surfaces the strongest detection's Class_ID, Confidence, and per-class scores so vision detections drive state machines and scopes.

How was it built and tested?

The author built the integration in three layers, working with Google Antigravity as an AI engineering co-pilot. A universal C++20 MEX gateway reads model_metadata.h at compile time, so one wrapper adapts to any impulse type. An automated .zip importer and MSVC patcher handles the dozens of DSP and TFLite Micro source files. Level-2 S-functions wrapped in custom Simulink masks add dropdowns, checkboxes, and the build button.

Testing covered real end-to-end projects rather than a single sine wave: 3-axis coffee machine vibration classification, a Simscape industrial motor bearing predictive-maintenance model, a multi-modal test suite spanning temperature, 6-axis IMU, audio, and images, and the 4-state EV BMS with K-Means anomaly detection. Those runs caught Windows MSVC compiler quirks and variable-step solver drift.

Automotive teams can generate fault datasets — battery short circuits, thermal runaway, inverter faults, pothole impacts — from digital twins in minutes and verify quantized models before the test track. Robotics teams can prototype anomaly detectors for bearing wear, payload slip, and collisions before risking hardware. Hardware teams can start their ML pipeline on day one instead of waiting for PCB bring-up.

The takeaway for practitioners: clone the repo, add the toolbox folder to your MATLAB path, and you're running in under two minutes — no $5,000 test rig required. The open question is whether MathWorks or Edge Impulse picks up the integration officially, or the gap stays bridged by community code.

via hackster.io (Source)

Filed under

Share this article:

More from Sophie Lindqvist

Sophie Lindqvist

Show full bio

News editor covering regulation, policy and their impact on Instruments, test and measurement at Testbench Report.

113 articles

Application notes

« Previous articleNext article »