Creating a Pseudo-Cyclic signal using a cyclic signal
I am looking for a way using numpy or pytorch to skew a tensor.
For example given an array of samples of sin(x), i hope to get a skewed version of it (preferably the same size) such that the cycle of the function is either stretched or shrinks or even both (if it can interpolate it randomly), so in some parts the frequency is higher and in some parts lower.
I need to create &quot;pseudo-cyclic&quot; signals which means that they are almost cyclic but not perfectly.

You can play around with (for instance) locally varying frequency. Considering a sine function as a base periodic function, using a locally varying frequency can give &quot;stretched&quot; and/or &quot;dilated&quot; effect.
Example 1: chirp function with linear frequency change (check the wiki page for more information):
import matplotlib.pyplot as plt
import numpy as np

# initialize
n = 1000
x = np.linspace(0, 10, n)

# variying frequency between 2 and 4
f = np.linspace(2, 4, n)
y = np.sin(f * x)

# plot local frequency values and signal
plt.subplot(211)
plt.plot(x, f)
plt.ylabel('Local frequency')
plt.subplot(212)
plt.plot(x, y)
plt.ylabel('signal')
plt.xlabel('samples')
plt.show()

leading to increasing frequency pseudo-periodic signal:

Example 2: varying frequency with arbitrary function (here polynomial):
import matplotlib.pyplot as plt
import numpy as np

# initialize
n = 1000
x = np.linspace(0, 10, n)

# variying frequency between 2 and 4
f = .5 * (2 + (x - 5) ** 2 + 2 * x)
y = np.sin(f * x)

# plot local frequency values and signal
plt.subplot(211)
plt.plot(x, f)
plt.ylabel('Local frequency')
plt.subplot(212)
plt.plot(x, y)
plt.ylabel('signal')
plt.xlabel('samples')
plt.show()

with the following output

Playing around with the frequency function can help getting other pseudo-periodic signal shapes. Also note that scipy comes with a bank of signal generators like sweep_poly from which you can start with in order to get to randomly varying signal frequencies.
