I need to create a Simulink running signal minimum function
Mostrar comentarios más antiguos
I don't have the DSP toolbox, and I'm trying to write a custom Matlab function to compute the minimum of the signal throughout its running history without depending on this toolbox as it could be used on different machines for people with different licenses. I have a working function for a windowed sample of the signal, but is there any good way to implement this for the entirety of the signal? This is my windowed minimum signal custom Matlab function (it also outputs the sum of the input signal), where n is the number of samples for the windowed minimum, and u is the input signal. S is the output sum, and m is the output minimum:
function [S,m] = sum_and_min(u,n)
%#codegen
persistent interm;
if(isempty(interm) || isnan(u))
interm = 0;
else
interm = u;
end
persistent sum buf iter;
if isempty(sum)
sum = 0;
buf = zeros(1,n);
iter = 1;
end
% for each incoming sample u:
sum = sum + interm;
S = sum;
buf(iter) = sum;
iter = iter + 1;
if iter > numel(buf)
iter = 1;
end
m = min(buf);
end
Respuestas (2)
Derek Miller
el 20 de Nov. de 2017
umichguy84
el 20 de Nov. de 2017
0 votos
Hello, Here is an alternative to a Matlab function. See the attached image below for an example in Simulink.

How you handle the write and read of the data across simulations is up to you and would depend on your situation. But taking the last value of your MinValueOut, writing to a mat file with MinValueFromLastRun in a post sim callback, and then reading in that mat file in a pre sim callback would work.
Categorías
Más información sobre Scopes and Data Logging en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!