JuliaDSP / DSP.jl

Filter design, periodograms, window functions, and other digital signal processing functionality

Home Page:https://docs.juliadsp.org/dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Elliptic Filter Design Broken in v"0.7.0"

mattcbro opened this issue · comments

A recent update to DSP broke my code which used an Elliptic filter to design a bandpass filter.
Here is the code.

using DSP
using DSP.Filters

# create elliptic filter
bp1 = 0.75
bp2 = 10.0
Fsamp = 180
responsetype = Bandpass(bp1, bp2; fs = Fsamp)
designmethod = Elliptic(11, 0.25, 40)
#designmethod = Chebyshev2(11,  40)
bpass = digitalfilter(responsetype, designmethod)

# some random data
z = randn(300,2)
xnotch1 = filt(bpass, z)

This worked in v"0.6.10". Furthermore it appears to run if I replace my filter type with Chebyshev2.

The Error I get is this:

ERROR: LoadError: BoundsError: attempt to access 1-element Vector{ComplexF64} at index [2]
Stacktrace:
  [1] getindex
    @ ./array.jl:801 [inlined]
  [2] splice!(a::Vector{ComplexF64}, i::Int64, ins::Vector{Any}) (repeats 2 times)
    @ Base ./array.jl:1481
  [3] groupzp(z::Vector{ComplexF64}, p::Vector{ComplexF64})
    @ DSP.Filters ~/.julia/packages/DSP/JvLS1/src/Filters/coefficients.jl:325
  [4] SecondOrderSections{:z, Float64, Float64}(f::ZeroPoleGain{:z, ComplexF64, ComplexF64, Float64})
    @ DSP.Filters ~/.julia/packages/DSP/JvLS1/src/Filters/coefficients.jl:389
  [5] SecondOrderSections
    @ ~/.julia/packages/DSP/JvLS1/src/Filters/coefficients.jl:427 [inlined]
  [6] SecondOrderSections
    @ ~/.julia/packages/DSP/JvLS1/src/Filters/coefficients.jl:269 [inlined]
  [7] convert
    @ ~/.julia/packages/DSP/JvLS1/src/Filters/coefficients.jl:5 [inlined]
  [8] filt(f::ZeroPoleGain{:z, ComplexF64, ComplexF64, Float64}, x::Matrix{Float64})
    @ DSP.Filters ~/.julia/packages/DSP/JvLS1/src/Filters/filt.jl:119
  [9] top-level scope
    @ /data/projects/Maestro/PulseLib/testsession.jl:20
 [10] include(fname::String)
    @ Base.MainInclude ./client.jl:444
 [11] top-level scope
    @ none:1
in expression starting at /data/projects/Maestro/PulseLib/testsession.jl:20

Actually, while this doesn't throw anymore, it now gives wrong results. This is what the designed filer in ZPK form and the SOS version that gets used by filt look like:
filters_compare
That is pretty bad.

But the good news: #435 should actually make this work as expected (fingers crossed).

@martinholters I haven't tested the fix myself yet, I've been trying to find good workarounds. So nice catch. This should be reopened if it hasn't been fixed yet.

This should be reopened if it hasn't been fixed yet.

I chose to merge #435 instead, so this should now actually be fixed.

This should be reopened if it hasn't been fixed yet.

I chose to merge #435 instead, so this should now actually be fixed.

OK. Haven't had a chance to test any of this. I'm under a deadline crunch and had to revert my DSP.jl version back to 0.6.10 for now. There is also some issues with how filtfilt works. When you time reverse you need to conjugate as well, but I just haven't had time to create a proper test example and issue report for that.

Thanks for all the good work.