I'm trying to filter the velocity of a motor when I measure it, to do that, I have implemented the following low pass filter: enter image description here
I select fc = 500Hz, and the 'zoh' aproximation to get the discrete transfer function, considering Ts = 10 us (sample time), which is enough. From the discrete transfer function we can obtain the difference equations:
y(k) = a*y(k-1)+(1-a)x(k)
Where, a = exp(-wc*Ts)
In the C code:
w_real[0] = exp(-2*pi*fc*Ts*1e-6)*w_real[1] + (1-exp(-2*pi*fc*Ts*1e6))*60/(MOTOR.NPolePairs*delay*CLCK_SPD_PERIOD*1e-9);
w_real[1] = w_real[0];
W_real is a vector that contains the value of the angular velocity of the motor, w_real1 is used to store the last value (y(k-1)). The operation "60/(MOTOR.NPolePairs delay CLCK_SPD_PERIOD1e-9" corresponds with the calculation of the actual velocity, x(k). This low pass filter shouldn't include any delay to the system, because it has a pole in s = -2 pi fc = -3141, which is far enough from the two complex poles of the system (s = 1000 +- 878i),however, when I apply the filter, the values of the w_real suffer a delay.
The following image show the step response (0.5*u(t)) of the system, the red graph is with the low pass filter, and the blue, without it: enter image description here
The difference in the gain has to do with the blue graph is the mathematical model of the motor.If I quit the filter I obtain a quick response, more similar to the model: enter image description here
I'm confused, Why does this filter introduce that long delay?
By last, when I simulate the step response of the model and filter: G(s)*LPF(s) the delay doesn't appear.
Regards, José Antonio.