Looking for a sine curve with custom midpoint

115 Views Asked by At

For a signal generating software, I'm looking for a function that generates a sine-based curve but with a shifted midpoint. Usually, a sine curve looks like this:

in       out  slope
-------------------
0.0 pi    0       1
0.5 pi    1       0
1.0 pi    0      -1
1.5 pi   -1       0
2.0 pi    0       1

I need to move the midpoint from pi to an arbitrary other value, like 0.7 pi or 1.4 pi. The quarter points should still be in the middle of their side, but if they're slightly off to make the curve "look better", that's fine, too. Example:

in       out  slope
-------------------
0.0 pi    0       1
0.7 pi    1       0
1.4 pi    0      -1
1.7 pi   -1       0
2.0 pi    0       1

What function gives me these values?

2

There are 2 best solutions below

2
On

The simplest is to define a piecewise linear function that takes the new $x$ values to the old ones. So let $$y=\begin {cases} \frac x{1.4} & x \le 1.4\pi\\\pi+\frac {x-1.4 \pi}{0.6}&1.4\pi \lt x \le 2\pi \end {cases}$$ and use $\sin (y)$

5
On

Not exactly what you asked for but a derivable periodic function ($a$ is the "control parameter") : $$f_a(x):=\sin\left(x-a\,\sin(x/2)^2\right)$$ $f_1(x)\;$ would produce the smooth :

f_1(x)

The idea is to replace the 'input' identity function $\;x\mapsto x\;$ with something growing more slowly in $(0,2\pi)$ and with derivative $1$ at $2k\pi$ as illustrated here ( $x\mapsto x-a\,\sin(x/2)^2$ ):

modified input


If you want the input function to be linear at the left you may indeed use a cubic curve to come back to the next linear part. I preferred the $\sin$ function in the map :

$$x\mapsto \begin{cases} x-a\,x & x < \pi\\ x-a\,x\dfrac{1-\sin(x-3\pi/2)}2&x \ge \pi \end{cases}$$ half linear

If the first part of the $\sin$ function has to be preserved (stretched only) you'll have to replace the $\,x < \pi\,$ by $\,x < \frac{\pi}{1-a}\,$ with a somewhat more complicated function : $$x\mapsto \begin{cases} x-a\,x & x < \frac{\pi}{1-a}\\ x-\dfrac{a\,x}2\left(1-\sin\left(\dfrac {x-\pi-\frac{\pi}{2(1-a)}}{2-\frac 1{1-a}}\right)\right)&x \ge \frac{\pi}{1-a} \end{cases}$$ In this case we need $\;0\le a\le \dfrac 12\;$ and the second part of the $\sin$ function will collapse entirely for $a=\dfrac 12$.

Final result for $a=0.3$ :

first sin