another dev commit

This commit is contained in:
zymon 2023-05-16 11:55:55 +02:00
parent 9aad4f303b
commit 937fce822f
5 changed files with 51 additions and 47 deletions

View file

@ -1,22 +1,24 @@
export ISM
function ISM(
array::TxRxArray,
tx::TxRx,
array::TxRxArray,
room::AbstractRoom,
config::ISMConfig;
)
Pn, o, B = array.p, array.origin, array.B
[ISM(TxRx(B*p.position+o, B*p.B, p.directivity), tx, room, config) for p in Pn]
rxs, origin, B = array.txrx, array.origin, array.B
l2g = rx -> TxRx(B * rx.position + origin, B * rx.B, rx.directivity)
[ISM(tx, rx |> l2g, room, config) for rx in rxs]
end
"""
"""
function ISM(
rxs::AbstractVector{<:TxRx},
tx::TxRx,
rxs::AbstractVector{<:TxRx},
room::AbstractRoom,
config::ISMConfig;
)
@ -25,13 +27,12 @@ end
"""
"""
function ISM(
rx::TxRx,
tx::TxRx,
rx::TxRx,
room::RectangularRoom,
config::ISMConfig;
)
@ -53,7 +54,7 @@ function ISM(
if config.hp
return AllenBerkley_highpass100(h, config.fs)
# Zmień to na funkcie operującą na zaalokowanym już h
# TODO: Zmień to na funkcie operującą na zaalokowanym już h
# AllenBerkley_highpass100!(h, config.fs)
# return h
else

View file

@ -15,6 +15,7 @@ include("utils.jl")
include("ISM.jl")
include("moving_sources.jl")
export WASN
include("WASN.jl")
end # module

View file

@ -16,11 +16,7 @@ struct Node
δ::Real
end
function Node(rx, δ=0.0)
Node(rx, δ)
end
struct Event
struct Event # NOTE: TxNode może będzie lepszą nazwa?
tx::TxRx
emission::Real
fs::Real
@ -33,8 +29,12 @@ function synth_events(
room::AbstractRoom,
rir_config::AbstractRIRConfig,
)
hs = [ISM(nodes[i].rx, events[j].tx, room, rir_config) for i in eachindex(nodes), j in eachindex(events)]
s = [[conv(h, events[j].signal) for h in hs[i, j]] for i in eachindex(nodes), j in eachindex(events)]
hs = Matrix{Vector{Vector{Float64}}}(undef, nodes |> length, events |> length)
iter = Iterators.product(nodes |> eachindex, events |> eachindex) |> collect
Threads.@threads for (i,j) iter
hs[i,j] = ISM(events[j].tx, nodes[i].rx, room, rir_config)
end
s = [[conv(h, events[j].signal) for h in hs[i, j]] for i eachindex(nodes), j eachindex(events)]
(signals=s, hs=hs)
end
@ -54,9 +54,10 @@ function synthesise(
# Find length of the output signal
δ_max = [node.δ for node nodes] |> maximum;
N = [ceil(Int, (events[j].emission + δ_max)*fs) + length(e_signal[1, j][1]) for j eachindex(events)] |> maximum
N += floor(Int, fs)
# Allocate memory for output signals
output = [zeros(N, node.rx.p |> length) for node nodes]
output = [zeros(N, node.rx.txrx |> length) for node nodes]
for i eachindex(nodes), j eachindex(events)
shift_n = floor(Int, (events[j].emission + nodes[i].δ)*fs)

View file

@ -5,11 +5,12 @@ export h2RT60, Sabine_RT60
"""
function h2RT60(h::AbstractVector{<:Number}, Fs::Real)
cs = cumsum(reverse(h.^2))
edc = 10*log10.(reverse(cs./cs[end])) # energy decay curve
dB(x) = 10log10(x)
normalize(x) = x ./ x[begin]
edc = h .|> abs2 |> reverse |> cumsum |> reverse |> normalize .|> dB
ind = findfirst(edc .<= -60. )
if ind == nothing
if ind === nothing
rt = length(h)/Fs
else
rt = ind/Fs