Help on derivative of a function in discrete time

4 次查看(过去 30 天)
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

回答(1 个)

Walter Roberson
Walter Roberson 2015-6-14
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 个评论
lady bird
lady bird 2015-6-15

Thank you Walter Roberson for your answer

in fact, i did a mistake my code was rather as follows:

    r_1=0;
    r1(k)=r(k)-r_1/ts;
    r_1=r(k); 

where r1(k) is the first derivative, and i dont know if this is correct

In the other hand, yes i just checked in that book , there is an update of the variables as u just stated

   r_2 = r_1;
   r_1 = r(k);

r_1 and r_2 are initialized to zero at first

Walter Roberson
Walter Roberson 2015-6-16
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Variables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by