another dev commit
This commit is contained in:
parent
9aad4f303b
commit
937fce822f
5 changed files with 51 additions and 47 deletions
15
src/ISM.jl
15
src/ISM.jl
|
@ -1,22 +1,24 @@
|
||||||
export ISM
|
export ISM
|
||||||
|
|
||||||
function ISM(
|
function ISM(
|
||||||
array::TxRxArray,
|
|
||||||
tx::TxRx,
|
tx::TxRx,
|
||||||
|
array::TxRxArray,
|
||||||
room::AbstractRoom,
|
room::AbstractRoom,
|
||||||
config::ISMConfig;
|
config::ISMConfig;
|
||||||
)
|
)
|
||||||
Pn, o, B = array.p, array.origin, array.B
|
rxs, origin, B = array.txrx, array.origin, array.B
|
||||||
[ISM(TxRx(B*p.position+o, B*p.B, p.directivity), tx, room, config) for p in Pn]
|
l2g = rx -> TxRx(B * rx.position + origin, B * rx.B, rx.directivity)
|
||||||
|
[ISM(tx, rx |> l2g, room, config) for rx in rxs]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
function ISM(
|
function ISM(
|
||||||
rxs::AbstractVector{<:TxRx},
|
|
||||||
tx::TxRx,
|
tx::TxRx,
|
||||||
|
rxs::AbstractVector{<:TxRx},
|
||||||
room::AbstractRoom,
|
room::AbstractRoom,
|
||||||
config::ISMConfig;
|
config::ISMConfig;
|
||||||
)
|
)
|
||||||
|
@ -25,13 +27,12 @@ end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
"""
|
||||||
function ISM(
|
function ISM(
|
||||||
rx::TxRx,
|
|
||||||
tx::TxRx,
|
tx::TxRx,
|
||||||
|
rx::TxRx,
|
||||||
room::RectangularRoom,
|
room::RectangularRoom,
|
||||||
config::ISMConfig;
|
config::ISMConfig;
|
||||||
)
|
)
|
||||||
|
@ -53,7 +54,7 @@ function ISM(
|
||||||
|
|
||||||
if config.hp
|
if config.hp
|
||||||
return AllenBerkley_highpass100(h, config.fs)
|
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)
|
# AllenBerkley_highpass100!(h, config.fs)
|
||||||
# return h
|
# return h
|
||||||
else
|
else
|
||||||
|
|
|
@ -15,6 +15,7 @@ include("utils.jl")
|
||||||
include("ISM.jl")
|
include("ISM.jl")
|
||||||
include("moving_sources.jl")
|
include("moving_sources.jl")
|
||||||
|
|
||||||
|
export WASN
|
||||||
include("WASN.jl")
|
include("WASN.jl")
|
||||||
|
|
||||||
end # module
|
end # module
|
||||||
|
|
17
src/WASN.jl
17
src/WASN.jl
|
@ -16,11 +16,7 @@ struct Node
|
||||||
δ::Real
|
δ::Real
|
||||||
end
|
end
|
||||||
|
|
||||||
function Node(rx, δ=0.0)
|
struct Event # NOTE: TxNode może będzie lepszą nazwa?
|
||||||
Node(rx, δ)
|
|
||||||
end
|
|
||||||
|
|
||||||
struct Event
|
|
||||||
tx::TxRx
|
tx::TxRx
|
||||||
emission::Real
|
emission::Real
|
||||||
fs::Real
|
fs::Real
|
||||||
|
@ -33,8 +29,12 @@ function synth_events(
|
||||||
room::AbstractRoom,
|
room::AbstractRoom,
|
||||||
rir_config::AbstractRIRConfig,
|
rir_config::AbstractRIRConfig,
|
||||||
)
|
)
|
||||||
hs = [ISM(nodes[i].rx, events[j].tx, room, rir_config) for i in eachindex(nodes), j in eachindex(events)]
|
hs = Matrix{Vector{Vector{Float64}}}(undef, nodes |> length, events |> length)
|
||||||
s = [[conv(h, events[j].signal) for h in hs[i, j]] for i in eachindex(nodes), j in eachindex(events)]
|
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)
|
(signals=s, hs=hs)
|
||||||
end
|
end
|
||||||
|
@ -54,9 +54,10 @@ function synthesise(
|
||||||
# Find length of the output signal
|
# Find length of the output signal
|
||||||
δ_max = [node.δ for node ∈ nodes] |> maximum;
|
δ_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 = [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
|
# 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)
|
for i ∈ eachindex(nodes), j ∈ eachindex(events)
|
||||||
shift_n = floor(Int, (events[j].emission + nodes[i].δ)*fs)
|
shift_n = floor(Int, (events[j].emission + nodes[i].δ)*fs)
|
||||||
|
|
|
@ -5,11 +5,12 @@ export h2RT60, Sabine_RT60
|
||||||
|
|
||||||
"""
|
"""
|
||||||
function h2RT60(h::AbstractVector{<:Number}, Fs::Real)
|
function h2RT60(h::AbstractVector{<:Number}, Fs::Real)
|
||||||
cs = cumsum(reverse(h.^2))
|
dB(x) = 10log10(x)
|
||||||
edc = 10*log10.(reverse(cs./cs[end])) # energy decay curve
|
normalize(x) = x ./ x[begin]
|
||||||
|
edc = h .|> abs2 |> reverse |> cumsum |> reverse |> normalize .|> dB
|
||||||
|
|
||||||
ind = findfirst(edc .<= -60. )
|
ind = findfirst(edc .<= -60. )
|
||||||
if ind == nothing
|
if ind === nothing
|
||||||
rt = length(h)/Fs
|
rt = length(h)/Fs
|
||||||
else
|
else
|
||||||
rt = ind/Fs
|
rt = ind/Fs
|
||||||
|
|
Loading…
Reference in a new issue