Rate Limiter mfile without a for loop
22 次查看(过去 30 天)
显示 更早的评论
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);
end
if ~isscalar((lo))%length(lo) > 0
warning('the lower rate limit should be a scaler the first value will be selected');
lo = lo(1);
end
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);
else
Temp.rate = (Sig(i)-y(i-1)) / (time(i)-time(i-1));
end
if Temp.rate > up
y(i) = Temp.ts * up + y(i-1);
elseif Temp.rate < lo
y(i) = Temp.ts * lo + y(i-1);
else
y(i) = Sig(i);
end
end
out = y;
end
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!
0 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Naming Conventions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!