Code Monkey home page Code Monkey logo

Comments (9)

rtlopez avatar rtlopez commented on August 16, 2024 1

@rotorflight definately something has to be done, If any first order lpf will be set above nyquist/2, bad things might happen. Also pt1 filter might have it's own limitCutoff() function.

from rotorflight-firmware.

rotorflight avatar rotorflight commented on August 16, 2024

The formula used in BF is incorrect. They have discussed it, and concluded that they did not want to fix it, as people are used to have it that way. Everybody would have needed to fix their configs after that.

The BF formula is for a continuous domain first order filter. When a continuous filter is converted into a discrete filter with Tustin/bilinear transform/zero order hold/etc, frequency warping happens. The cutoff formula must do frequency pre-warping to compensate.

Further, a discrete first order filter can't have cutoff above Nyquist / 2. (unlike the continuous first order).
If you try to use a freq higher than this, the gain will be incorrect.

from rotorflight-firmware.

rotorflight avatar rotorflight commented on August 16, 2024

See https://en.wikipedia.org/wiki/Bilinear_transform
Section "Frequency Warping"

from rotorflight-firmware.

rtlopez avatar rtlopez commented on August 16, 2024

@rotorflight thanks fo quick response, so that limitCutoff() is probably wrong, there is

    // 95% of Nyquist
    return fminf(cutoff, 0.475f * sampleRate);

but should be

    // 47.5% of Nyquist
    return fminf(cutoff, 0.2375f * sampleRate);

I'm not sure if UI account this, it shouldn't allow to set any LPF above nyquist/2 too.

from rotorflight-firmware.

rotorflight avatar rotorflight commented on August 16, 2024

Only the first order LPF has this limit. Higher order LPFs can go up to Nyquist.

from rotorflight-firmware.

rotorflight avatar rotorflight commented on August 16, 2024

But we can add a limit in the 1st order gain calculation so that it is never higher than 0.99 or so.

from rotorflight-firmware.

rotorflight avatar rotorflight commented on August 16, 2024

I'll keep this issue open until the limit has been added.

from rotorflight-firmware.

rotorflight avatar rotorflight commented on August 16, 2024

Correction. Only the filters that are converted to digital domain with the "rectangular rule" (zero-order hold) rather than the "trapezoidal rule" or bi-linear transform has this problem. PTx filters and EWMAx are the only ones in RF like this.

Both types require the frequency pre-warping. However, PTx filters just can't go over Fs/4.

from rotorflight-firmware.

rotorflight avatar rotorflight commented on August 16, 2024

Fixed in devel branch.

from rotorflight-firmware.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.