MATLAB: Filter coefficient (N) in PID block

\nccodefilterpid

Good evening folks!
While tuning my quadrotor model in Matlab I found that the Matlab PID function had a Filter coefficient (N) term in the PID equation. However I have not encountered such a term in my typical PID programs. How would one implement this term into the PID equation and what would be some simple C code to add this term into the derivative? I tried generating C code from my model but got a lot of header and C program files with nothing close to simple.
My current PID code line in C is:
U2 = KP * phi_error + KI * phi_errorsum + KD * (PHI_RATE_desired-PHI_RATE);
Many Thanks, Robert

Best Answer

The code would look like that.
FilterCoefficient = (Kd * u - Filter_DSTATE) * N;
y = (Kp * u + Integrator_DSTATE) + FilterCoefficient;
Integrator_DSTATE += Ki * u * 0.01;
Filter_DSTATE += 0.01 * FilterCoefficient;
HTH.
Arkadiy