I try to generate a sine wave signal with a frequency changing over time. The frequency is randomly defined by generating some random values in the range [0.5, 2]
and interpolating the points between them.
The expected output signal is a sine wave with a non-changing amplitude and a changing frequency.
But there are some smaller bumps and the signal is not a 'smooth' sine wave. E.g. the period at x = 200
should be larger than the period at x = 10
, but the opposite is the case.
Does anyone know, what happened here?
import numpy as np
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt
x_samples = np.arange(-100, 3100, 50)
freq_samples = np.random.random(x_samples.shape) * 1.5 + 0.5
x = np.arange(0, 3000, 0.1)
interpolation = interp1d(x_samples, freq_samples, kind='quadratic')
freq = interpolation(x)
y = np.sin(freq * x)
plt.plot(x, y, label="sin(freq(x) * x)")
plt.plot(x, freq, label="freq(x)")
plt.legend()
plt.show()