[5a2c8f]: / Sine Generation / data_generation.py

Download this file

47 lines (37 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
"""
Created on Tue Dec 24 20:25 2019
@author: anne marie delaney
eoin brophy
Script to generate a training and test data set of sine waves
"""
import pandas as pd
import numpy as np
import random
"""Create a training set of sine waves with 10000 records"""
a = np.arange(0.1,0.9,0.02)
x = np.arange(0,20,0.5)
r = np.arange(2,6.1,0.1)
count = 0
fs = len(x)
y = np.zeros((1,len(x)))
for n in range(10000):
amp = a[random.randint(0,len(a)-1)]
rad = r[random.randint(0,len(r)-1)]
phase = random.uniform(-1,1)*np.pi
y = np.append(y,amp*np.sin(((2*np.pi*rad*x)+phase)/fs).reshape((1,len(x))),axis = 0)
data = pd.DataFrame(y[1:][:])
data.to_csv('./sinedata_v2.csv', header = False, index = False)
"""Creating a test set of sine waves with 3000 records"""
a = np.arange(0.1,0.9,0.02)
x = np.arange(0,20,0.5)
r = np.arange(2,6.1,0.1)
count = 0
fs = len(x)
y = np.zeros((1,len(x)))
for n in range(3000):
amp = a[random.randint(0,len(a)-1)]
rad = r[random.randint(0,len(r)-1)]
phase = random.uniform(-1,1)*np.pi
y = np.append(y,amp*np.sin(((2*np.pi*rad*x)+phase)/fs).reshape((1,len(x))),axis = 0)
data = pd.DataFrame(y[1:][:])
data.to_csv('sinedata_test_v2.csv', header = False, index = False)