Help on derivative of a function in discrete time
4 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Walter Roberson
on 14 Jun 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 Comments
Walter Roberson
on 16 Jun 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.
See Also
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!