UnderwaterAcoustics.jl
UnderwaterAcoustics.jl copied to clipboard
Complex signal required for SampledAcousticSource when using Propagation Models?
Hello and Happy New Year!
I was having fun with this package and wanted to try sending some more generic signals through the acoustic simulation API. No issues creating the Tx and looking at the signal.
env = UnderwaterEnvironment()
pm = PekerisRayModel(env,8)
rx = AcousticReceiver(500.0, -10.0)
tx = SampledAcousticSource(0, 0, -5.0, cos.(collect(1:1000)./10.0); fs=1000.0)
record(tx, 1.0, 1000.0)
When I try to run this with the propagation model things break.
record(pm, tx, rx, 1.0, 1000.0;)
InexactError: Float64(-0.0010541008282025442 + 0.000582555920034865im)
Looking through the source is seems like Pinger
, etc., generate in-phase and quadrature signal components using cis
. Indeed if I run
tx = SampledAcousticSource(0, 0, -5.0, cis.(collect(1:1000)./10.0); fs=1000.0)
it works fine, as far as I can tell. Maybe some stronger typing is necessary here? It's also confusing to have the simpler command above work fine, though I understand why this is the case?
Thanks, Graham
The propagation modeling API is designed to work on complex analytic signals, as the phase of the signal needs to be carried through the propagation model (since reflecting boundaries or caustics can introduce phase changes). Hence you need the cis
, rather than the cos
. For a more general real passband signal x
, you can simply do analytic(x)
to get the complex passband signal.
We should improve the documentation to make it clearer.
Thanks for the clarification! Doc update would indeed be helpful, though you could still consider typing the signal as an Array{Complex}
to prevent amateurs such as myself getting confused.
Yes, thanks for the feedback. In fact, I will see if I can do a step better and automatically promote the array to an analytic version if you pass in a real one, and convert the output back to real in that case.
Already fixed along the way... automatically promotes to complex analytic: (tested with v0.3.0)
julia> env = UnderwaterEnvironment();
julia> pm = PekerisRayModel(env,8);
julia> rx = AcousticReceiver(500.0, -10.0)
UnderwaterAcoustics.BasicAcousticReceiver{Float64}((500.0, 0.0, -10.0))
julia> tx = SampledAcousticSource(0, 0, -5.0, cos.(collect(1:1000)./10.0); fs=1000.0);
SampledAcousticSource{Float64, Float64, MetaArrays.MetaArray{Vector{Float64}, SignalAnalysis.SamplingInfo, Float64, 1}}((0.0, 0.0, -5.0), 15.987461914087758, [...])
julia> record(tx, 1.0, 1000.0)
SampledSignal @ 1000.0 Hz, 1000-element view(PaddedView(0.0, OffsetArray(::Vector{Float64}, 1:1000), (1:1000,)), 1:1000) with eltype Float64:
0.9950041652780258
0.9800665778412416
⋮
0.80745865769955
0.8623188722876839
julia> record(pm, tx, rx, 1.0, 1000.0)
SampledSignal @ 1000.0 Hz, 1000-element Vector{ComplexF64}:
541289.5256436621 + 413918.1556491197im
778671.6830371993 + 178283.27662377933im
⋮
306054.7486357424 + 5918.184271510494im
900566.348229628 + 186808.38614732752im