Rate Limiter mfile without a for loop

27 views (last 30 days)
Aubai on 22 Sep 2017
Dear All,
i have some data with a slow rate of change (small slopes) yet at some points my rate of change is very high i would like to identify those points and limite the rate of change at those points.
of course this is already done in Matlab Simulink block Rate Limiter. i would like to have the same effect as this block yet using only mfiles coding envinroment.
so my question how can i code this without using loops?
Here is the code when using the loop:
if true
% code
function [out] = Rate_Limiter(time,Sig,up,lo,Initial)
if ~isscalar(up)%length(up) > 0
warning('the upper rate limit should be a scaler the first value will be selected');
up = up(1);
if ~isscalar((lo))%length(lo) > 0
warning('the lower rate limit should be a scaler the first value will be selected');
lo = lo(1);
Temp.ts = mean(diff(time));
y = nan(length(Sig),1);
for i = 1:length(Sig)
if i == 1
Temp.rate = (Sig(i)-Initial) / (Temp.ts);
Temp.rate = (Sig(i)-y(i-1)) / (time(i)-time(i-1));
if Temp.rate > up
y(i) = Temp.ts * up + y(i-1);
elseif Temp.rate < lo
y(i) = Temp.ts * lo + y(i-1);
y(i) = Sig(i);
out = y;
I know that this might be impossible as it is let's say 'a closed loop control system' which mean the final output of the ongoing step (i) may depend on the previous output of the function final output (i-1).
but lets just see if there is some other way to do it!

Answers (0)


Find more on Simulink Environment Customization in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by