42 lines
1 KiB
Julia
42 lines
1 KiB
Julia
using Plots
|
|
using DSP
|
|
using CSV
|
|
using ControlSystems
|
|
|
|
pyplot()
|
|
|
|
# Parameters
|
|
filename = joinpath(@__DIR__, "data", "walk.csv") # input file
|
|
h = 1/22 # sample time
|
|
orders = [
|
|
(title="quadratique", order=2, sizes=5:2:11),
|
|
(title="cubique", order=3, sizes=5:2:11),
|
|
(title="big_quadra", order=2, sizes=11:10:51)
|
|
]
|
|
|
|
|
|
function savgol(size::Int64, poly_order::Int64, deriv::Int64=0, delta::Float64=1.0, conv::Bool=false)
|
|
half_size, rem = divrem(size, 2)
|
|
if rem == 0
|
|
throw(ArgumentError("size must be odd."))
|
|
end
|
|
M = [-half_size:half_size;] .^ [0:poly_order;]';
|
|
y = zeros(poly_order+1)';
|
|
y[deriv+1] = factorial(deriv) / delta^deriv;
|
|
scal = y*inv(M'*M)*M'
|
|
if conv
|
|
scal = scal[end:-1:1]
|
|
end
|
|
scal
|
|
end
|
|
|
|
plot(title="Comparaison de tailles de filtres")
|
|
for size in orders[3].sizes
|
|
filter = savgol(size, 2, 1, h, true)
|
|
H = tf(filter, [1], h)
|
|
mag, phase, w = bode(H)
|
|
plot!(w,log.(mag[:,1]), label=string(size, " points"))
|
|
end
|
|
savefig(joinpath(@__DIR__, "results", "savgol_bode.eps"))
|
|
show()
|