ToB*_*oBe 2 code-generation simulink
我想在纯 Simulink 模型中实现一个非常巨大的(10^6 个元素 - 固定大小)循环缓冲区(没有进一步的工具箱,没有 S-Function)。
在某些时候,我需要读取一些元素(任何地方,而不仅仅是开始或结束)。
我无法使用以下解决方案:
我还没有尝试过“S-Function”,我正在寻找替代解决方案。
您还知道什么进一步的方法?
可以使用 MATLAB Fcn 模块创建简单的循环缓冲区:
function y = CircularBuffer(u, N)
%#codegen
% Function to implement a simple N element circular buffer
% Define the internal buffer variable as persistent so
% so that it will maintain its values from one time step
% to the next.
persistent buffer writeIdx
% Initialize the buffer the first time through
if isempty(buffer)
% Initialize the buffer
buffer = zeros(N,1);
writeIdx = 1;
else
buffer(writeIdx) = u;
if (writeIdx == N)
writeIdx = 1;
else
writeIdx = writeIdx+1;
end
end
% Output the buffer
y = buffer;
Run Code Online (Sandbox Code Playgroud)
这完全支持代码生成(并且不执行 memcpy)。
如果需要,您可以轻松更改缓冲区的数据类型,但如果您希望输入和输出信号具有不同的采样率(与信号处理模块集中的缓冲区一样),那么您需要恢复使用 S -功能。
| 归档时间: |
|
| 查看次数: |
8177 次 |
| 最近记录: |