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.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 12 Dez. 2013

1 Stimme

function e=fcn(v)
persistent vp
if isempty(vp)
vp=0;
end
e=v-vp;
vp=v;
Wayne King
Wayne King am 12 Dez. 2013
Bearbeitet: Wayne King am 12 Dez. 2013

0 Stimmen

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');

Kategorien

Mehr zu Modeling finden Sie in Hilfe-Center und File Exchange

Tags

Gefragt:

am 12 Dez. 2013

Bearbeitet:

am 12 Dez. 2013

Community Treasure Hunt

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

Start Hunting!

Translated by