I'm trying to generate a wave form that looks like this: square wave with large transitional section

It looks to me like a square wave that has a large transitional section between going from "low" to "high" and back.

Any idea how to generate such a wave mathematically (and/or via some Python library)?

Note also that there is a higher-frequency carrier wave.

  • 5
    $\begingroup$ To me it is more like sum of two sines(?), can you provide a more clear image? $\endgroup$
    – MimSaad
    Oct 29 '16 at 17:30

Try a suitably parameterized function of form:

$$f(t) = \operatorname{clip}\big(a_0\sin(f_0 t) + a_1\sin(f_1 t)\big),$$

where $t$ is time, $f_0$ and $f_1$ are the frequencies and $a_0$ and $a_1$ the amplitudes of two sine waves, and:

$$\operatorname{clip}(x) = \left\{\begin{array}{ll}-1 &\text{if } x < -1\\x &\text{if }-1 \le x \le 1 \\1 &\text{if } x > 1.\end{array}\right.$$

You don't show the scale of the data so the bounds $-1$ and $1$ might be of wrong absolute value. I assumed that the data is zero-centered so there is no zero frequency (bias) term and the bounds look symmetrical in your graph.

  • 2
    $\begingroup$ In your $\mathrm{clip}(x)$, $0$ in the second line should be $x$. Apart from that, the bounds are not necessarily $1$ and $-1$, but $\gamma_1$ and $\gamma_2$, or at least $\gamma$ and $-\gamma$. $\endgroup$
    – msm
    Oct 30 '16 at 8:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.