modelling smooth square wave function

1.4k Views Asked by At

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.

clipped sine wave enter image description here

2

There are 2 best solutions below

0
On

A generic method for drawing a controllable "smoothed" version of a function that is sharp:

  1. Generate the "sharp" function as a time series $S=\{s_0,s_1,\cdots\}$
  2. Convolve $S$ with a smoothing kernel, e.g. $[{1 \over 4},{1\over 2},{1\over4}]$
  3. If it is not smooth enough, convolve again.

Playing with more sophisticated kernels will give you more freedom and control.

1
On

You can obtain a $1$- parameter smooth approximation starting from the approximation for the sign function, i.e:

$$\sin x /\sqrt{\sin^2 x +\varepsilon ^2} \quad |\; \varepsilon \to 0$$

example

sin_approx_1