Skip to content

Implementing a convolution operator #940

@Jilhg

Description

@Jilhg

Given a (periodic) function $f$ I would like to implement its convolution operator $C_f$, i.e. an operator that I can later apply on a function to give $C_f g = \int dy f(x-y)g(y)$.

After doing some search through the code, I don't think a convolution operator has been implemented in ApproxFun, though as a complete newbie, tbh, I am quite lost in the code. I could imagine a convolution was implemented as least implicitly, because I guess it is used for multiplying two functions over any Fourier space.

I managed to implement and explicit convolution for two functions on a Laurent() space. This is convenient, as the convolution basically just amounts to multiplying the coefficients of both functions:

#assume that f and g are Laurent over the same domain
function convolution_approxfun(f,g)
    x0=first(ApproxFunBase.domain(f))
    x1=last(ApproxFunBase.domain(f))
    L=x1-x0
    #fourier index of the n'th coefficient
    fourier_index = [if mod(a,2)==1 div(a-1,2) else -div(a,2) end for a=1:ncoefficients(f)]
    return Fun(Laurent(ApproxFunBase.domain(f)),f.coefficients.*g.coefficients.*L.*exp.(-2*pi*1im/L.*fourier_index*x0))
end

It works, but it is of course not very flexible code (Note the extra phase has to be added in case the interval starts at $x_0 \neq 0$).

The reason I need to implement the convolution operator is that I would like to solve some linear equation that contains a convolution operator. So the above explicit implementation is not enough for me, I need to implement an operator that I can add and multiply to other operators.

From what I understand about the functionality of ApproxFun.jl I think a good implementation would look something like this:

  1. Using a conversion operator to convert a function on any periodic domain to the canonical domain with the canonical space (I think its Fourier()) on it.
  2. Implementing a convolution operator on this canonical space, which is just multiplying the coefficients
  3. Using a conversion operator to convert the function back to the original domain/space

I have the feeling all of these steps could be very easy to implement, but I am lacking the detailed understanding of how ApproxFun.jl works in the background. I would be great if someone could help me with that: How do I implement a custom operator in general? How do I take care of the conversion properly?

PS: In case others agree I would be great to add convolution operators to the general functionality of ApproxFun in the future. At least for me convolution operators appear frequently in scientific computing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions