How to create variable size buffers in Simulimk?

2 visualizaciones (últimos 30 días)
Vaibhavee Vaidya
Vaibhavee Vaidya el 27 de Ag. de 2020
Respondida: Anurag Ojha el 14 de Ag. de 2024
I want to create a vector of data that is output by the RTL-SDR Simulink block. This vector has variable length depending on certain other parameters. I was using a Simulink buffer block to create a vector, however, I am unable to design a variable size buffer in Simulink.
Thank you in advance.

Respuestas (1)

Anurag Ojha
Anurag Ojha el 14 de Ag. de 2024
Hey Vaibhavee
In order to create a variable size buffers in simulink. You can use MATLAB Function block. MATLAB Function blocks enable you to define custom functions in Simulink models.
Here is a sample code of how you can write function that create a buffer of variable size.
function y = variable_size_buffer(u, len)
% Declare y as a variable-size signal
coder.varsize('y', [1, Inf]);
% Initialize the buffer as persistent
persistent buffer;
if isempty(buffer)
buffer = [];
end
% Append the new data to the buffer
buffer = [buffer, u];
% Check if the buffer length exceeds the desired length
if length(buffer) > len
% Trim the buffer to the desired length
buffer = buffer(end-len+1:end);
end
% Output the buffer
y = buffer;
end
Refer to this MATLAB documentation to get better understanding:

Categorías

Más información sobre Communications Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by