insert_impuse

This commit is contained in:
zymon 2024-06-10 16:29:11 +02:00
parent 9c922f79bf
commit f00ca2cbc9

View file

@ -108,14 +108,14 @@ function image_source_generator(
rx_DoA = isp ./ d rx_DoA = isp ./ d
# Compute receiver directivity gain # Compute receiver directivity gain
rx_DG = directivity_pattern(SVector{3}(rx_DoA), rx.B, rx.directivity) rx_DG = directivity_pattern(rx_DoA, rx.B, rx.directivity)
# Direction of Arrival of ray coming out from transmitter to wall # Direction of Arrival of ray coming out from transmitter to wall
perm = (abs(n - q) + abs(n), abs(l - j) + abs(l), abs(m - k) + abs(m)) perm = (abs(n - q) + abs(n), abs(l - j) + abs(l), abs(m - k) + abs(m))
tx_DoA = @. -rx_DoA * (-1, -1, -1).^perm tx_DoA = @. -rx_DoA * (-1, -1, -1).^perm
# Compute transmitter directivity gain # Compute transmitter directivity gain
tx_DG = directivity_pattern(SVector{3}(tx_DoA), tx.B, tx.directivity) tx_DG = directivity_pattern(tx_DoA, tx.B, tx.directivity)
# Compute attenuation coefficient # Compute attenuation coefficient
A = tx_DG * rx_DG * prod(b) / (4π * d) A = tx_DG * rx_DG * prod(b) / (4π * d)
@ -127,6 +127,23 @@ function image_source_generator(
end end
function insert_impuse!(h, A, τ, impulse_width, fs, Δt, twid, ω, N)
# Compute range of samples in transfer function
a = impulse_width / 2
i_s = max(ceil(Int, (τ - a) * fs) + 1, 1) # start
i_e = min(floor(Int, (τ + a) * fs) + 1, N) # end
# Insert yet another impulse into transfer function
for i i_s:i_e
t = (i - 1) * Δt - τ # time signature
w = fma(cos_fast(ω*t), 0.5, 0.5) # Hann window
x = twid * t
sinc = ifelse(iszero(x), 1.0, sin_fast(x)/x)
@inbounds h[i] += w * A * sinc
end
end
""" """
References: References:
[1] J. B. Allen and D. A. Berkley, “Image method for efficiently simulating smallroom acoustics, The Journal of the Acoustical Society of America, vol. 65, no. 4, Art. no. 4, Apr. 1979, doi: 10.1121/1.382599. [1] J. B. Allen and D. A. Berkley, “Image method for efficiently simulating smallroom acoustics, The Journal of the Acoustical Society of America, vol. 65, no. 4, Art. no. 4, Apr. 1979, doi: 10.1121/1.382599.
@ -147,22 +164,10 @@ function ISM!(
ω = 2π / config.Wd ω = 2π / config.Wd
twid = π * config.fs twid = π * config.fs
for a in image_source_generator(tx, rx, room, config) for image_source image_source_generator(tx, rx, room, config)
a |> isnothing && continue image_source |> isnothing && continue
A, τ, _, _ = image_source
A, τ, _, _ = a insert_impuse!(h, A, τ, config.Wd, config.fs, Δt, twid, ω, config.N)
# Compute range of samples in transfer function
i_s = max(ceil(Int, (τ - config.Wd / 2) * config.fs) + 1, 1) # start
i_e = min(floor(Int, (τ + config.Wd / 2) * config.fs) + 1, config.N) # end
# Insert yet another impulse into transfer function
for i i_s:i_e
t = (i - 1) * Δt - τ # time signature
w = fma(cos_fast(ω*t), 0.5, 0.5) # Hann window
x = twid * t
sinc = ifelse(iszero(x), 1.0, sin_fast(x)/x)
@inbounds h[i] += w * A * sinc
end
end end
end end