Coefficients for odd-order highpass filters mixed up?

DSP, Plugin and Host development discussion.
Post Reply New Topic
RELATED
PRODUCTS

Post

I am wondering if the code in the DSPFilters Project

void BiquadBase::setOnePole (complex_t pole, complex_t zero)

function is correct.

b1 is set fixed to one, and
b0 the calculated zero crossing .

However b0 is the coefficient which is applied to the x[n-0] value, and for highpass filters this ends up in beeing

b0 = -1
b1 = +1

which does invert the original signal.

Correct would be

b0 = +1
b1 = -1

For low pass filters, both b0 and b1 are set to +1, so the mixup does not matter.

The

void BiquadBase::setTwoPole (complex_t pole1, complex_t zero1,
complex_t pole2, complex_t zero2)


function already always sets b0 to 1.

So possibly the following patch:


--- a/DSPFiltersCPP/source/Biquad.cpp
+++ b/DSPFiltersCPP/source/Biquad.cpp
@@ -143,8 +143,8 @@ void BiquadBase::setOnePole (complex_t pole, complex_t zero)
const double a0 = 1;
const double a1 = -pole.real();
const double a2 = 0;
- const double b0 = -zero.real();
- const double b1 = 1;
+ const double b0 = 1;
+ const double b1 = -zero.real();
const double b2 = 0;

setCoefficients (a0, a1, a2, b0, b1, b2);

would fix that.

Is that patch is correct? Or could somebody explain why the original code is correct ?

Thank you for your comments,

Peter

Post

I can't say if its correct, but this fixes my phase-problems for odd order filter types!

Post

Sorry, was misreading the question.

Wouldn't a hipass of any order have near zero degrees phase shift approaching nyquist, and a phase shift of {+90 degrees * FilterOrder} approaching DC?

And a lopass of any order have near zero degrees phase shift approaching DC, and a phase shift of [-90 degrees * FilterOrder] approaching nyquist?

So a first-order hipass should have near +90 degrees phase shift approaching DC. A second order HP, near +180 degrees approaching DC (inverted gain). And a third order HP, near +270 degrees phase shift approaching DC?

Does the original code or your fix give the expected result?

Post

This is about Vinnie Falcos DSP Lib
https://github.com/vinniefalco/DSPFilters
http://www.kvraudio.com/forum/viewtopic ... 3&t=249926
JCJR wrote:Wouldn't a hipass of any order have near zero degrees phase shift approaching nyquist, and a phase shift of {+90 degrees * FilterOrder} approaching DC?
Yes, that should be the correct behavior. The problem is that DSPFilters inverts the phase with all odd-order high-pass filters (Also the phase-shift for odd order shelf filters is wrong). During my research i found this lonely very old post, which fixes the wrong behavior. It isn't fixed in the github repository. I have no idea if its mathematically correct, but it seems to fix the wrong behavior.

Post Reply

Return to “DSP and Plugin Development”