Help on derivative of a function in discrete time
Afficher commentaires plus anciens
Hello all Please can you help me out calculating derivatives of discrete time functions in matlab r(k+1) from r(k)
Given a discrete signal r(k)=0.5*sin*(pi*k*ts) for k=1:1=100
I found in one book that they used an extrapolation method as follows:
dr(k)=(r(k)-r_1)/ts;
dr_1=(r_1-r_2)/ts;
r1(k)=2*r(k)-r_1;
dr1(k)=2*dr(k)-dr_1;
to calculate first and second derivatives. i didn't understand this method
I tried rather to use a simple formula:
r_1=0;
r_1(k)=r(k)-r_1/ts;
r_1=r(k);
I don't know if this is correct ?
Thank you so much for your precious help
Best regards
Réponses (1)
Walter Roberson
le 14 Juin 2015
You change the same variable in all three lines. You have
r_1=0;
r_1(k)=r(k)-r_1/ts;
r_1=r(k);
You set all of r_1 in the first line. In the second line you overwrite only part of r_1 . But in the third line you overwrite all of it, using a value that was not changed in the previous lines. The effect is going to be as if you had only one line
r_1 = r(k);
I cannot really advise on the correctness of the method you showed from the book as I do not know what r1 is intended to represent that is different from dr. Also we would need to know how r_1 and r_2 are initialized. My suspicion is that the book might also show them changing, possibly like
r_2 = r_1;
r_1 = r(k);
so that the variables represent the two previous values.
3 commentaires
lady bird
le 15 Juin 2015
lady bird
le 15 Juin 2015
Walter Roberson
le 16 Juin 2015
They are using dr() as the first derivative, it appears, so I do not understand why they would also have r1.
The r_1 and r_2 make sense to me now.
Catégories
En savoir plus sur Mathematics 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!