Greetings all! This is a general question that involves engineering judgement (which I don't have a lot of in the field of motor controls).
1. In discrete math for a real time application, I might code a time derivative as:
Similar equation for an integral:
2. There are more "accurate" equations than the ones above, for instance:
More accurate derivative:
Let's say I want to use the "more accurate" derivative equation in a 100kHz PWM control loop application (for instance, a dc-dc converter, or a motor control application).
The "more accurate" derivative uses an x[n+2] term, which means that whenever I use the equation, I'm always 2 samples "behind". In the world of 100kHz real time applications, is this 2 sample delay a "big deal", or can I get away with it?
Are you trying to implement PID loop for motor speed control. These delays have effect and also the motor/circuit lag will introduce more delay in the system. A proper tuned PID can overcome this.
In my experience with PID control, the derivative term is usually unnecessary or diminished. In discrete math it is mostly a noise maker, for that it is not worth improving it with 4-point approximation. Furthermore, increasing sampling rate worsens derivative term accuracy to practically a noise level. I think that 10kHz sampling rate should suffice for a motor control, while 100kHz is not enough for DC-DC converter application.