I’m not sure if I understood the problem correctly, but perhaps just pass the coefficients and offsets as parameters? Something like
function dy(y, δx, coeffs, offsets)
N = length(y)
dy = zeros(N)
for j in eachindex(y)
denom = 32*δx # and something else near the edges?
dy[j] = sum(y[j+i]*c for (i,c) in zip(offsets,coeffs) if j+i in eachindex(y)) / denom
end
dy
end
(I’m not sure what that denominator is for and where the numbers 32,8,2 come from).
You might want to take a look at ImageFiltering.jl
, and specifically ImageFiltering.imfilter
. It does exactly what it seems you are trying to do, except maybe near the edges (since I’m not sure what is going on near the edges in your code).