Skip to content

Instantly share code, notes, and snippets.

@darden1
Last active December 9, 2018 14:36
Show Gist options
  • Save darden1/1b8116d3f03da7d719f4485848616374 to your computer and use it in GitHub Desktop.
Save darden1/1b8116d3f03da7d719f4485848616374 to your computer and use it in GitHub Desktop.
sin.py
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(0)
n_sequence = 5
n_data = int(20+1)*n_sequence
a, b = 1., 1.
phase = np.pi / 4
time = np.linspace(0, 1, n_data)
noise_d1 = np.random.rand(n_data) - 0.5
noise_d2 = np.random.rand(n_data) - 0.5
ft = a * np.sin(2*np.pi*time)
fd1 = a * np.sin(2*np.pi*time - phase) + b * noise_d1
fd2 = a * np.sin(2*np.pi*time - 2*phase) + b * noise_d2
X, Y, T = [], [], []
for t in range(0, n_data - n_sequence, 1):
X.append(np.vstack([fd1[t:t+n_sequence], fd2[t:t+n_sequence]]).T)
Y.append([ft[t:t+n_sequence].reshape(-1, 1)])
T.append(time[t+n_sequence-1])
X, Y, T = np.array(X), np.vstack(Y), np.vstack(T)
plt.plot(T, Y[:,-1,:], label="target")
plt.plot(T, X[:,-1,:], label="sample")
plt.legend(loc="best")
plt.title("sample and target")
plt.xlabel("time")
plt.ylabel("amplitude")
plt.xlim([0, 1])
plt.ylim([-2, 2])
plt.grid(True)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment