0

I am trying to upload a waveform to a signal generator. The first thing I need to do is read in the file. The file is a .wfm file. This is what it looks like when I open it in notepad.

Waveform file

I try to read in the file in different ways to try to see which one will work best for me.

fileName = 'C:/Users/cruzmeza/Desktop/16qam.wfm' lst = []
lst1 = []
DataIn = []


fi = open(fileName, 'rb')
data = fi.read()
fi.close()

wave = open(fileName, 'rb')
for x in wave:
    lst.append(x)

wave.close()

f = open(fileName, "rb")
try:
    byte = f.read(1)
    while byte != "":
        lst1.append(byte)
        byte = f.read(1)
finally:
    f.close()

print 'Done'

When I read the file I get the following for each method.

data
'\x0e\x87@q\x9f\x81R\xc7\x00\x8a\xf0\xa5\xdd\xd4

lst
['\x0e\x87@q\x9f\x81R\xc7\x00\x8a\xf0\

lst1
['\x0e', '\x87', '@', 'q', '\x9f

My question is, how do I change the hex values into their numerical value, int/float anything. There are about 2000 samples in the waveform file.

Instead of \x0e I would like to have 14.0

C. Meza
  • 3
  • 1
  • 1
    Have you checked [this](http://stackoverflow.com/questions/1592158/convert-hex-to-float)? – Sangbok Lee Mar 14 '17 at 16:55
  • Just a quick start for an answer: your problem is the handling of bytes versus characters in python2. You don't have hex, you really have the numerical values. Then you converted them to text to see what you have. – dsh Mar 14 '17 at 17:01
  • What format is the waveform file? Where did you get it from? – Peter Wood Mar 14 '17 at 17:02
  • See [TEKTRONIX WINDOWS OSCILLOSCOPE WFM CONVERTER](http://www.tek.com/oscilloscope/tds7054-software/tektronix-windows-oscilloscope-wfm-converter) – Peter Wood Mar 14 '17 at 17:02
  • Also [Can I convert my wfm files to an open format+ such as a CSV (comma separated values) file?](http://www.tek.com/support/faqs/can-i-convert-my-wfm-files-open-format-such-csv-comma-separated-values-file) – Peter Wood Mar 14 '17 at 17:03
  • Peter, The file was exported using Keysight Signal Studio for Custom Modulation. – C. Meza Mar 14 '17 at 17:14

0 Answers0