using DSP, PyPlot, Polynomials, FFTW, Statistics
using Suppressor
@suppress_out begin
sc = include("WFbyCKMSplus_scripts.jl")
at = include("../AnalysisToolbox.jl")
mrb = include("../WFMR_bs.jl")
mr = include("../WFMR.jl")
whf = include("../WhiteningFilters.jl")
util = include("../Utils.jl")
end
Zeros = 2*rand(10) .- 1
Poles = 2*rand(10) .- 1
[Zeros Poles]
l = coeffs(Polynomial([1])*prod(Polynomial([1, -z]) for z in Zeros))
w = coeffs(Polynomial([1])*prod(Polynomial([1, -z]) for z in Poles))
r = 1.0
N = 10^4; D = 10^3; p = 2;
e = randn(N+D)
pred = at.ARMA_gen(;l, w, r, e, steps = N, discard = D);
A = 2*rand(10) .- 1
f = coeffs(Polynomial([1])*prod(Polynomial([1, -a]) for a in A))
sig = filt(f,pred)
Nex = 2^13; Θ = 2pi*(0:Nex-1)/Nex;
Spred_num = at.z_crossspect_dm(pred,pred;Nex, L = 1500)
Hpred(z) = Polynomial(w)(z)/Polynomial(l)(z)
Spred_ana = map(z -> abs2(Hpred(z)),exp.(im*Θ))
semilogy(Θ,Spred_num, label = "Spred_num")
semilogy(Θ,Spred_ana, label = "Spred_ana")
legend()
Ssig_num = at.z_crossspect_dm(sig,sig;Nex)
Hsig(z) = Polynomial(f)(z)*Hpred(z)
Ssig_ana = map(z -> abs2(Hsig(z)),exp.(im*Θ))
figure()
semilogy(Θ,Ssig_num, label = "Ssig_num")
semilogy(Θ,Ssig_ana, label = "Ssig_ana")
legend()
sig = reshape(sig, 1,:)
pred = reshape(pred, 1,:)
[sig; pred]
function testdisp(h,sig,pred; vew = 90:200, f)
@suppress begin
figure(figsize=(12,4))
title("The filters")
f == 0 || plot(f,"k.-",label = "exact")
plot(real(h[:]),"r.:",label = "approx")
xlabel("lag"); legend()
end
sig_hat = at.my_filt(h,pred);
vew = 90:200
res = util.TakeLook(sig,sig_hat; vew)
suptitle("A trajectory and Error over a Window")
println("MSE: ",var(res[100:end]))
end
# Benchmark
h = @timed mrb.get_wf_bs(sig,pred; M_out = 20)
tim = h.time; h = h.value
testdisp(h,sig,pred; f)
println("Time: ",tim," sec")
# Benchmark
h = @timed mr.get_wf(sig,pred; M_out = 20)
tim = h.time; h = h.value
testdisp(h,sig,pred; f)
println("Time: ",tim," sec")
# Benchmark
h = @timed sc.vector_wiener_filter_fft(sig,pred, maxit = 1)
tim = h.time; h = h.value
testdisp(h,sig,pred; f)
println("Time: ",tim," sec")
# Benchmark
h = @timed sc.vector_wiener_filter_fft(sig,pred, maxit = 2)
tim = h.time; h = h.value
testdisp(h,sig,pred; f)
println("Time: ",tim," sec")
# Benchmark
h = @timed sc.vector_wiener_filter_fft(sig,pred, maxit = 3, par = 1000, verb = true)
tim = h.time; h = h.value
testdisp(h,sig,pred; f)
println("Time: ",tim," sec")