--- /dev/null
+0.000000000000000000e+00,0.000000000000000000e+00
+2.040816326530612082e-02,2.026679365482009221e-01
+4.081632653061224164e-02,3.969241489249223376e-01
+6.122448979591836593e-02,5.747060412161791865e-01
+8.163265306122448328e-02,7.286347834693502890e-01
+1.020408163265306006e-01,8.523215697196182550e-01
+1.224489795918367319e-01,9.406327851124867134e-01
+1.428571428571428492e-01,9.899030763721238246e-01
+1.632653061224489666e-01,9.980874821347183179e-01
+1.836734693877550839e-01,9.648463089837633344e-01
+2.040816326530612013e-01,8.915592304110039334e-01
+2.244897959183673186e-01,7.812680235262641215e-01
+2.448979591836734637e-01,6.385503202266020750e-01
+2.653061224489795533e-01,4.693296127772009774e-01
+2.857142857142856984e-01,2.806293995143572806e-01
+3.061224489795917880e-01,8.028167484281438504e-02
+3.265306122448979331e-01,-1.233981373621782646e-01
+3.469387755102040782e-01,-3.219563150726186818e-01
+3.673469387755101678e-01,-5.071517094845140461e-01
+3.877551020408163129e-01,-6.712977935519317541e-01
+4.081632653061224025e-01,-8.075816909683358746e-01
+4.285714285714285476e-01,-9.103469443107827797e-01
+4.489795918367346372e-01,-9.753282860670453580e-01
+4.693877551020407823e-01,-9.998286683840895694e-01
+4.897959183673469274e-01,-9.828312039256306143e-01
+5.102040816326530726e-01,-9.250413717382028889e-01
+5.306122448979591066e-01,-8.288577363730427194e-01
+5.510204081632652517e-01,-6.982723955654002168e-01
+5.714285714285713969e-01,-5.387052883861570551e-01
+5.918367346938775420e-01,-3.567792408989380881e-01
+6.122448979591835760e-01,-1.600450860432523215e-01
+6.326530612244897211e-01,4.333173336868257480e-02
+6.530612244897958663e-01,2.449100710119784530e-01
+6.734693877551020114e-01,4.363234264718193200e-01
+6.938775510204081565e-01,6.096271964908323016e-01
+7.142857142857141906e-01,7.576284153927196341e-01
+7.346938775510203357e-01,8.741842988197331410e-01
+7.551020408163264808e-01,9.544571997387516493e-01
+7.755102040816326259e-01,9.951153947776635311e-01
+7.959183673469386600e-01,9.944713672636170676e-01
+8.163265306122448051e-01,9.525518475314609379e-01
+8.367346938775509502e-01,8.710967034823207111e-01
+8.571428571428570953e-01,7.534867274396376269e-01
+8.775510204081632404e-01,6.046033165061542869e-01
+8.979591836734692745e-01,4.306258703827389178e-01
+9.183673469387754196e-01,2.387753156440326208e-01
+9.387755102040815647e-01,3.701440148506414396e-02
+9.591836734693877098e-01,-1.662827938487564106e-01
+9.795918367346938549e-01,-3.626784288265488265e-01
+1.000000000000000000e+00,-5.440211108893697745e-01
--- /dev/null
+#!/usr/bin/env python
+"""keysight_convert.py v0.1 (written in python 2.7)
+
+convert csv files to keysight/agilent 81150A binary waveforms
+x values have to be floats between 0 and 1 (first point should start with x=0)
+y values have to be floats between -1 and +1
+
+if --normalize flag is on, input waveform will be automatically fit into the allowed value range
+
+csv format:
+
+<xval1>,<yval1>
+<xval2>,<yval2>
+<xval3>,<yval3>
+...
+
+example:
+
+./keysight_convert.py example.csv
+
+2016 by Michael Wiebusch
+http://mwiebusch.de
+"""
+import numpy as np
+from matplotlib import pyplot as plt
+import argparse
+import re
+
+
+#small helper fuction for little endian/big endian conversion stuff
+def flip(num):
+ return bytearray([num & 0xFF,(num & 0xFF00)>>8])
+
+#def normalize(vec):
+ #vec=vec-vec[0]
+ #vec=vec/max(abs(vec))
+ #return vec
+
+
+
+def main():
+
+ # Parse command-line arguments
+ parser = argparse.ArgumentParser(usage=__doc__)
+ #parser.add_argument("-i","--input", help="input file (csv)")
+ parser.add_argument("filename", help="input file (csv)")
+ parser.add_argument("-o","--output", help="output binary file, otherwise input filename + .wfm extension will be used")
+ parser.add_argument("-n","--normalize", help="normalize input waveform to limits of binary format", action='store_true')
+ args = parser.parse_args()
+
+ #remove file extension, add wfm
+ infile_base = re.split('\.[^\.]+$',args.filename)[0]
+ outfile=infile_base+".wfm"
+ if args.output:
+ outfile=args.output
+
+ a = np.loadtxt(open(args.filename,"rb"),delimiter=",",skiprows=1)
+
+ #print a
+
+ x=a[:,0]
+ y=a[:,1]
+
+ #plt.plot(x,y)
+ #plt.show()
+
+ no_points = x.size
+
+ if args.normalize:
+ print "normalizing"
+ x=x-x[0]
+ x=x/max(x)
+ y=y/max(abs(y))
+
+ print "converting "+str(no_points)+" data points"
+
+ #the file skeleton (with stuff in it that I don't understand
+ template = "42FEAF4201000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000800000000400000FF000000D80E05000000000000409F4000000000000000000000008040D594407DBFBE2AFFFFF73F0100000000000000"
+ #with open('template.bin', 'rb') as f:
+ #data = f.read()
+
+ b = bytearray(template.decode("hex"))
+
+ ##debug output
+ #print ''.join('{:02X}'.format(x) for x in b)
+
+ #insert number of points
+ b[0x50] = no_points & 0xFF
+ b[0x51] = (no_points & 0xFF00)>>8
+
+ #insert file name (first 8 characters)
+ for i in range(0,8):
+ if(i < len(infile_base)):
+ b[0x08+2*i] = infile_base[i]
+
+ #append data points
+ for i in range(0,no_points):
+ b=b+flip(min(0x4000,int(0x4000*x[i])))
+ b=b+flip(0)
+ b=b+flip(int(0x1FFF*y[i]))
+ b=b+flip(0)
+
+ #first point has to start at zero. or the function generator will crash. enforce it
+ b[0x80] = 0
+ b[0x81] = 0
+
+ #write out finished binary
+ print "done."
+ print "writing output file: "+outfile
+ with open(outfile, 'wb') as f:
+ f.write(b);
+ print "done."
+
+
+if __name__ == "__main__":
+ main()