export revTime,agn,avr_mse,hifft #TODO make this more robust function revTime(h,env, dB = 60.) cs = cumsum(flipdim(h.^2,1),1) edc = 10*log10(flipdim(cs./cs[end],1)) #energy decay curve rt = zeros(Float64,size(h,2)) for i = 1:size(h,2) ind = findfirst(edc[:,i] .<= -dB ) if ind == 0 rt[i] = size(h,1)/env.Fs else rt[i] = ind/env.Fs end end return rt, edc end #add gaussian noise function agn(p::Array{Float64},SNR::Float64) σn = 0. pn = zeros(p) Nt = size(p,1) for kk = 1:size(p,2) σp = var(p[:,kk]) σn = 10^(-SNR/10)*σp pn[:,kk] = p[:,kk]+sqrt(σn)*randn(Nt) end return pn end # creates the hermitian of a signal and takes the ifft function hifft(x::Array{Complex{Float64}},Nt::Int64) real(ifft([x[1:1,:];x[2:end,:];flipdim(conj(x[2:end-iseven(Nt),:]),1)],1)) end """ Compute average normalize error 1/N ∑_i^N || p1[:,i]-p2[:,i] ||^2/ ||p1[:,i]||^2 where N is the number of columns If complex arrays are given these are tranformed into time domain. """ function avr_mse(p1::Array{Float64},p2::Array{Float64}) if size(p1) != size(p2) error("array must have same dimensions") end mse = 0. for i = 1:size(p1,2) mse += norm(p1[:,i]-p2[:,i])^2/norm(p1[:,i])^2 end return 1/size(p1,2)*mse end function avr_mse(p1::Array{Complex{Float64}}, p2::Array{Complex{Float64}}, Nt::Int64) p1 = hifft(p1,Nt) p2 = hifft(p2,Nt) return avr_mse(p1,p2) end avr_mse(p1::Array{Float64},p2::Array{Float64},Nt::Int64) = avr_mse(p1,p2)