Equation for a smooth staircase function

Here is an example based on Math536's answer: Wolfram link

$$f(h,w,a,x) = h \left[\frac{\tanh \left( \frac{ax}{w}-a\left\lfloor \frac{x}{w} \right\rfloor-\frac{a}{2}\right)}{2\tanh\left(\frac{a}{2}\right) } + \frac{1}{2} + \left\lfloor \frac{x}{w} \right\rfloor\right]$$

Where h is the step height, w is the period, and a is the smoothness


We can start with a simple soft staircase function:

$$ f(x) = x - sin \space x $$

and then feed it into itself:

$$ y(x) = f(f(x)) $$

then again:

$$ y(x) = f(f(f(x))) $$

and again:

$$ y(x) = f^4(x) $$

As you can see, each iteration makes the "flat" part of the step longer, and the rise steeper.

enter image description here enter image description here enter image description here enter image description here

The period and the height of each step is $ 2 \pi $, so multiply $x$ by $2 \pi / w$ and $y$ by $h / 2 \pi$ to reach your desired scale.

In reality, the curve is only truly flat (zero derivative) at the centre of each step — at every $ 2 \pi k $ — and only close to flat on either side of that point.

Configurability is limited: The softness of the step can only be specified in integer amounts (the number of times we reapply $f$ to itself), and it requires many/infinite applications to make the step really sharp.


Let $s : [0,1] \to [0,1]$ be a smooth function representing a single step. Assume that there exists some $\epsilon > 0$ such that $s(x) = 0$ for all $x < \epsilon$ and $s(x) = 1$ for all $x > 1 - \epsilon$. Setting $$ f(x) = s(x - \lfloor x \rfloor) + \lfloor x \rfloor$$ then gives us a smooth staircase with steps of height and width $1$. By rescaling $f$, we can get steps of arbitrary width $w$ and height $h$: $$f(h,w,x) = h f(x/w) = h(s(x/w - \lfloor x/w \rfloor) + \lfloor x/w \rfloor).$$

Tags:

Functions