I'm trying to develop a simple analytic expression for a "smoothed" square wave. What I've come up with is
$$y = \frac{\tanh \left(g\ \mathrm{mod}( x/p , 1) \right ) - \tanh \left(g\ \mathrm{mod}(( x/p , 1) - d) \right )}{2}$$
And this produces a fairly pleasant shape (depending on the value of $g$). For reference with $g = 50$ and $d = 0.2$, the resulting plot is
However, I can't think of what transformation I need to do to make sure the derivative is continuous at the start of the period ($x = 0, \pm p, \dots$).
Any thoughts?