baggepinnen / ControlSystemIdentification.jl

System Identification toolbox, compatible with ControlSystems.jl
https://baggepinnen.github.io/ControlSystemIdentification.jl/dev
MIT License
132 stars 13 forks source link

Feature request: generator of some standard input signals such as PRBS #82

Open hurak opened 2 years ago

hurak commented 2 years ago

It would be useful to have some functionality similar to Matlab's idinput for generating some standard input signals such as PRBS.

I have only found some PRBS generator withing some telecom package.

jamestjsp commented 1 year ago

I came to report this request!! I used to use a python package called SIPPY they have a helper function for GBN. https://github.com/CPCLAB-UNIPI/SIPPY/blob/0a542bd259600d486b5a90a8a892e598fe6a0878/sippy/functionset.py#L25

baggepinnen commented 1 year ago

A PRBS signal can easily be generated by

sign.(randn(N))

and to give it a certain frequency content, you could filter the random signal before taking the sign. Another useful signal is a chirp, which can be generated using

"""
    chirp(Ts, f0, f1, Tf; logspace = true)

A [chrip signal](https://en.wikipedia.org/wiki/Chirp) between frequencies (Hz) `f0` and `f1` with sample time `Ts` and duration `Tf` (seconds). `logspace` determines if the frequency change is logarithmic or linear. For experiments, it makes sense to use `logspace=true` to get a similar number of periods of excitation for all frequencies. A chirp with logarithmically spaced frequencies is also called an exponential chirp, or geometric chirp.
"""
function chirp(Ts, f0, f1, Tf; logspace=true)
    t = range(0, step=Ts, stop=Tf)
    N = length(t)
    f = logspace ? exp10.(LinRange(log10(f0), log10(f1), N)) : LinRange(f0, f1, N)
    q = @. sin(2π*f*t)
    reshape(q, :, 1)
end