Repository navigation
IIR, 4th order: strange results? #275
|
Hello. Using Trying to understand where I am wrong, i've added some reference math to (please check complete code at the attachment). This comparsion gives exact match with 2nd order IIR comes with P.S. I compile like And using Please note again, i am talk about C API. I use Archlinux x86_64. Thanks! |
Replies: 3 comments 2 replies
|
Hello, Do you use prebuilt kfr_capi library from Github Actions or you build it on your machine? |
|
Hi, I've looked at your test case. This isn't a bug in KFR. The main issue is that the coefficient format is wrong. Your The reference filter interprets it this way, but There's also an out-of-bounds read. With The fix is to convert the 4th-order filter into two SOS sections (e.g. with |
|
Thanks @dancasarin , now it works fine. |
Hi,
I've looked at your test case. This isn't a bug in KFR.
The main issue is that the coefficient format is wrong. Your
sosarray contains a single 4th-order direct-form IIR filter:The reference filter interprets it this way, but
kfr_filter_create_iir_plan_f64expects a cascade of 2nd-order sections, where each section is[a0, a1, a2, b0, b1, b2]. Passing direct-form coefficients to the SOS API will produce incorrect results.There's also an out-of-bounds read. With
sos_count = 2, KFR reads2 × 6 = 12doubles, but your array only contains 10, so it reads past the end. That's undefined behavior and explains the inconsistent results.The fix…