1

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?

ygoe
  • 111

2 Answers2

1

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

Raymond Manzoni
  • 43,021
  • 5
  • 86
  • 140
  • ($x\mapsto x-a,\sin(x/2)$ appears nicer in $(0,2\pi)$ but is reverted in the following interval) – Raymond Manzoni Dec 09 '18 at 21:34
  • Hm, I've tried it but the result's didn't look too good. Especially the selection of the midpoint is very limited. But the idea of putting another function before the sin(x) is interesting. I'll have to play with that for a bit. – ygoe Dec 09 '18 at 22:22
  • I've found something interesting. A Bézier curve might be helpful to build a smooth connection from the first to the second section. Then apply sin on that. I'll look into that tomorrow. – ygoe Dec 09 '18 at 22:47
  • The Bézier function indeed did lead to a curve similar to what I had in mind. There's a JavaScript implementation of it which I ported to C# for my case. https://github.com/gre/bezier-easing I use control points that are symmetric so that there's no break when repeating the pattern. The resulting "easing" value is then put into sin(). – ygoe Dec 12 '18 at 20:41
  • Thanks for the follow up @ygoe! You may propose your solution as an answer here, excellent continuation, – Raymond Manzoni Dec 12 '18 at 22:50
0

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)$

Ross Millikan
  • 374,822
  • While that's simple and comprehensible, there's a break at the midpoint where the curve suddenly changes direction. It's not smooth. (Forgive me my simple math words, I've learnt them in German only at school, long ago.) – ygoe Dec 09 '18 at 22:23
  • True, there is a break in the derivative. You have five points based on what you specified. You can put any curve you want through them. You could use a Bezier curve, which is continuous through the second derivative, but is harder to derive. – Ross Millikan Dec 09 '18 at 22:47