EmbeddedRelated.com
Forums

Digital integrator in C

Started by steven02 5 years ago2 replieslatest reply 5 years ago1168 views
#C

Hello,

I am going to implement a digital integrator in C. I have decided to use trapezoidal rule in recurrent form i.e. to use following formula 

$$I(k) = I(k-1) + \frac{T}{2}\cdot [x(k-1) + x(k)]$$, 

where $$T$$ is the period of execution. Please can anybody tell me whether this formula is good choice or any other better ways how to calculate an integral exist? Thanks in advance for any ideas.

#C

[ - ]
Reply by jms_nhDecember 15, 2019

Don't bother with the trapezoidal rule; it provides a very small filtering against high-frequency noise, and if you're using a control feedback system you need to manage the phase lag caused by filtering/delays.

[ - ]
Reply by liyuDecember 15, 2019

It depends on the purpose of the integrator. If it's just for integral calculation, then the forward approximation is more simple,

I(k)=I(k-1)+T*x(k)  

If it's for feedback control, then frequency-domain response could be important as already mentioned by others. In that case, comparing different implementation methods in frequency domain should be helpful, and this can be done easily with Matlab.