Is there a way to stream data one bit at a time through a model via a clock?

1 view (last 30 days)
Greetings,
I am trying to take a large .mat file and stream the data through a model one bit at time via a clock. Is there a way to modify the "From file" block to do this? This is for academic training and I have access to pretty much every block set.
Thank you

Answers (1)

Shubham
Shubham on 4 Mar 2024
Hi William,
To achieve streaming data from a .mat file one bit at a time via a clock in a Simulink model, you will need to use a combination of blocks and potentially some custom MATLAB script. The "From File" block typically reads data in larger chunks than one bit at a time, and it's designed to output data at each simulation step based on the sample time you specify. However, for academic training purposes, let's explore a way to modify or work around this limitation.
Steps to Stream Data One Bit at a Time:
  1. Write a MATLAB script to load your .mat file, convert the data into a binary format (if necessary), and then save this binary sequence to a new .mat file or a workspace variable.
  2. Since the "From File" block might not directly support bit-by-bit streaming as you need, you can use a MATLAB Function block to manually manage the reading and streaming of data. MATLAB Function Block: Add a MATLAB Function block to your model. This block will read from the pre-processed .mat file or workspace variable and output one bit at each execution.Implement the Function: Inside the MATLAB Function block, implement logic to read and output one bit of your data at each time step. You'll likely need to manage the current index of the bit being read using a persistent variable.
  3. Clock Block: Use a Clock block to drive the execution of your MATLAB Function block. Connect the output of the Clock block to the input of your MATLAB Function block. Sample Time: Ensure that the sample time of your MATLAB Function block and any related blocks is set appropriately to match the rate at which you want to stream bits.
  4. The output of your MATLAB Function block will be the streamed bits. You can then connect this output to the rest of your model for further processing or training.
Considerations:
  • Streaming data one bit at a time can be very slow, especially for large datasets. Ensure this approach is suitable for your application.
  • Ensure your data's binary representation matches your model's needs, considering aspects like bit order and data type.
This approach leverages the flexibility of MATLAB Function blocks to achieve functionality that's not directly available through standard Simulink blocks.

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!