Hi
I am looking for an implementation of scipy.signal.convolve.
Is there an implementation in Julia?
Or convolution Linear Filtering similar to R stats::filter
Thanks
Hi
I am looking for an implementation of scipy.signal.convolve.
Is there an implementation in Julia?
Or convolution Linear Filtering similar to R stats::filter
Thanks
For 1D signals you may use the convolution in DSP.jl
. See Convolutions
.
For 2D and multi dimensional arrays you may use the convolutions in ImageFiltering.jl
implemented by imfilter()
.
Pay attention that by default it applies correlation. You may change that by applying reflect()
on the kernel.
Personally, I wish for a method which is well optimized (Wrapping Intel IPP) which works on arrays in general and not tied to DSP
or Images
context.
For small kernels I found StaticKernels.jl
which is the fastest I could find on the Julia eco system.
If one day NNLib.jl
will support the OneDNN
backend (See Use oneDNN · Issue #74 · FluxML/NNlib.jl · GitHub), it might become a good CPU based implementation for convolution / correlation.
Thanks for your answer. I knew convolutions, but it is not the exact implementation in R or Scipy. Scipy implementation is not too complicated. I will rewrite it in Julia.
The DSP methods should be similar to the Scipy ones, see e.g. Translating a 1d convolution from Python to Julia - #4 by rafael.guerra. I think it would be better if you provide some examples of what you’re trying to do and where/why you think they are not behaving the same. Certainly much easier than rewriting your own functions from scratch.
I would like to apply linear convolution filtering to univariate time series similar to R’s stats::filter
. I could not find such a method in Julia; I will use it for seasonal decomposition similar to R’s stats::decompose
or Python’s statsmodels.tsa.seasonal.seasonal_decompose
.
You can also write your own convolution, if (for whatever reason) you don’t like DSP.jl:
julia> using FFTW
julia> toy_conv(a,b) = begin
newlen = length(a)+length(b)-1
pada = [a; zeros(newlen-length(a))]
padb = [b; zeros(newlen-length(b))]
real(ifft(fft(pada) .* fft(padb)))
end
toy_conv (generic function with 1 method)
julia> toy_conv([1,1],[1,1,0])
4-element Vector{Float64}:
1.0
2.0
1.0
0.0
You can also write your own FFT, if (for whatever reason) you don’t like FFTW…
Thank you for your response. I have rewritten the C++ code of R’s stats::filter
in Julia. I will share Julia’s implementation of stats::decompose soon. I have seen other Julia developers need it too