Skip to content

Commit 0be25d5

Browse files
authored
Merge pull request #41 from fronzbot/dev
v0.2.1
2 parents c0974e5 + e7d90fd commit 0be25d5

File tree

16 files changed

+525
-22
lines changed

16 files changed

+525
-22
lines changed

.DS_Store

6 KB
Binary file not shown.

.github/workflows/coverage.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: coverage
2+
3+
on:
4+
push:
5+
branches: [ master, dev ]
6+
pull_request:
7+
branches: [ master, dev ]
8+
9+
jobs:
10+
coverage:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
python-version: ['3.11']
15+
steps:
16+
- name: Check out code from GitHub
17+
uses: actions/checkout@v4.1.6
18+
- name: Set up Python ${{ matrix.python-version }}
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: ${{ matrix.python-version }}
22+
- name: Install dependencies
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install -r requirements.txt
26+
pip install -r requirements_test.txt
27+
pip install tox
28+
- name: Run Coverage
29+
run: |
30+
tox -r -e cov
31+
- name: Upload coverage
32+
uses: actions/upload-artifact@v4.3.3
33+
with:
34+
name: coverage-${{ matrix.python-version }}
35+
path: coverage.xml
36+
overwrite: true
37+
upload-coverage:
38+
runs-on: ubuntu-latest
39+
strategy:
40+
matrix:
41+
python-version: ['3.11']
42+
needs:
43+
- coverage
44+
timeout-minutes: 10
45+
steps:
46+
- name: Check out code from GitHub
47+
uses: actions/checkout@v4.1.6
48+
- name: Download all coverage artifacts
49+
uses: actions/download-artifact@v4.1.7
50+
with:
51+
name: coverage-${{ matrix.python-version }}
52+
path: coverage.xml
53+
- name: Upload coverage to Codecov
54+
uses: codecov/codecov-action@v4.4.1
55+
with:
56+
fail_ci_if_error: true
57+
token: ${{ secrets.CODECOV_TOKEN }}
58+
name: python-adc-eval

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
python-version: [3.9]
14+
python-version: [3.11]
1515

1616
steps:
1717
- uses: actions/checkout@v2

.github/workflows/tests.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: tests
2+
3+
on:
4+
push:
5+
branches: [ main, dev ]
6+
pull_request:
7+
branches: [ main, dev ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.platform }}
12+
strategy:
13+
max-parallel: 4
14+
matrix:
15+
platform:
16+
- ubuntu-latest
17+
python-version: ['3.9', '3.10', '3.11', '3.12']
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install -r requirements.txt
29+
pip install -r requirements_test.txt
30+
pip install tox
31+
- name: Test
32+
run: |
33+
tox -r

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ __pycache__
44
python_adc_eval.egg-info
55
dist
66
.ruff_cache
7+
.coverage

README.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
python-adc-eval |Lint| |PyPi Version| |Codestyle|
2-
===================================================
1+
python-adc-eval |Lint| |PyPi Version| |Codecov| |Codestyle|
2+
=============================================================
33

44
A python-based ADC evaluation tool, suitable for standalone or library-based usage
55

@@ -48,7 +48,9 @@ Given an array of values representing the output of an ADC, the spectrum can be
4848
4949
.. |Lint| image:: https://github.com/fronzbot/python-adc-eval/workflows/Lint/badge.svg
5050
:target: https://github.com/fronzbot/python-adc-eval/actions?query=workflow%3ALint
51-
.. |PyPi Version| image:: https://img.shields.io/pypi/v/spithon.svg
51+
.. |PyPi Version| image:: https://img.shields.io/pypi/v/python-adc-eval.svg
5252
:target: https://pypi.org/project/python-adc-eval
5353
.. |Codestyle| image:: https://img.shields.io/badge/code%20style-black-000000.svg
5454
:target: https://github.com/psf/black
55+
.. |Codecov| image:: https://codecov.io/gh/fronzbot/python-adc-eval/graph/badge.svg?token=156GMQ4NNV
56+
:target: https://codecov.io/gh/fronzbot/python-adc-eval

adc_eval/analyser.png

-218 KB
Binary file not shown.

adc_eval/spectrum.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def db_to_pow(value, places=3):
88
"""Convert dBW to W."""
99
if isinstance(value, np.ndarray):
10-
return 10 * np.log10(value)
10+
return 10 ** (0.1 * value)
1111
return round(10 ** (0.1 * value), places)
1212

1313

@@ -90,18 +90,25 @@ def find_harmonics(spectrum, freq, nfft, bin_sig, psig, harms=5, leak=20):
9090
bin_harm = int(harm - (zone - 1) * nfft / 2)
9191

9292
# Make sure we pick the max bin where power is maximized; due to spectral leakage
93-
bin_harm_max = bin_harm
93+
# if bin_harm == nfft/2, set to bin of 0
94+
if bin_harm == nfft / 2:
95+
bin_harm = 0
96+
pwr_max = spectrum[bin_harm]
9497
for i in range(bin_harm - leak, bin_harm + leak + 1):
95-
if spectrum[i] > spectrum[bin_harm_max]:
96-
bin_harm_max = i
97-
98-
bin_harm = bin_harm_max
98+
try:
99+
pwr = spectrum[i]
100+
if pwr > pwr_max:
101+
bin_harm = i
102+
pwr_max = pwr
103+
except IndexError:
104+
# bin + leakage out of bounds, so stop looking
105+
break
99106

100107
harm_stats["harm"][harm_index]["bin"] = bin_harm
101-
harm_stats["harm"][harm_index]["power"] = spectrum[bin_harm]
108+
harm_stats["harm"][harm_index]["power"] = pwr
102109
harm_stats["harm"][harm_index]["freq"] = round(freq[bin_harm] / 1e6, 1)
103-
harm_stats["harm"][harm_index]["dBc"] = dBW(spectrum[bin_harm] / psig)
104-
harm_stats["harm"][harm_index]["dB"] = dBW(spectrum[bin_harm])
110+
harm_stats["harm"][harm_index]["dBc"] = dBW(pwr / psig)
111+
harm_stats["harm"][harm_index]["dB"] = dBW(pwr)
105112

106113
harm_index = harm_index + 1
107114

@@ -118,7 +125,9 @@ def calc_psd(data, fs, nfft=2**12, single_sided=False):
118125
psd = np.mean(XF, axis=1) / (fs / nfft) # average the ffts and divide by bin width
119126
freq = fs * np.linspace(0, 1, nfft)
120127
if single_sided:
128+
# First we double all the bins, then we halve the DC bin
121129
psd = 2 * psd[0 : int(nfft / 2)]
130+
psd[0] /= 2
122131
freq = freq[0 : int(nfft / 2)]
123132
return (freq, psd)
124133

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ classifiers = [
2121
]
2222
requires-python = ">=3.8.0"
2323
dependencies = [
24-
"matplotlib==3.8.4",
24+
"matplotlib==3.9.0",
2525
]
2626

2727
[project.urls]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
matplotlib==3.8.4
1+
matplotlib==3.9.0

0 commit comments

Comments
 (0)