How to calculate in v(k) - v(k-1) in M file
Afficher commentaires plus anciens
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.
Réponses (2)
Azzi Abdelmalek
le 12 Déc 2013
function e=fcn(v)
persistent vp
if isempty(vp)
vp=0;
end
e=v-vp;
vp=v;
Wayne King
le 12 Déc 2013
Modifié(e) : Wayne King
le 12 Déc 2013
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');
Catégories
En savoir plus sur Modeling dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!