Develop circular buffer block in Simulink

85 views (last 30 days)
Dear all,
I am currently try to implement a circular buffer block in Simulink, since I do not have access to the DSP Toolbox. The idea is to store chunks of signal along a real-time simulation for further processing of the windowed signal. The buffer should have the following features:
  • user-defined length
  • user-defined initial conditions
  • update only the oldest buffer value
So far I've come up with the Simulink model attached to this question. Although correctly working (I tested it against the results derived from a standard DSP-Toolbox Buffer block with similar input values), such models evidences two major drawbacks:
  1. the buffer length is now directly given within the function, whereas I'd like allowing the user to define the length. Clearly, the size won't change during the simulation, but it should be sort of "input" for the buffer.
  2. the initial condition is forced to be 0, but to better tracke whether the buffer is filled or not, I'd like setting the initial condition to 99999 as an example. Clearly, also such a value should be tunable when setting up the simulation.
Could you suggest any valid way to overcome these two issues?

Accepted Answer

Zack Peters
Zack Peters on 6 Apr 2016
Hi Francesco,
The MATLAB Function block is a good way to do it. One limitation is variable sample times at in/out. Meaning if you want to unbuffer only once the buffer is full then you can control this from within the block. Also, rather than use a delay block and loop it around, I prefer to keep a persistent variable inside. It makes things a lot less sloppy. Finally, you can pass parameters into your MATLAB Function block, which can come from either the base workspace, the model workspace, or a mask. In this case I masked the MATLAB Function block (try to open it) and created a mask dialog for the IC/Buffer Length parameters. That way they can be easily set by the user from the block's dialog. It's certainly not as robust/feature rich as the DSP blocks, but it will get the job done in a pinch.
See attached model.
~Zack

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!