DSP.jl - digitalFilter - no matching method when using 'fs' as argument

Hi,

Julia v1.10.4
DSP v0.7.9

I was trying to create a digital filter using the example code, and get the following error.
https://github.com/JuliaDSP/DSP.jl/blob/76001f4f863f43df6b5ee48575e77f3dd3fe3941/docs/src/filters.md?plain=1#L216

digitalfilter(responsetype, designmethod; fs=1000)


ERROR: MethodError: no method matching digitalfilter(::Bandpass{Float64}, ::ZeroPoleGain{:s, ComplexF64, ComplexF64, Float64}; fs::Int64)

Closest candidates are:
  digitalfilter(::FilterType, ::FilterCoefficients) got unsupported keyword argument "fs"
   @ DSP ~/.julia/packages/DSP/H0J1V/src/Filters/design.jl:461
  digitalfilter(::FilterType, ::FIRWindow) got unsupported keyword argument "fs"
   @ DSP ~/.julia/packages/DSP/H0J1V/src/Filters/design.jl:595

I tried running it without the ‘fs’ argument, and it works.
digitalfilter(responsetype, designmethod)

I looked at the source, and it seems fine. I don’t understand what is wrong?
https://github.com/JuliaDSP/DSP.jl/blob/76001f4f863f43df6b5ee48575e77f3dd3fe3941/src/Filters/design.jl#L622

Thanks for any help!

The fs keyword argument goes into the constructor of the responsetype object, e.g.

julia> digitalfilter(Lowpass(0.3; fs=1000), Butterworth(3))
ZeroPoleGain{:z, ComplexF64, ComplexF64, Float64}(ComplexF64[-1.0 + 0.0im, -1.0 + 0.0im, -1.0 + 0.0im], ComplexF64[0.9990566353334952 + 0.0016308813925406407im, 0.9990566353334952 - 0.0016308813925406407im, 0.9981168187068135 + 0.0im], 8.355936714097361e-10)
2 Likes

Danke!

Can I ask a dumb follow up question.

The function definition specifies fs as an argument. So I’m wondering why the function doesn’t recognise it?

https://github.com/JuliaDSP/DSP.jl/blob/76001f4f863f43df6b5ee48575e77f3dd3fe3941/src/Filters/design.jl#L622

function digitalfilter(ftype::FilterType, proto::FIRWindow; fs::Real=2)
    coefs = firprototype(length(proto.window), ftype, fs)
    @assert length(proto.window) == length(coefs)
    out = coefs .* proto.window
    proto.scale ? rmul!(out, 1/scalefactor(out, ftype, fs)) : out
end

Also, I guess the example in the documentation is just a mistake, or just outdated?

This fs parameter was added only very recently (PR #458, commit 3ad3c1cc4689) by Christian Gruber, to refactor how frequency scaling works across analogue and digital filter design. This is new to me as well.