doom'd net

still mucking around with the ol'computer


The Bitscope, Linux and the Python

The Bitscope DSO program can save files of the read data in a simple CSV format.  There are many easy ways to handle those files.

In the manual, they describe how to import them into MS Excel, they also talk about the limitations of Excel, which really isn’t the best tool for this job. However, it seems that AWK would be perfect. Using Python and numpy might have some interesting possibilities as well. Even Perl would probably make a good choice, but Perl wont be covered here.

bitscope

The format of of the saved DSO file is:

trigger,stamp,channel,index,type,delay,factor,rate,count,data

Where the data extends out count times.

So the first two lines of one of the files might look like:

trigger,stamp,channel,index,type,delay,factor,rate,count,data
4470,21:14:36,0,4469,0,0.0021,12,440,439,2.5665,2.5653,2.554,2.5651,2.5596,2.5576,2.559,2.5605,2.5625,2.5569,2.5595,2.5605,
2.5605,2.5637,2.5665,2.5651,2.5605,2.5594,2.5547,2.5549,2.5614,2.5635,2.5611,2.5605,2.5635,2.5577,2.5614,2.5665,2.5647,2.5605,
2.5605,2.5573,2.5489,2.5563,2.5653,2.5613,2.5548,2.5605,2.5598,2.5552,2.5593,2.5647,1.9853,-0.77478,-2.5601,-2.5635,-2.5635,
-2.5635,-2.5493,-2.5547,-2.5599,-2.5534,-2.5519,-2.5562,-2.5565,-2.5681,-2.5532,-2.5549,-2.5582,-2.5524,-2.5544,-2.5547,-2.5632,
-2.56,-2.556,-2.5516,-2.5554,-2.5605,-2.557,-2.5525,-2.5493,-2.5536,-2.5546,-2.5635,-2.5578,-2.5611,-2.5605,-2.5526,-2.5546,
-2.5531,-2.5516,-2.5516,-2.556,-2.5526,-2.5516,-2.5575,-2.3059,1.1281,2.5665,2.5637,2.5539,2.5529,2.5542,2.5555,2.5619,2.5635,
2.5609,2.5605,2.5546,2.5563,2.5652,2.5596,2.5564,2.5574,2.5622,2.5635,2.5635,2.5587,2.5602,2.5634,2.5604,2.5583,2.5616,2.5572,
2.5635,2.5608,2.5576,2.5594,2.5605,2.5605,2.5579,2.549,2.5547,2.5586,2.5636,2.5541,2.5584,2.5546,2.5593,2.5617,1.9611,-1.6026,
-2.5554,-2.5602,-2.5458,-2.5579,-2.5589,-2.5532,-2.5565,-2.5559,-2.5606,-2.5671,-2.5614,-2.5553,-2.5571,-2.5576,-2.5575,-2.5518,- 
2.5551,-2.5598,-2.5635,-2.5576,-2.5545,-2.5603,-2.5586,-2.5501,-2.5535,-2.5573,-2.5576,-2.5645,-2.5726,-2.559,-2.5616,-2.5588,
-2.5562,-2.555,-2.5576,-2.5553,-2.5546,-2.5626,-2.5606,-2.5581,-2.5643,-2.5536,-1.628,1.2689,2.5604,2.5635,2.5616,2.5649,2.5593,
2.5496,2.5486,2.5609,2.5661,2.5635,2.5653,2.5672,2.5594,2.5497,2.555,2.5648,2.5618,2.5579,2.5633,2.5634,2.5605,2.5593,2.5563,
2.5605,2.5579,2.5577,2.5624,2.5594,2.5552,2.5649,2.5637,2.5573,2.5505,2.5665,2.5641,2.5565,2.5546,2.5623,2.5623,2.5616,2.5635,
2.5534,2.5571,-2.5546,-2.5611,-2.5644,-2.5553,-2.5596,-2.5635,-2.559,-2.5581,-2.5565,-2.5568,-2.5525,-2.5488,-2.5546,-2.5541,
-2.5505,-2.5598,-2.5556,-2.554,-2.5561,-2.5546,-2.5565,-2.5487,-2.5554,-2.5548,-2.5516,-2.5578,-2.5601,-2.5576,-2.5566,-2.5546,
-2.556,-2.5559,-2.5488,-2.5478,-2.551,-2.5596,-2.5605,-2.5574,-2.555,-2.5589,-2.5608,-2.5546,-2.5504,-1.3864,1.4556,2.5597,
2.5558,2.5625,2.5578,2.552,2.5605,2.5599,2.5593,2.5647,2.5625,2.5527,2.556,2.5626,2.5565,2.5649,2.5637,2.5576,2.5576,2.5593,
2.5632,2.5556,2.5576,2.5607,2.5617,2.5647,2.5596,2.5524,2.56,2.5604,2.5525,2.56,2.5583,2.5585,2.5584,2.562,2.5623,2.5595,2.5621,
2.5635,2.5608,2.5546,2.5546,1.8341,-1.9258,-2.5615,-2.5598,-2.5575,-2.5623,-2.5675,-2.5562,-2.554,-2.5573,-2.5516,-2.5548,
-2.5576,-2.5576,-2.5566,-2.5558,-2.559,-2.5555,-2.5535,-2.5567,-2.5551,-2.5546,-2.5516,-2.5489,-2.5546,-2.5559,-2.5605,-2.5605,
-2.5605,-2.5589,-2.5595,-2.5562,-2.557,-2.5523,-2.5573,-2.5518,-2.5579,-2.5593,-2.5528,-2.5508,-2.5587,-2.5538,-2.5549,-2.5521,
-1.2202,2.1186,2.5635,2.5573,2.5526,2.56,2.5576,2.5576,2.5589,2.5637,2.5611,2.5555,2.5569,2.5576,2.5547,2.5606,2.5639,2.5654,
2.5597,2.5576,2.5563,2.5561,2.5558,2.5566,2.5598,2.5555,2.5712,2.5635,2.5605,2.5595,2.5561,2.5616,2.5598,2.5561,2.5576,2.5595,
2.5605,2.5605,2.5551,2.5575,2.5603,2.5576,2.5583,2.5605,0.99457,-1.9089,-2.5576,-2.5576,-2.5576,-2.5625,-2.5555,-2.5575,-2.5521,
-2.5605,-2.5592,-2.5564,-2.5582,-2.556,-2.5592,-2.5625,-2.5614,-2.5581,-2.5602,-2.5605,-2.5577,-2.5605,-2.5593,-2.5563,-2.5605,
-2.5605,-2.5589,-2.5557,-2.5609,-2.5541,-2.5542,-2.5546,-2.5543,-2.5497,-2.5582,-2.5614,-2.5613,-2.5562,-2.5562,-2.5576,-2.5555,
-2.5522,-2.5541,-2.5461,-1.608

