Digital integrator in C

Started by steven02 1 year ago2 replieslatest reply 1 year ago168 views


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.


[ - ]
Reply by jms_nhDecember 12, 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,


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.