Delay in control loops

It’s pretty cool you’re using reorganization for this. Maybe it is a bit finicky because of the sin function (in the part where you generate the pattern from reorganized parameters theta). When the frequency argument to the sine function (f) changes, but the phase does not change, there could be some discontinuities in the output signal. Here is a plot, f changes from 1 to 1.5 at t=5s, and then the signal shifts to a different position in the cycle, which might create a large error.

image

This may be one of the reasons people use oscillators. In electronics, they are called voltage-controlled oscillators (VCO) because the input voltage determines the output frequency, and in software, they are called (surprise) software-controlled oscillators or numerically controlled oscillators, if you wish to google the terms.

Here is how ti behaves with the change in frequency:

image

minimal example code

In this case, it is only needed to reorganize frequency because the phase will just shift automatically when you change f (I think).