Skip to content

Commit d6d3260

Browse files
authored
Merge pull request #4 from fronzbot/fix-div-by-zero
Prevents a divide-by-zero situation
2 parents 816cd72 + 55cbc64 commit d6d3260

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

adc_eval/spectrum.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ def harmonics(psp, fft_n, ref_pow, sample_freq, leak=20, n=5, window="hanning"):
6161
df = sample_freq / fft_n
6262
# calculate fundamental frequency
6363
fund_bin = np.argmax(psp)
64-
fund_freq = np.sum(
65-
[psp[i] * i * df for i in range(fund_bin - leak, fund_bin + leak + 1)]
66-
) / np.sum(psp[fund_bin - leak : fund_bin + leak + 1])
67-
if np.isinf:
68-
fund_freq = fund_bin * df
64+
fund_freq = fund_bin * df
65+
num = np.sum([psp[i] * i * df for i in range(fund_bin - leak, fund_bin + leak + 1)])
66+
den = np.sum(psp[fund_bin - leak : fund_bin + leak + 1])
67+
if den > 0:
68+
fund_freq = num / den
6969

7070
# calculate harmonics info
7171
h = []

0 commit comments

Comments
 (0)