berndporr / iir1

DSP IIR realtime filter library written in C++
http://berndporr.github.io/iir1/
MIT License
637 stars 140 forks source link

Butterworth::HighPass<1> flips polarity of signal #38

Closed heebje closed 2 years ago

heebje commented 2 years ago

Hi,

I use a simple 6dB/oct Butterworth::HighPass<1> in an audio plugin I am developing, and I discovered that apparently it flips the polarity of the signal. I would expect the pass band to have a phase of close to 0 degrees, but it's close to 180 degrees instead.

I noticed this when mixing the 'wet' signal of my plugin with the dry signal. I did an extra test, outside of my plugin, just to confirm.

Is this by design? It doesn't feel right.

berndporr commented 2 years ago
int main(int, char**)
{
    const int order = 1;

    // sampling rate here 1kHz as an example
    const float samplingrate = 1000;

    FILE *fimpulse = NULL;

    // Butterworth lowpass
    Iir::Butterworth::LowPass<order> f;
    double cutoff_frequency = 100; // Hz
    f.setup(samplingrate, cutoff_frequency);
    fimpulse = fopen("lp.dat", "wt");
    // let's simulated date streaming in
    for (int i = 0; i < 1000; i++)
    {
        double a = 0;
        if (i == 10) a = 1;
        double b = f.filter(a);
        fprintf(fimpulse, "%e\n", b);
    }
    fclose(fimpulse);

}

i

berndporr commented 2 years ago

Impulse response positive so all good. Since you haven't provided a testable case I'm closing it.