Clear Filters
Clear Filters

Using n-D Look Up Tables for Data Conversion

1 view (last 30 days)
Hello Everyone!
I hope you all are doing well! For a real time experiement I am trying to run in Simulink, I am trying to figure out a way to convert data from 8 different EMG sensors and stream them into tabular form in order to use a Classification Leaner function to make live predictions of this data. I am envisioning a table within Simulink that has 8 columns, each for the 8 different sensors, with rows representing the time stamps of the data values across the different sensors of data. The rows should be constantly increasing throughout the experiment.
I am trying to us an 8-D Look-Up table in order to join the 8 different data streams into tabular form, but I cannot figure out how to shape the parameters of the table (the breakpoints and tabular data settings specifically). Can someone help me with this, or suggest an easier alternative to accomplish what I am thiniking of?
Thanks in advance!

Accepted Answer

Namnendra
Namnendra on 16 May 2024
HI Caly,
For the purpose you've described, using an 8-D Look-Up Table (LUT) in Simulink to combine 8 different EMG sensor data streams into a tabular form might not be the most straightforward or efficient approach. LUTs are generally used for mapping input values to output values based on defined breakpoints, rather than for aggregating time-series data from multiple sources into a table format.
Instead, consider a strategy that involves collecting the data streams into a MATLAB function block or using Simulink blocks designed for handling and aggregating signals. Here's a simplified approach to achieve what you're aiming for:
Step 1: Aggregate Sensor Data
First, you'll want to aggregate the 8 different EMG sensor data streams. This can be achieved by using a Concatenate block in Simulink, which combines multiple inputs into a single output vector or matrix.
1. Concatenate Block: Place a Concatenate block (found under Simulink -> Math Operations) and set its parameters to concatenate along the first dimension if you're streaming data in a row-wise manner (time steps as rows, sensor readings as columns). To know more :- https://in.mathworks.com/help/simulink/slref/vectorconcatenate.html
Step 2: Buffer the Data
Since you're looking to have rows representing timestamps, you'll need to buffer the data over time.
1. Buffer Block: Use the Buffer block (from DSP System Toolbox, under Signal Management -> Buffers) to collect data over time. Set the buffer size according to the number of time steps you want to include in your table at any given moment. To know more :- https://in.mathworks.com/help/dsp/ref/buffer.html
Step 3: Convert Buffered Data to a MATLAB Table
To convert the buffered matrix into a MATLAB table and perform live predictions, you can use a MATLAB Function block.
1. MATLAB Function Block: Place a MATLAB Function block in your model and write a custom function inside it. This function will convert the input matrix (buffered data) into a table, and then you can apply your classification model to this table for live predictions.
Here's a simplified example of what the MATLAB function code might look like:
function out = emgPrediction(data)
% Convert matrix to table
tbl = array2table(data, 'VariableNames', {'Sensor1', 'Sensor2', 'Sensor3', 'Sensor4', 'Sensor5', 'Sensor6', 'Sensor7', 'Sensor8'});
% Load your trained classification model (load once using persistent variable)
persistent trainedModel;
if isempty(trainedModel)
trainedModel = load('myTrainedModel.mat').trainedModel; % Adjust filename/path as necessary
end
% Make predictions
predictions = trainedModel.predictFcn(tbl);
% Output or further process the predictions as needed
out = predictions;
end
Step 4: Use the Predictions
The output from the MATLAB Function block can then be used within your Simulink model for further processing or for control purposes, depending on your experiment's requirements.
Additional Notes
- Model Loading: Ensure that the model is loaded efficiently (e.g., using persistent variables as shown) to avoid reloading it on every execution step.
- Real-Time Considerations: For real-time experiments, ensure that the execution time for predictions and data buffering is within your system's real-time constraints.
- Simulink Configuration: Depending on your version of MATLAB and Simulink, specific block paths or functionalities might differ slightly. Always refer to the latest documentation for guidance.
This approach should offer a more direct and flexible way to achieve your goal of making live predictions from aggregated EMG sensor data in Simulink.
I hope the above information helps you in your task.
Thank you.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!