This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TSW1400EVM: Convert binary file to integer values

Part Number: TSW1400EVM


Hi Experts,

Good day.

My question is about the binary file data of a measurement with the TSW1400 EVM and the AFE583  (recorded with the HSDC Pro v. 4.7).

A test measurement (sine wave) was recorded on ch1 (the other 31 channels are floating). In order to be able to transform the binary file the CSV file was recorded as well (to be able to compare the transformed values).
At the moment I am trying to get the same values from the binary and the csv file.

Can you tell me how I have to convert the values in the binary file in order to get the real measured values? Here is the starting sequence of the bin file:
b'\xec\x05\x96\x08\xd1\x07\xb5\x07\xc5\x07\\\x07\xfe\x07\xba\x07\x02\x08\xd8\x07\x1b\x08\xce\x07\xc5\x07\xe7\x07\x12\x08\xc8\x07\xb4\x07\xe1\x07\x16\x08\x1b\x08\x1e\x08\xff\x07M\x08\x99\x07\x08\x08'

The first two lines of my CSV are:

-532       150         -47          -75         -59         -164       -2            -70          2             -40         27           -50         -59          -25         18                -56         -76          -31         22           27          
30           -1            77           -103       8             92           104       113         103             -55         49           -34

-120       151         -45          -70         -58         -166       -4            -69          1             -28         28           -44         -58          -26         18                -58         -76          -30         22           31          
35           1              77          -106       7             90           106         114         104                -54         49           -35

I already read this article High Speed Data Converter (HSDC) Pro Software Output Binary File Format - Data converters forum - Data converters - TI E2E support forums but with the here described solution I didn’t get the same values as in the CSV file.

I am looking forward to your help.

Regards,


  • Please attach the .bin file and the .csv file so I can create a script.

  • Hi Chase,

    Attached to this mail are the two files you're requested. The sine wave is stored in ch1.

    New Compressed (zipped) Folder.zip

    Regards,

    Josel


  • Josel,

    Please find MATLAB script attached which can perform this conversion. If customer wants Python version instead, please let me know and I can quickly create a python version as well.

    https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/73/parse_5F00_bin_5F00_data.m

    Regards, Chase

  • Attached is a python version of the same script above. hsdc_pro_bin_to_csv.zip

    To download, please click on the top right of the code preview window.

    import numpy
    
    ''' user input parameters '''
    file_name = 'Reference_5MHz_Sine_Ch1.bin'
    newCSVfilename = 'generated_csv_file.csv'
    num_channels = 32
    adc_resolution = 12
    
    ''' Open file '''
    f = open(file_name, "r")
    data = numpy.fromfile(f, dtype=numpy.uint16)
    f.close()
    
    ''' manipulate data '''
    shifted_data=[]
    for sample in data: # convert to 2s complement by subtracting the midcode (adc_resolution-1):
        shifted_data.append(sample-2**(adc_resolution-1))
    num_samples = int(len(shifted_data)/num_channels)
    shifted_data = numpy.array(shifted_data) # convert list to numpy array for reshape
    
    samples = shifted_data.reshape(num_samples,num_channels) # Change single column of samples into matrix where each row is a new channel
    # Transposing to match CSV format is not needed with this python script as shown in the matlab script for saving. To read data, transposing is needed as shown in line 28 of this script
    
    ''' Save matrix as csv '''
    numpy.savetxt(newCSVfilename,samples,delimiter=',',fmt='%i')
    
    ''' Plotting first 100 pts of channel 1 '''
    samples=samples.T
    
    import matplotlib.pyplot as plt
    
    plt.plot(samples[0])
    plt.xlim([1,100])
    plt.title('Time-domain Signal')
    plt.xlabel('Sample #')
    plt.ylabel('Codes')
    plt.show()

    Regards, Chase