I need to create a Simulink running signal minimum function
显示 更早的评论
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
回答(2 个)
umichguy84
2017-11-20
0 个投票
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Descriptive Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!