# Orders of complimentary butterworth filters for IMU

I'm currently trying to design a complimentary filter for deployment on a drone, as part of an assessed semester project. Even though processing power is not an issue (we have GHz, lots of pipelining and all the good stuff), I am still electing to use an IIR filter in the final implementation, as this is easier to represent mathematically in my opinion.

As I have read Here in this answer, certain orders of filters do not produce monotonic unity gain in output. As such, at this stage I am mostly interested in proving, in a round-about way, which orders of filters produce monotonic unity gain. Phase difference is almost inconsequential at this stage, as I am reasonably confident in not using such a high-order filter that we hit any timing constraints.

So, I have written some initial matlab code to test my application on a first order Butterworth pair, as seen below. It is worth noting that our sampling frequency is 1 Khz, meaning the nyquist frequency is 500 Hz. As such the normalized cutoff frequency of 0.25 equates to 125 Hz, although this is arbitrary at this stage. Possible problems include the summing of the 2 filters in the last line, or the need to add some integrator term to the high-pass. We also currently have some stock complimentary filters that came with the drone (all came as a big package from Quanser, their autonomous vehicle research suite thingy), but it seems lackluster to just use them and not know what they do. I will also be taking a closer look at the filters for the IMU and magnetometer in a short while after this is complete, as I think I can do a little better.

clc;
clear;
close all;
w_n=0.25; %cutoff frequency

[zL1,pL1,kL1] = butter(1,w_n,'low');
[numL1,denL1] = zp2tf(zL1,pL1,kL1);
sysL1=tf(numL1,denL1);

[zH1,pH1,kH1] = butter(1,w_n,'high');
[numH1,denH1] = zp2tf(zH1,pH1,kH1);
sysH1=tf(numH1,denH1);

sys1=sysL1+sysH1;


Making the bode plot of this transfer function gives me something completely different from what I was expecting, as also seen below.

Any help and guidance is appreciated, many thanks!

• what you are getting is ok. Adding a high pass and (a complementary) lowpass filter of unity gains both will give you a unity gain filter which has a 0 dB gain at all frequencies. Your plot shows dB gains of $10^{-15}$ which is numerically zero. So what' the problem ? Commented Dec 2, 2018 at 21:39
• I am just using the command window to generate bode plots, using bode(). I get the expected result for both the low and high pass, monotonic in the pass- and stop-bands, and nice and smooth in the transition. Could this be to do with the way matlab handles summation of transfer functions? Commented Dec 2, 2018 at 21:40
• oh. now I see it, It is right, but I'm getting a numerical error because of the machine epsilon... I know mine is something^-16, checked a while back Commented Dec 2, 2018 at 21:41