forked from MatCat/csv2arb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsine.py
38 lines (29 loc) · 786 Bytes
/
sine.py
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
# -*- coding: utf-8 -*-
"""
https://github.com/gnbl/csv2arb
Generate one period of sin() in SAMPLES and write one value per line to OUTFILE (ASCII).
"""
import sys
import math
if len( sys.argv ) < 3:
print("usage: {} OUTFILE SAMPLES".format(sys.argv))
sys.exit()
filename = sys.argv[1]
samples = int( sys.argv[2] )
increment = math.pi*2/samples
omega = 0.0 * math.pi
offset = 0.0
scale = 1.0
eol = "\n"
data = []
for i in range(samples):
value = offset + math.sin( omega + i*increment) * scale
data.append( str(value) + eol )
# CSV
if True:
with open( filename + ".csv", 'w') as f:
f.write( "".join(data) )
# binary
#if False:
# with open( filename + ".bin", 'wb') as f:
# f.write( "".join(data) )