Skip to content

Commit ac44d00

Browse files
committed
upversion 2.10.8; update examples and doc
Signed-off-by: Martin <[email protected]>
1 parent fb8e531 commit ac44d00

File tree

10 files changed

+173
-159
lines changed

10 files changed

+173
-159
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
2024-05-02: more documentation for example programs [fb8e531]
12
2024-05-01: fix set_cal_out_freq_6022.py; some minor updates [3560cbd]
23
2024-02-25: add fx2lib lib files [852f574]
34
2024-02-24: refactoring; move firmware code out of python module [0ddab5e]

README.md

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ and focusses mainly on Hantek6022BE/BL under Linux (development system: Debian s
2222

2323
## Hantek 6022 Python API for Linux
2424

25-
<img alt="Scope Visualisation Example" width="100%" src="plot_from_capture.png">
25+
![Scope Visualisation Example](examples/plot_from_capture.png)
2626

2727
This is a API for Python for the ultra-cheap, reasonably usable (and hackable) 6022 DSO,
2828
with a libusb implementation via libusb1 for Linux.
@@ -45,8 +45,12 @@ all tools named `*_6022.py` are copied to `/usr/bin` and are thus globally avail
4545

4646
You can even use the programs without installing anything. You just need a working `python3-libusb` installation.
4747
All you need is the `PyHT6022` directory in the directory where your Python program is located (e.g. in `examples`).
48-
This means: download this repo (as `https://github.com/Ho-Ro/Hantek6022API/archive/refs/heads/main.zip`
49-
or with `git clone https://github.com/Ho-Ro/Hantek6022API.git`), go to `examples` and try e.g. `python3 get_serial_number.py`.
48+
This means:
49+
50+
- download this repo (as `https://github.com/Ho-Ro/Hantek6022API/archive/refs/heads/main.zip`)
51+
- or execute `git clone https://github.com/Ho-Ro/Hantek6022API.git`
52+
- go to `examples`
53+
- try e.g. `python3 get_serial_number.py`.
5054

5155

5256
## Developer Info
@@ -61,8 +65,8 @@ to your udev rules, via
6165
After you've done this, the scope should automatically come up with the correct permissions to be accessed
6266
without being root user.
6367

64-
The following instructions are tested with Debian stable versions *stretch*, *buster* and *bullseye*
65-
and are executed also automatically by GitHub under Ubuntu (*2004*) after each push to this repo - have a look
68+
The following instructions are tested with Debian stable versions *stretch*, *buster*, *bullseye*, and *bookworm*
69+
and are executed also automatically by GitHub under Ubuntu (*2204*) after each push to this repo - have a look
6670
at the [GitHub Action](https://github.com/Ho-Ro/Hantek6022API/actions/workflows/build_check.yml).
6771
On each successful run a Debian package is available under *Artifacts*.
6872

@@ -277,36 +281,61 @@ The 256 x downsampling option increases the SNR and effective resolution (8bit -
277281
and allows very long time recording. The program uses the offset and gain calibration from EEPROM.
278282
It writes the captured data into stdout or an outfile and calculates DC, AC and RMS of the data.
279283

280-
usage: capture_6022.py [-h] [-d [DOWNSAMPLE]] [-g] [-o OUTFILE] [-r RATE] [-t TIME] [-x CH1]
281-
[-y CH2]
282-
283-
optional arguments:
284-
-h, --help show this help message and exit
285-
-d [DOWNSAMPLE], --downsample [DOWNSAMPLE]
286-
downsample 256 x DOWNSAMPLE
287-
-g, --german use comma as decimal separator
288-
-o OUTFILE, --outfile OUTFILE
289-
write the data into OUTFILE
290-
-r RATE, --rate RATE sample rate in kS/s (20, 32, 50, 64, 100, 128, 200, default: 20)
291-
-t TIME, --time TIME capture time in seconds (default: 1.0)
292-
-x CH1, --ch1 CH1 gain of channel 1 (1, 2, 5, 10, default: 1)
293-
-y CH2, --ch2 CH2 gain of channel 2 (1, 2, 5, 10, default: 1)
294-
284+
```
285+
usage: capture_6022.py [-h] [-d [DOWNSAMPLE]] [-g] [-o OUTFILE] [-r RATE] [-t TIME] [-x CH1] [-y CH2]
286+
287+
Capture data from both channels of Hantek6022
288+
289+
options:
290+
-h, --help show this help message and exit
291+
-d [DOWNSAMPLE], --downsample [DOWNSAMPLE]
292+
downsample 256 x DOWNSAMPLE
293+
-g, --german use comma as decimal separator
294+
-o OUTFILE, --outfile OUTFILE
295+
write the data into OUTFILE (default: stdout)
296+
-r RATE, --rate RATE sample rate in kS/s (20, 32, 50, 64, 100, 128, 200, default: 20)
297+
-t TIME, --time TIME capture time in seconds (default: 1.0)
298+
-x CH1, --ch1 CH1 gain of channel 1 (1, 2, 5, 10, default: 1)
299+
-y CH2, --ch2 CH2 gain of channel 2 (1, 2, 5, 10, default: 1)
300+
```
295301

296302
The program `plot_from_capture_6022.py` takes the captured data (either from stdin
297303
or from a file from command line argument) and presents them as seen on top of this page.
298304

299-
usage: plot_from_capture_6022.py [-h] [-i INFILE] [-c CHANNELS] [-s [MAX_FREQ]]
305+
```
306+
usage: plot_from_capture_6022.py [-h] [-i INFILE] [-c CHANNEL] [-s [MAX_FREQ]] [-x]
307+
308+
Plot output of capture_6022.py over time
309+
310+
options:
311+
-h, --help show this help message and exit
312+
-i INFILE, --infile INFILE
313+
read the data from INFILE (default: stdin)
314+
-c CHANNEL, --channel CHANNEL
315+
show only CH1 or CH2, default: show both)
316+
-s [MAX_FREQ], --spectrum [MAX_FREQ]
317+
display the spectrum of the samples, optional up to MAX_FREQ
318+
-x, --xkcd plot in XKCD style :)
319+
```
320+
321+
The program `fft_from_capture_6022.py` takes the captured data (either from stdin
322+
or from a file from command line argument) and shows the spectrum.
300323

301-
optional arguments:
302-
-h, --help show this help message and exit
303-
-i INFILE, --infile INFILE
304-
read the data from INFILE
305-
-c CHANNELS, --channels CHANNELS
306-
show one (CH1) or two (CH1, CH2) channels, default: 2)
307-
-s [MAX_FREQ], --spectrum [MAX_FREQ]
308-
display the spectrum of the samples, optional up to MAX_FREQ
324+
```
325+
usage: fft_from_capture_6022.py [-h] [-i INFILE] [-f | -n] [-x]
326+
327+
Plot FFT of output from capture_6022.py, use hann windowing as default
328+
329+
options:
330+
-h, --help show this help message and exit
331+
-i INFILE, --infile INFILE
332+
read the data from INFILE, (default: stdin)
333+
-f, --flat_top use flat top window
334+
-n, --no_window use no window
335+
-x, --xkcd plot in XKCD style :)
336+
```
309337

338+
![fft from capture](examples/fft_from_capture.png)
310339

311340
## Other neat things you can do
312341

examples/README.md

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,21 @@ options:
4646

4747
### `fft_from_capture_6022.py`
4848
```
49-
usage: fft_from_capture_6022.py [-h] [-i INFILE] [-x]
49+
usage: fft_from_capture_6022.py [-h] [-i INFILE] [-f | -n] [-x]
5050
51-
Plot FFT of output from capture_6022.py, use hann windowing
51+
Plot FFT of output from capture_6022.py, use hann windowing as default
5252
5353
options:
5454
-h, --help show this help message and exit
5555
-i INFILE, --infile INFILE
5656
read the data from INFILE, (default: stdin)
57+
-f, --flat_top use flat top window
58+
-n, --no_window use no window
5759
-x, --xkcd plot in XKCD style :)
5860
```
59-
61+
#### Hann window
6062
![fft from capture](fft_from_capture.png)
61-
62-
### `fft_ft_from_capture_6022.py`
63-
```
64-
usage: fft_ft_from_capture_6022.py [-h] [-i INFILE] [-x]
65-
66-
Plot FFT of output from capture_6022.py, use flattop windowing
67-
68-
options:
69-
-h, --help show this help message and exit
70-
-i INFILE, --infile INFILE
71-
read the data from INFILE
72-
-x, --xkcd plot in XKCD style :)
73-
```
63+
#### Flat top window
7464
![fft ft from capture](fft_ft_from_capture.png)
7565

7666
### `plot_from_capture_6022.py`
@@ -82,7 +72,7 @@ Plot output of capture_6022.py over time
8272
options:
8373
-h, --help show this help message and exit
8474
-i INFILE, --infile INFILE
85-
read the data from INFILE (default: use stdin)
75+
read the data from INFILE (default: stdin)
8676
-c CHANNEL, --channel CHANNEL
8777
show only CH1 or CH2, default: show both)
8878
-s [MAX_FREQ], --spectrum [MAX_FREQ]

examples/fft_from_capture.png

2.93 KB
Loading

examples/fft_from_capture_6022.py

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@
88
'''
99

1010
import csv
11+
import math
12+
import matplotlib.mlab as ml
1113
import matplotlib.pyplot as plt
14+
import numpy as np
1215
import sys
1316
import argparse
1417

1518
# construct the argument parser and parse the arguments
1619
ap = argparse.ArgumentParser(
1720
prog='fft_from_capture_6022.py',
18-
description='Plot FFT of output from capture_6022.py, use hann windowing' )
21+
description='Plot FFT of output from capture_6022.py, use hann windowing as default' )
1922
ap.add_argument( '-i', '--infile', type = argparse.FileType('r'),
2023
help='read the data from INFILE, (default: stdin)' )
24+
windows = ap.add_mutually_exclusive_group()
25+
windows.add_argument( '-f', '--flat_top', action = 'store_true',
26+
help='use flat top window')
27+
windows.add_argument( '-n', '--no_window', action = 'store_true',
28+
help='use no window')
2129
ap.add_argument( '-x', '--xkcd', action = 'store_true',
2230
help='plot in XKCD style :)' )
2331
options = ap.parse_args()
2432

25-
if options.xkcd:
26-
plt.xkcd()
27-
2833
infile = options.infile or sys.stdin
2934

3035
# Use output of 'capture_6022.py'
@@ -46,19 +51,59 @@
4651

4752
infile.close()
4853

54+
55+
##############################
56+
# define own window function #
57+
##############################
58+
#
59+
def flat_top( x ):
60+
N = len( x )
61+
# use matlab coefficients -> https://www.mathworks.com/help/signal/ref/flattopwin.html
62+
# scaled by 1/0.21547095 to get an overall window amplitude gain of 1.0
63+
a0, a1, a2, a3, a4 = 1, 1.933732403, 1.286777443, 0.387889630, 0.032242713
64+
p = 2 * math.pi / (N-1)
65+
# gain = 0
66+
for n in range( N ):
67+
x[n] = (
68+
a0
69+
- a1 * math.cos( p * n )
70+
+ a2 * math.cos( p * n * 2 )
71+
- a3 * math.cos( p * n * 3 )
72+
+ a4 * math.cos( p * n * 4 )
73+
)
74+
# gain += x[n]
75+
# print( "flat_top:", gain/N )
76+
return x
77+
#
78+
##############################
79+
80+
81+
if options.flat_top:
82+
window = flat_top
83+
elif options.no_window:
84+
window = ml.window_none
85+
else:
86+
window = None # default: hann window
87+
4988
# Sample frequency
5089
fs = 1 / ( time[1] - time[0] )
5190

91+
if options.xkcd:
92+
plt.xkcd()
93+
5294
# Stack plots in two rows, one column, sync their frequency axes
5395
fig, axs = plt.subplots( 2, 1, sharex = True )
5496

55-
# Channel 1 spectrum (default window: hanning)
56-
axs[0].magnitude_spectrum( ch1, fs, scale = 'dB' )
97+
# Channel 1 spectrum
98+
axs[0].magnitude_spectrum( ch1, fs, scale = 'dB', window = window )
5799
axs[0].grid( True )
100+
axs[0].set_title( 'Spectrum 1')
58101

59-
# Channel 2 spectrum (default window: hanning)
60-
axs[1].magnitude_spectrum( ch2, fs, scale = 'dB' )
102+
# Channel 2 spectrum
103+
axs[1].magnitude_spectrum( ch2, fs, scale = 'dB', window = window )
61104
axs[1].grid( True )
105+
axs[1].set_title( 'Spectrum 2')
62106

107+
fig.tight_layout()
63108
# And display everything
64109
plt.show()

examples/fft_ft_from_capture.png

2.56 KB
Loading

examples/fft_ft_from_capture_6022.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

0 commit comments

Comments
 (0)