Orders of complimentary butterworth filters for IMU












1














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.
Bode plot of sys1



Any help and guidance is appreciated, many thanks!










share|improve this question






















  • 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 ?
    – Fat32
    Dec 2 '18 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?
    – Thefoilist
    Dec 2 '18 at 21:40






  • 1




    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
    – Thefoilist
    Dec 2 '18 at 21:41
















1














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.
Bode plot of sys1



Any help and guidance is appreciated, many thanks!










share|improve this question






















  • 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 ?
    – Fat32
    Dec 2 '18 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?
    – Thefoilist
    Dec 2 '18 at 21:40






  • 1




    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
    – Thefoilist
    Dec 2 '18 at 21:41














1












1








1







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.
Bode plot of sys1



Any help and guidance is appreciated, many thanks!










share|improve this question













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.
Bode plot of sys1



Any help and guidance is appreciated, many thanks!







filter-design infinite-impulse-response






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 2 '18 at 21:21









Thefoilist

1084




1084












  • 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 ?
    – Fat32
    Dec 2 '18 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?
    – Thefoilist
    Dec 2 '18 at 21:40






  • 1




    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
    – Thefoilist
    Dec 2 '18 at 21:41


















  • 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 ?
    – Fat32
    Dec 2 '18 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?
    – Thefoilist
    Dec 2 '18 at 21:40






  • 1




    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
    – Thefoilist
    Dec 2 '18 at 21:41
















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 ?
– Fat32
Dec 2 '18 at 21:39






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 ?
– Fat32
Dec 2 '18 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?
– Thefoilist
Dec 2 '18 at 21:40




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?
– Thefoilist
Dec 2 '18 at 21:40




1




1




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
– Thefoilist
Dec 2 '18 at 21:41




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
– Thefoilist
Dec 2 '18 at 21:41










1 Answer
1






active

oldest

votes


















2














You are simply seeing the quantization of the double type. Basically you have a pole and a zero that should cancel each other out. But because of the limited precision of the double data type, it doesn't. So instead of having 0 dB you have a gain of 10^-15 dB give or take.



But in real life, 99.99999% of the time 10^-15 dB = 0 dB



For the record, I think you could use the minreal function in Matlab to cancel the almost equal pole(s) and zero(s). You would then get your unity gain and your flat bode plot with 0 dB and 0 degree phase.



I don't like simply posting links, but a reminder on how floating-point works should help you.



https://en.wikipedia.org/wiki/Floating-point_arithmetic






share|improve this answer























    Your Answer





    StackExchange.ifUsing("editor", function () {
    return StackExchange.using("mathjaxEditing", function () {
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    });
    });
    }, "mathjax-editing");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "295"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdsp.stackexchange.com%2fquestions%2f53862%2forders-of-complimentary-butterworth-filters-for-imu%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You are simply seeing the quantization of the double type. Basically you have a pole and a zero that should cancel each other out. But because of the limited precision of the double data type, it doesn't. So instead of having 0 dB you have a gain of 10^-15 dB give or take.



    But in real life, 99.99999% of the time 10^-15 dB = 0 dB



    For the record, I think you could use the minreal function in Matlab to cancel the almost equal pole(s) and zero(s). You would then get your unity gain and your flat bode plot with 0 dB and 0 degree phase.



    I don't like simply posting links, but a reminder on how floating-point works should help you.



    https://en.wikipedia.org/wiki/Floating-point_arithmetic






    share|improve this answer




























      2














      You are simply seeing the quantization of the double type. Basically you have a pole and a zero that should cancel each other out. But because of the limited precision of the double data type, it doesn't. So instead of having 0 dB you have a gain of 10^-15 dB give or take.



      But in real life, 99.99999% of the time 10^-15 dB = 0 dB



      For the record, I think you could use the minreal function in Matlab to cancel the almost equal pole(s) and zero(s). You would then get your unity gain and your flat bode plot with 0 dB and 0 degree phase.



      I don't like simply posting links, but a reminder on how floating-point works should help you.



      https://en.wikipedia.org/wiki/Floating-point_arithmetic






      share|improve this answer


























        2












        2








        2






        You are simply seeing the quantization of the double type. Basically you have a pole and a zero that should cancel each other out. But because of the limited precision of the double data type, it doesn't. So instead of having 0 dB you have a gain of 10^-15 dB give or take.



        But in real life, 99.99999% of the time 10^-15 dB = 0 dB



        For the record, I think you could use the minreal function in Matlab to cancel the almost equal pole(s) and zero(s). You would then get your unity gain and your flat bode plot with 0 dB and 0 degree phase.



        I don't like simply posting links, but a reminder on how floating-point works should help you.



        https://en.wikipedia.org/wiki/Floating-point_arithmetic






        share|improve this answer














        You are simply seeing the quantization of the double type. Basically you have a pole and a zero that should cancel each other out. But because of the limited precision of the double data type, it doesn't. So instead of having 0 dB you have a gain of 10^-15 dB give or take.



        But in real life, 99.99999% of the time 10^-15 dB = 0 dB



        For the record, I think you could use the minreal function in Matlab to cancel the almost equal pole(s) and zero(s). You would then get your unity gain and your flat bode plot with 0 dB and 0 degree phase.



        I don't like simply posting links, but a reminder on how floating-point works should help you.



        https://en.wikipedia.org/wiki/Floating-point_arithmetic







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 3 '18 at 0:11

























        answered Dec 2 '18 at 21:41









        Ben

        53428




        53428






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Signal Processing Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            Use MathJax to format equations. MathJax reference.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdsp.stackexchange.com%2fquestions%2f53862%2forders-of-complimentary-butterworth-filters-for-imu%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            AnyDesk - Fatal Program Failure

            How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

            QoS: MAC-Priority for clients behind a repeater