NO, I don’t expect you to actually read it, but you get the point.  But a simple AWK script to parse it might help:

rate=$8

if( $3 == 0 ) 
for( i=10; i <= NF; i++ ) {
  print count/rate, $i 
  count ++
}

This will give an output of <time in sec> <value>:

0 1.0332
1.47275e-05 1.1459
2.94551e-05 1.2382
4.41826e-05 1.3353
5.89102e-05 1.4255
7.36377e-05 1.5027
8.83652e-05 1.5492
0.000103093 1.6061
0.00011782 1.638
0.000132548 1.6496
...

You can then use something like graph from the Plotutils package to graph it:

awk -f dso.awk < square.csv \| graph -TX:

square wave

NOTE: The sample files, along with a more complete scripts will be available on GitHub and noted at the end of this post.

Cool, now the file can be parsed in awk, what about Python? Pretty easy! Here is a little code example:

f = open("square.csv", 'r')

with f:
    reader = csv.reader( f )
    next ( reader ) # skip the header

    for row in reader:
       if int( row[2] ) == 0:
          rate0 = int ( row[7] )
          count0 = int( row[8] )
          data0.extend( [ float( x ) for x in row[9:len(row)] ])

       if int( row[2] ) == schannel1:
          rate1 = int ( row[7] )
          count1 = int( row[8] )
          data1.extend( [ float( x ) for x in row[9:len(row)] ])

sig0 = np.array( self.data0 )
sig1 = np.array( self.data1 )

And with the signals in numpy arrays, there are many possibilities.

In the GitHub repository, there is a Python Library called bitscope.py.  It has a function that will parse a given CSV from the DSO program, and will return a normal array, numpy array, and other bits of data from the file.

Now you can do cool things like an DFT on the data, as the dso_fft.py program does:

square fft

And

tone fft

There is even a program that uses Pygame to play the recorded sound as audio, through the speakers.

The AWK, Python, and sample files can be found at https://github.com/lorddoomicus/bitscopei.

Note:  The AWK script must be run with gawk. All the Python scripts require numpy to be installed. Some may also require matplotlib and/or Pygame.