General Formula for Delayed Cosine Function?

230 Views Asked by At

I essentially need a cosine function that "delays" its peaks. I need to be able to control the length of the delay and the length of each peak. I've gotten close with the following formula, but it has some problems:

$$\frac{pi}{a}<mod(x,d\pi)<d\pi-\frac{pi}{a}:-1, \cos(ax)$$

In this formula, $a$ is the parameter that controls the length of each peak and $d$ controls the length of the delay; the problem is that it only works for $d\in\{2,4,6,...\}$ and for $a\in\{1,2,3,4,...\}$ but I want it to work (be continuous) for all real $d>2$ and for all real $a>1$.

How can I fix the formula to do that? Here's a video showing the problems: https://www.youtube.com/watch?v=OftnCvr4ecQ&feature=youtu.be

Also, here's the Desmos link: https://www.desmos.com/calculator/ji1mcrbheq

1

There are 1 best solutions below

1
On BEST ANSWER

Well, I'd separate the problem into two parts - (1), finding a function that represents a single one of the "bumps" you want, and (2), finding a way to repeat them periodically along the $x$-axis.

Define the parameters $a =$ the width of each "cosine bump" at its base, and $d =$ the distance between each successive peak.

For part (1): define your "cosine bump function" (no, it's not a real bump function in the sense of being non-analytic and smooth, but it still looks like a bump, so let's roll with it) piecewise, as $$ f_0(x) = \begin{cases} \cos\left(\dfrac{2\pi x}{a}\right), & |x| \le \dfrac{a}{2} \\ -1, & \dfrac{a}{2} \lt |x| \le d \end{cases}$$

For part (2): you just need a function that looks like the identity function modulo $d$, but also re-centered to the center of each bump. You could just use that, directly: $$ p(x)= \left(\left(x + \frac{d}{2}\right) \;\mathrm{mod}\;d \right) - \frac{d}{2} $$

Or, if you want something that doesn't invoke $\mathrm{mod}$, an appropriate transformation of the floor function works just as well (personally, I like this one better): $$ \newcommand{\floor}[1]{\left\lfloor#1\right\rfloor} p(x) = x - d\floor{\frac{x}{d} + \frac{1}{2}} $$

(Note, if $a > d$, then your bumps touch each other before flattening out, and there will be no flat stretches. I took care to define $p(x)$ symmetrically about the center of each bump, so that each copy of $f_0(x)$ would at least join at a kink in this case. Also, if $a = d$, then you just have an ordinary cosine function, with period $a$.)

Finally, the function you want is just $$ f(x) = f_0(p(x)) $$

Here is the Desmos graph that lets you play around with $a$ and $d$, and see the bumps widen / separate, respectively.