What function represents this log sine wave?

293 Views Asked by At

Please help me find a continuous function suitable for describing a blue dots chart. What is this function like? Thanks. Orange chart is $\ln{x^{\frac{1}{4}}}$

plot one

olot two

1

There are 1 best solutions below

4
On BEST ANSWER

Without exact data it is hard to do anything for certain, but I would do the following:

  1. Fit the baseline (you already did that)
  2. Subtract baseline from your data
  3. To the remainder, try to fit a sinusoid of the form

$$f(x) = g(x) \sin(\omega x + \phi)$$

where $\omega$ and $\phi$ are the angular frequency and the phase and the oscillation and $g(x)$ is some monotonically increasing function. I would try to $g(x) = x^k$ for some constant $k$.

There is a ton of numerical fitting libraries you could use, but honestly you could just guesswork the parameters fast enough I think

Edit: Having had a look at the actual data, I have found that the oscillation frequency was changing with time, so I had to guess that one as well. The final form of the function I arrived at is

$$y(x) = \frac{1}{4}\log x + \frac{1}{16}x^2 \sin(\omega \sqrt{x} + \phi)$$

where $\omega \approx 6.27$ and $\phi \approx 3$. Once again, if you want precise coefficients, you should try to fit the function numerically. Also, I suspect that the baseline is not perfectly described by $\frac{1}{4}\log{x}$, it is a little bit slower than that.

Below is the code I used to arrive at this conclusion

# 1. Plot Data
plt.figure(figsize=(10,10))
plt.plot(x, y)
plt.show()

# 2. Fit Baseline
plt.figure(figsize=(10,10))
plt.plot(x, y)
plt.plot(x, np.log(x)/4)
plt.show()

#3. Subtracting baseline
ybase = y - np.log(x)/4

plt.figure(figsize=(10,10))
plt.plot(x, ybase)
plt.show()

genv = x**(1/2)/16

#4. Guessing envelope function
plt.figure(figsize=(10,10))
plt.plot(x, ybase)
plt.plot(x, genv)
plt.show()

#5. Dividing by the envelope function
yenv = ybase/genv
plt.figure(figsize=(10,10))
plt.plot(x, yenv)
plt.show()

#6. Guessworking the frequency dynamics by choosing a function of the x-argument
yenv = ybase/genv
plt.figure(figsize=(10,10))
plt.plot(np.sqrt(x), yenv)
plt.show()

#7. Guessworking the absolute frequency prefactor and phase
yenv = ybase/genv
plt.figure(figsize=(10,10))
plt.plot(np.sqrt(x), yenv)
plt.plot(np.sqrt(x), np.sin(np.sqrt(x)*6.3 + 2))
plt.show()

#8. Putting it all together
ytot = np.log(x)/4 + x**(1/2)/16 * np.sin(np.sqrt(x)*6.3 + 2)

plt.figure()
plt.plot(x, y)
plt.plot(x, ytot)
plt.show()