I would like to model a smooth square wave function (see graph) but be able to control the amount of smoothness from fairly soft as shown to quite hard.
But I want to control the amount of smoothness using a simple function so the more the graph goes to a crest or peak the more compressed it becomes depending on some parameter that I can adjust.
I thought something sine logarithmic as that tends to compress but could not get that to work. I also want to avoid such things as the sgn function or Fourier series.



A generic method for drawing a controllable "smoothed" version of a function that is sharp:
Playing with more sophisticated kernels will give you more freedom and control.