Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
hurak opened this issue Nov 29, 2021 · 6 comments
Open

Comments

@hurak
Copy link

hurak commented Nov 29, 2021

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
Copy link

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
Copy link
Owner

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

@hurak
Copy link
Author

hurak commented Oct 7, 2024

I am afraid that the code

sign.(randn(N))

does not produce a PRBS signal.

@baggepinnen
Copy link
Owner

baggepinnen commented Oct 7, 2024

How do you define PRBS? It's psudo random since it's deterministic given the random seed. It's also binary, taking only values {-1, 1}, so to me it's a psudo-random binary signal.

@hurak
Copy link
Author

hurak commented Oct 7, 2024

You are right that the signal generated by sign.(randn(N)) is pseudorandom for a given seed, and it is also binary because of the sign function. Perhaps this is indeed what qualifies it as a PRBS. I am not much familiar with the conventions in the SysID domain, but I thought that the particular name of PRBS is reserved only for the outcomes of those Linear Feedback Shift Registers (LFSR). And these have some useful properties such as an easy possibility to set the frequency content. If instead you filter a random discrete-time signal and then do the sign function, is the frequency content really preserved? This is how it is offered in the System Identification Toolbox for Matlab: https://www.mathworks.com/help/ident/ref/idinput.html#bvjg0km-1, which in turn builds on Ljung's popular textbook.

@baggepinnen
Copy link
Owner

The shift-register method is just a simple way to generate a PRBS signal, that also happens to be trivial to implement on an embedded device without libraries.

If instead you filter a random discrete-time signal and then do the sign function, is the frequency content really preserved?

It is not, the application of sign adds some high-frequency components back in. However, I'm not sure if matlab's version allows you to pick a precise spectrum either? It allows you to pick a period, which is of course easy to to with repeat in julia

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants