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개)
Derek Miller
2017년 11월 20일
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!