JuliaWaveScattering / MultipleScattering.jl

A Julia library for simulating, processing, and plotting multiple scattering of waves.
Other
46 stars 12 forks source link

An easy to use type impulse #23

Closed arturgower closed 2 years ago

arturgower commented 6 years ago

Currently the struct impulse is very elegant: it has two fields, which are functions representing the impulse in time and frequency (one being the analytic Fourier Transform of the other). However, I think the struct should be easy to use and understand for the most common cases of use. These are: 1) simple analytic functions like a discrete delta and Gaussian 2) providing a discrete impulse in either time (most common) or frequency. This is always the case when comparing with experiments.

In both cases, it should be easy to plot both the impulse in time and frequency, even if the user only provided the impulse in, say, time. Currently I think it is not easy to provide 2, and even the inability to plot the discrete delta function in 1 will confuse most. For example, after sampling the discrete delta in frequency, it can be useful to look at the resulting impulse in time, and vice-versa (a common exercise in signal processing). It helps decide how to sample the frequency.

I think it will make our lives easier to use instead

struct Impulse{T<:AbstractFloat}
    in_time::Vector{T}
    in_freq:::Vector{Complex{T}}
    t::Vector{T}
    ω::Vector{T}
end

One draw back is that it seems that both the vectors ω and t need to be supplied. But this is not really an issue in practice, and, for example, the impulse in time can be easily re-sampled from the impulse in frequency for a different t vector.

Although the struct impulse is elegant, and is more flexible than above, there is no clear example where this flexibility is needed. And I think it is not worth the added complications of trying to convert impulse vectors to functions.

jondea commented 6 years ago

I suppose there's no reason not to have both, one called DiscreteImpulse and the other ContinuousImpulse. Users wouldn't even have to see them, they'd just use the most relevant constructor and multiple dispatch will decide how to compute with them.