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

Filter coefficients error

JuhaHeiskala opened this issue · comments

Hi,
Is the below behaviour intentional?
Or have I misunderstood something....

julia> cc=DSP.PolynomialRatio([1.0], [1.0,1.0])
PolynomialRatio{:z, Float64}(Polynomials.LaurentPolynomial(1.0), Polynomials.LaurentPolynomial(1.0*z⁻¹ + 1.0))

julia> ff=DSP.DF2TFilter(cc)
ERROR: ArgumentError: length of state vector must match filter order
Stacktrace:
 [1] DF2TFilter
   @ ~/.julia/packages/DSP/C3OhM/src/Filters/filt.jl:137 [inlined]
 [2] DF2TFilter (repeats 2 times)
   @ ~/.julia/packages/DSP/C3OhM/src/Filters/filt.jl:154 [inlined]
 [3] top-level scope
   @ REPL[10]:1

This was with Julia 1.6.1 and DSP v0.7.2.
I briefly looked at the code and looked to be that state vector is initialized to the longer coefficient length, but then the error comes from a check that the input coefficients and state vector are all the same length. (lines 136-140 in filt.jl)

function DF2TFilter{Ti,Si}(coef::PolynomialRatio{:z}, state::Vector) where {Ti,Si}
        length(state) == length(coef.a)-1 == length(coef.b)-1 ||
            throw(ArgumentError("length of state vector must match filter order"))
        new{Ti,Si}(coef, state)
    end

Same error happens if the coefficients are padded with zeros to have same length, but not if coefficients are the same length and have non-zero first and last values.

Fallout of #284, I guess. (But note that before, PolynomialRatio with different numerator/denominator order was inconsistently defined, so the result of the filtering may not have been what one expected.)