I have obtained some Z coefficients in MatLAB. Now I need to implement the filter in C.
How do I do this?
The coefficients in Z domain:
num = [0.2557 -0.5115 -0.2557 1.0230 -0.2557 -0.5115 0.2557];
den = [1.0000 -4.0196 6.1894 -4.4532 1.4208 -0.1418 0.0044];
Any help is appreciated.
(I tried googling, but didn’t find anything clear and easy to understand.)
I’m guessing that the main issue is translating from Z domain to time.
Y(z) = H(z)*X(z)
H(z) = B(z)/A(z) = Y(z)/X(z)
B(z)*X(z) = A(z)*Y(z)
Then from the documentation:
B(z) = b(1)*z^-n + … + b(n+1)
A(z) = z^-n + … + a(n+1)
Converting to time domain:
b(1)*x(t) + b(2)*x(t-1) + … + b(n+1)*x(t-n) = a(1)y(t) + … + a(n+1)*y(t-n)
Then ‘solving’ for y(t), given that a(1) is 1:
y(t) = b(1)*x(t) + b(2)*x(t-1) + … + b(n+1)*x(t-n) – a(2)*y(t-1) … – a(n+1)*y(t-n)
where n = 7. So, say you have to arrays in which you store the last 6 values of the input x and the filter output y:
It’s not great, but I think that ought to get you going. Let me know if something isn’t clear!