Commit 0aaeecc3 authored by Fredrik Bagge Carlson's avatar Fredrik Bagge Carlson
Browse files

add reference generator

parent 5fdd4935
......@@ -61,6 +61,7 @@ for (i,t) = enumerate(0:h:duration)
end
```
Often one finds the need to implement a stateful controller, i.e., a function
that has a memory or state. To this end, the function [`sysfilter`](@ref) is
provided. This function is used to implement control loops where a signal is
......
......@@ -9,6 +9,7 @@ include("interface_documentation.jl")
include("interface_implementations/ballandbeam.jl")
include("utilities.jl")
include("reference_generators.jl")
include("controllers.jl")
end # module
export PRBSGenerator
#PRBS
"""
r = PRBSGenerator(state = 1)
Generates a pseudo-random binary sequence. Call like `random_input = r()`.
"""
mutable struct PRBSGenerator
state::Int
end
PRBSGenerator() = PRBSGenerator(Int(1))
function (r::PRBSGenerator)(args...)
state = r.state
bit = ((state >> 0) (state >> 2) (state >> 3) (state >> 5) ) & 1
r.state = (state >> 1) | (bit << 15)
bit
end
using LabProcesses
using Base.Test
# write your own tests here
@test 1 == 2
# Reference generators
r = PRBSGenerator(Int(1))
seq = [r() for i = 1:10]
@test all(seq .== [0, 0, 1, 0, 0, 1, 1, 0, 0, 1])
foreach(r,1:10_000)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment