I did not expect the macro approach to work like this, either; however, I tried this based on this thread. To demonstrate:
ff = Signal(0.0)
gg = @medWin(ff,3)
for i=1:10
push!(ff, i)
println("ff is ", ff.value)
println("gg is ", gg.value)
println("-----")
end
Gives desired output for gg (median of last 3 values of f):
ff is 1.0
gg is 0.5
-----
ff is 2.0
gg is 1.0
-----
ff is 3.0
gg is 2.0
-----
ff is 4.0
gg is 3.0
-----
ff is 5.0
gg is 4.0
-----
ff is 6.0
gg is 5.0
-----
ff is 7.0
gg is 6.0
-----
ff is 8.0
gg is 7.0
-----
ff is 9.0
gg is 8.0
-----
ff is 10.0
gg is 9.0
-----
And, i forgot to include my lastX function:
function lastX(u::Signal, n ::Int)
sigs = Array{Signal}(1,n+1)
sigs[1] = u
for i=1:n
sigs[i+1] = previous(sigs[i])
end
return zip(sigs[2:end]...)
end