DSP-Cpp-filters icon indicating copy to clipboard operation
DSP-Cpp-filters copied to clipboard

Second order All pass "so_apf.h" might have missing frequency

Open visuttaja opened this issue 3 years ago • 6 comments

I can see at top comment section mentioning frequency but parameters are only for Q and samplerate(fs). Then when I test filter it gives only abrupt bump. Happily nothing worse happens though. I think one of those fs's must be the frequency but I don't understand much about filters math so I cannot correct the situation my self. Maybe you could kindly review the second order all pass code to clarify which is the frequency - if any. It is this part which I feel is missing frequency parameter and corresponding code part in file so_apf.h:

tp_coeffs& calculate_coeffs(float Q, int fs)

visuttaja avatar Feb 24 '22 03:02 visuttaja

Ok. I found some info! All pass filter is supposed to change only phase of signal keeping level of different frequencies the same. But still the abrupt bump is not right output? Or is it after all?

visuttaja avatar Feb 25 '22 03:02 visuttaja

For the first and second order all pass filters the meaning of Q and fc are:

  • fc, corner frequency
  • Q, steepness of phase shift at fc (second-order only)

For more info I could refer you to the chapter 6 (6.6.7) of this book here.

All the filters in this code are derived from this book, which worth every cent.

Regards.

dimtass avatar Feb 26 '22 17:02 dimtass

Yes. I understand. That is why I pointed out that in the code you publish the formal parameter names for second order all pass filter are tp_coeffs& calculate_coeffs(float Q, int fs) where it probably should be like you point out is tp_coeffs& calculate_coeffs(float Q, int fc)

Note the "fs" changes to "fc" like you point out.

And if so then fc should be used in code instead of fs. I did implement all the filters you kindly provided in java and all them worked fine except second order all pass filter. So I found that the guidance in that file is /**

  • Second order all-pass filter
  • Dimitris Tassopoulos 2016-2020
  • fc, corner frequency
  • Q, steepness of phase shift at fc (second-order only) */ But in code there is no fc used. And not as parameter either. So it is not consistent and there is something going on. Then I concluded that possibly there would be some typo you are aware if you check it out and would be able to solve immediately with you insight on the matter. I mean....If there is error you would like to know about it no matter what is the source? I am not blaming you you see. Just telling.

visuttaja avatar Feb 27 '22 03:02 visuttaja

Thanks for the feedback. It's possible that there are bugs in the code and there were a couple of PRs also from other users to fix them.

dimtass avatar Feb 27 '22 10:02 dimtass

Actually, Will Pirkle issued some errata including one for the 2nd order APF (page 188), alpha is correct, but beta relies on thetac, which is not described and your code is apparently wrong there. It should read: coef_size_t a = (tan(pi * Q / fs) - 1.0) / (tan(pi * Q / fs) + 1.0); // same as your code coef_size_t b = -cos(2 * pi * fc / fs); // instead of -cos(pi * Q/fs) Source here: https://www.willpirkle.com/support/errata/ Hope that helps ;-)

lorenzolamasse avatar May 12 '22 17:05 lorenzolamasse

@lorenzolamasse good find. I'll take a look at the errata and the book and fix any errors. Thanks!

dimtass avatar May 14 '22 15:05 dimtass