How to calculate in v(k) - v(k-1) in M file
이전 댓글 표시
Hi all!
How to calculate v(k) - v(k-1) in M file. v(k) is not in the table/array, but it is an input signal from Simulink model (e.g. voltage) to Matlab Fnc block.
In Simulink (without using Matlab Fnc blocks) I use Variable Transport Delay. But now I want to write as much code as possible in M file.
Thanks.
답변 (2개)
Azzi Abdelmalek
2013년 12월 12일
function e=fcn(v)
persistent vp
if isempty(vp)
vp=0;
end
e=v-vp;
vp=v;
Wayne King
2013년 12월 12일
편집: Wayne King
2013년 12월 12일
you can use the diff() function in MATLAB. That is v(k)-v(k-1)
Also in R2013b if you have DSP System Toolbox, you can use the System object
dsp.FIRFilter
and then use the System block (create Simulink block from the System object)
hfir = dsp.FIRFilter('Numerator',[1 -1]);
x = 1:10;
x = x.^2;
y = step(hfir,x');
카테고리
도움말 센터 및 File Exchange에서 Modeling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!