From 878281a755dc564c53b27ece2df5839381cf335d Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Thu, 5 Dec 2024 15:37:50 +0100 Subject: [PATCH] Let `_filt_iir!` handle `a`, `b` of different length --- src/Filters/filt.jl | 9 +-------- src/dspbase.jl | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/Filters/filt.jl b/src/Filters/filt.jl index d282c85a..0765181c 100644 --- a/src/Filters/filt.jl +++ b/src/Filters/filt.jl @@ -162,14 +162,7 @@ function filt!(out::AbstractArray{<:Any,N}, f::DF2TFilter{<:PolynomialRatio,Arra mul!(out, x, b[1]) else a = coefa(f.coef) - as = length(a) - bs = length(b) - if as != 1 - if as < n - append!(a, zero(eltype(a)) for _ in 1:(n-as)) - elseif bs < n - append!(b, zero(eltype(b)) for _ in 1:(n-bs)) - end + if length(a) != 1 for col in CartesianIndices(axes(x)[2:end]) _filt_iir!(out, b, a, x, view(si, :, col), col) end diff --git a/src/dspbase.jl b/src/dspbase.jl index b86ff43e..0cbb3b12 100644 --- a/src/dspbase.jl +++ b/src/dspbase.jl @@ -45,9 +45,6 @@ function filt!(out::AbstractArray, b::Union{AbstractVector, Number}, a::Union{Ab a = @noinline broadcast(/, a, norml) b = @noinline broadcast(/, b, norml) end - # Pad the coefficients with zeros if needed - bs length(b) + for j in length(b):silen-1 + si[j] = muladd(val, -a[j+1], si[j+1]) + end + si[silen] = -a[silen+1]*val + else + for j in length(a):silen-1 + si[j] = muladd(xi, b[j+1], si[j+1]) + end + si[silen] = xi*b[silen+1] + end end end