Skip to content

Commit

Permalink
Merge pull request #544 from zarath/bugfix/541_crash_in_ri
Browse files Browse the repository at this point in the history
More int float issues fixed.
  • Loading branch information
zarath authored Sep 16, 2022
2 parents 92af43a + d163143 commit 6630568
Show file tree
Hide file tree
Showing 53 changed files with 983 additions and 812 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Changelog
=========

0.5.3-pre
0.5.3
-----

- Int casts due to python 3.10 extension interface changes
- Pycodestyle changes

0.5.2
-----

Expand Down
2 changes: 1 addition & 1 deletion NanoVNASaver/About.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

VERSION = "0.5.3-pre"
VERSION = "0.5.3"
VERSION_URL = (
"https://raw.githubusercontent.com/"
"NanoVNA-Saver/nanovna-saver/master/NanoVNASaver/About.py")
Expand Down
6 changes: 4 additions & 2 deletions NanoVNASaver/Analysis/AntennaAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def runAnalysis(self):
self.vswr_bandwith_value, self.vswr_limit_value - 1)
self.input_vswr_limit.setValue(self.vswr_limit_value)
logger.debug(
"found higher minimum, lowering vswr search to %s", self.vswr_limit_value)
"found higher minimum, lowering vswr search to %s",
self.vswr_limit_value)
else:
new_start = new_start - 5 * self.bandwith
new_end = new_end + 5 * self.bandwith
Expand All @@ -101,7 +102,8 @@ def runAnalysis(self):
self.vswr_limit_value += 2
self.input_vswr_limit.setValue(self.vswr_limit_value)
logger.debug(
"no minimum found, looking for higher value %s", self.vswr_limit_value)
"no minimum found, looking for higher value %s",
self.vswr_limit_value)
new_start = max(self.min_freq, new_start)
new_end = min(self.max_freq, new_end)
logger.debug("next search will be %s - %s for vswr %s",
Expand Down
62 changes: 42 additions & 20 deletions NanoVNASaver/Analysis/BandPassAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def __init__(self, app):
layout.addRow(QtWidgets.QLabel("Band pass filter analysis"))
layout.addRow(
QtWidgets.QLabel(
f"Please place {self.app.markers[0].name} in the filter passband."))
f"Please place {self.app.markers[0].name}"
f" in the filter passband."))
self.result_label = QtWidgets.QLabel()
self.lower_cutoff_label = QtWidgets.QLabel()
self.lower_six_db_label = QtWidgets.QLabel()
Expand Down Expand Up @@ -134,9 +135,11 @@ def runAnalysis(self):
self.result_label.setText("Lower cutoff location not found.")
return

initial_lower_cutoff_frequency = self.app.data.s21[initial_lower_cutoff_location].freq
initial_lower_cutoff_frequency = (
self.app.data.s21[initial_lower_cutoff_location].freq)

logger.debug("Found initial lower cutoff frequency at %d", initial_lower_cutoff_frequency)
logger.debug("Found initial lower cutoff frequency at %d",
initial_lower_cutoff_frequency)

initial_upper_cutoff_location = -1
for i in range(pass_band_location, len(self.app.data.s21), 1):
Expand All @@ -149,19 +152,23 @@ def runAnalysis(self):
self.result_label.setText("Upper cutoff location not found.")
return

initial_upper_cutoff_frequency = self.app.data.s21[initial_upper_cutoff_location].freq
initial_upper_cutoff_frequency = (
self.app.data.s21[initial_upper_cutoff_location].freq)

logger.debug("Found initial upper cutoff frequency at %d", initial_upper_cutoff_frequency)
logger.debug("Found initial upper cutoff frequency at %d",
initial_upper_cutoff_frequency)

peak_location = -1
peak_db = self.app.data.s21[initial_lower_cutoff_location].gain
for i in range(initial_lower_cutoff_location, initial_upper_cutoff_location, 1):
for i in range(initial_lower_cutoff_location,
initial_upper_cutoff_location, 1):
db = self.app.data.s21[i].gain
if db > peak_db:
peak_db = db
peak_location = i

logger.debug("Found peak of %f at %d", peak_db, self.app.data.s11[peak_location].freq)
logger.debug("Found peak of %f at %d", peak_db,
self.app.data.s11[peak_location].freq)

lower_cutoff_location = -1
pass_band_db = peak_db
Expand All @@ -171,14 +178,17 @@ def runAnalysis(self):
lower_cutoff_location = i
break

lower_cutoff_frequency = self.app.data.s21[lower_cutoff_location].freq
lower_cutoff_gain = self.app.data.s21[lower_cutoff_location].gain - pass_band_db
lower_cutoff_frequency = (
self.app.data.s21[lower_cutoff_location].freq)
lower_cutoff_gain = (
self.app.data.s21[lower_cutoff_location].gain - pass_band_db)

if lower_cutoff_gain < -4:
logger.debug("Lower cutoff frequency found at %f dB"
" - insufficient data points for true -3 dB point.",
lower_cutoff_gain)
logger.debug("Found true lower cutoff frequency at %d", lower_cutoff_frequency)
logger.debug("Found true lower cutoff frequency at %d",
lower_cutoff_frequency)

self.lower_cutoff_label.setText(
f"{format_frequency(lower_cutoff_frequency)}"
Expand All @@ -196,13 +206,15 @@ def runAnalysis(self):
break

upper_cutoff_frequency = self.app.data.s21[upper_cutoff_location].freq
upper_cutoff_gain = self.app.data.s21[upper_cutoff_location].gain - pass_band_db
upper_cutoff_gain = (
self.app.data.s21[upper_cutoff_location].gain - pass_band_db)
if upper_cutoff_gain < -4:
logger.debug("Upper cutoff frequency found at %f dB"
" - insufficient data points for true -3 dB point.",
upper_cutoff_gain)

logger.debug("Found true upper cutoff frequency at %d", upper_cutoff_frequency)
logger.debug("Found true upper cutoff frequency at %d",
upper_cutoff_frequency)

self.upper_cutoff_label.setText(
f"{format_frequency(upper_cutoff_frequency)}"
Expand All @@ -221,7 +233,8 @@ def runAnalysis(self):
self.quality_label.setText(str(round(q, 2)))

self.app.markers[0].setFrequency(str(round(center_frequency)))
self.app.markers[0].frequencyInput.setText(str(round(center_frequency)))
self.app.markers[0].frequencyInput.setText(
str(round(center_frequency)))

# Lower roll-off

Expand All @@ -235,7 +248,8 @@ def runAnalysis(self):
if lower_six_db_location < 0:
self.result_label.setText("Lower 6 dB location not found.")
return
lower_six_db_cutoff_frequency = self.app.data.s21[lower_six_db_location].freq
lower_six_db_cutoff_frequency = (
self.app.data.s21[lower_six_db_location].freq)
self.lower_six_db_label.setText(
format_frequency(lower_six_db_cutoff_frequency))

Expand All @@ -262,7 +276,8 @@ def runAnalysis(self):

if sixty_db_location > 0:
if sixty_db_location > 0:
sixty_db_cutoff_frequency = self.app.data.s21[sixty_db_location].freq
sixty_db_cutoff_frequency = (
self.app.data.s21[sixty_db_location].freq)
self.lower_sixty_db_label.setText(
format_frequency(sixty_db_cutoff_frequency))
elif ten_db_location != -1 and twenty_db_location != -1:
Expand All @@ -275,7 +290,9 @@ def runAnalysis(self):
else:
self.lower_sixty_db_label.setText("Not calculated")

if ten_db_location > 0 and twenty_db_location > 0 and ten_db_location != twenty_db_location:
if (ten_db_location > 0 and
twenty_db_location > 0 and
ten_db_location != twenty_db_location):
octave_attenuation, decade_attenuation = self.calculateRolloff(
ten_db_location, twenty_db_location)
self.lower_db_per_octave_label.setText(
Expand All @@ -298,11 +315,13 @@ def runAnalysis(self):
if upper_six_db_location < 0:
self.result_label.setText("Upper 6 dB location not found.")
return
upper_six_db_cutoff_frequency = self.app.data.s21[upper_six_db_location].freq
upper_six_db_cutoff_frequency = (
self.app.data.s21[upper_six_db_location].freq)
self.upper_six_db_label.setText(
format_frequency(upper_six_db_cutoff_frequency))

six_db_span = upper_six_db_cutoff_frequency - lower_six_db_cutoff_frequency
six_db_span = (
upper_six_db_cutoff_frequency - lower_six_db_cutoff_frequency)

self.six_db_span_label.setText(
format_frequency(six_db_span))
Expand All @@ -329,7 +348,8 @@ def runAnalysis(self):
break

if sixty_db_location > 0:
sixty_db_cutoff_frequency = self.app.data.s21[sixty_db_location].freq
sixty_db_cutoff_frequency = (
self.app.data.s21[sixty_db_location].freq)
self.upper_sixty_db_label.setText(
format_frequency(sixty_db_cutoff_frequency))
elif ten_db_location != -1 and twenty_db_location != -1:
Expand All @@ -342,7 +362,9 @@ def runAnalysis(self):
else:
self.upper_sixty_db_label.setText("Not calculated")

if ten_db_location > 0 and twenty_db_location > 0 and ten_db_location != twenty_db_location:
if (ten_db_location > 0 and
twenty_db_location > 0 and
ten_db_location != twenty_db_location):
octave_attenuation, decade_attenuation = self.calculateRolloff(
ten_db_location, twenty_db_location)
self.upper_db_per_octave_label.setText(
Expand Down
42 changes: 28 additions & 14 deletions NanoVNASaver/Analysis/BandStopAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def runAnalysis(self):
peak_db = db
peak_location = i

logger.debug("Found peak of %f at %d", peak_db, self.app.data.s11[peak_location].freq)
logger.debug("Found peak of %f at %d",
peak_db, self.app.data.s11[peak_location].freq)

lower_cutoff_location = -1
pass_band_db = peak_db
Expand All @@ -125,14 +126,16 @@ def runAnalysis(self):
break

lower_cutoff_frequency = self.app.data.s21[lower_cutoff_location].freq
lower_cutoff_gain = self.app.data.s21[lower_cutoff_location].gain - pass_band_db
lower_cutoff_gain = (
self.app.data.s21[lower_cutoff_location].gain - pass_band_db)

if lower_cutoff_gain < -4:
logger.debug("Lower cutoff frequency found at %f dB"
" - insufficient data points for true -3 dB point.",
lower_cutoff_gain)

logger.debug("Found true lower cutoff frequency at %d", lower_cutoff_frequency)
logger.debug("Found true lower cutoff frequency at %d",
lower_cutoff_frequency)

self.lower_cutoff_label.setText(
f"{format_frequency(lower_cutoff_frequency)}"
Expand All @@ -148,14 +151,17 @@ def runAnalysis(self):
upper_cutoff_location = i
break

upper_cutoff_frequency = self.app.data.s21[upper_cutoff_location].freq
upper_cutoff_gain = self.app.data.s21[upper_cutoff_location].gain - pass_band_db
upper_cutoff_frequency = (
self.app.data.s21[upper_cutoff_location].freq)
upper_cutoff_gain = (
self.app.data.s21[upper_cutoff_location].gain - pass_band_db)
if upper_cutoff_gain < -4:
logger.debug("Upper cutoff frequency found at %f dB"
" - insufficient data points for true -3 dB point.",
upper_cutoff_gain)

logger.debug("Found true upper cutoff frequency at %d", upper_cutoff_frequency)
logger.debug("Found true upper cutoff frequency at %d",
upper_cutoff_frequency)

self.upper_cutoff_label.setText(
f"{format_frequency(upper_cutoff_frequency)}"
Expand All @@ -164,7 +170,8 @@ def runAnalysis(self):
self.app.markers[2].frequencyInput.setText(str(upper_cutoff_frequency))

span = upper_cutoff_frequency - lower_cutoff_frequency
center_frequency = math.sqrt(lower_cutoff_frequency * upper_cutoff_frequency)
center_frequency = math.sqrt(
lower_cutoff_frequency * upper_cutoff_frequency)
q = center_frequency / span

self.span_label.setText(format_frequency(span))
Expand All @@ -173,7 +180,8 @@ def runAnalysis(self):
self.quality_label.setText(str(round(q, 2)))

self.app.markers[0].setFrequency(str(round(center_frequency)))
self.app.markers[0].frequencyInput.setText(str(round(center_frequency)))
self.app.markers[0].frequencyInput.setText(
str(round(center_frequency)))

# Lower roll-off

Expand All @@ -187,7 +195,8 @@ def runAnalysis(self):
if lower_six_db_location < 0:
self.result_label.setText("Lower 6 dB location not found.")
return
lower_six_db_cutoff_frequency = self.app.data.s21[lower_six_db_location].freq
lower_six_db_cutoff_frequency = (
self.app.data.s21[lower_six_db_location].freq)
self.lower_six_db_label.setText(
format_frequency(lower_six_db_cutoff_frequency))

Expand All @@ -213,13 +222,15 @@ def runAnalysis(self):
break

if sixty_db_location > 0:
sixty_db_cutoff_frequency = self.app.data.s21[sixty_db_location].freq
sixty_db_cutoff_frequency = (
self.app.data.s21[sixty_db_location].freq)
self.lower_sixty_db_label.setText(
format_frequency(sixty_db_cutoff_frequency))
elif ten_db_location != -1 and twenty_db_location != -1:
ten = self.app.data.s21[ten_db_location].freq
twenty = self.app.data.s21[twenty_db_location].freq
sixty_db_frequency = ten * 10 ** (5 * (math.log10(twenty) - math.log10(ten)))
sixty_db_frequency = ten * \
10 ** (5 * (math.log10(twenty) - math.log10(ten)))
self.lower_sixty_db_label.setText(
f"{format_frequency(sixty_db_frequency)} (derived)")
else:
Expand Down Expand Up @@ -250,11 +261,13 @@ def runAnalysis(self):
if upper_six_db_location < 0:
self.result_label.setText("Upper 6 dB location not found.")
return
upper_six_db_cutoff_frequency = self.app.data.s21[upper_six_db_location].freq
upper_six_db_cutoff_frequency = (
self.app.data.s21[upper_six_db_location].freq)
self.upper_six_db_label.setText(
format_frequency(upper_six_db_cutoff_frequency))

six_db_span = upper_six_db_cutoff_frequency - lower_six_db_cutoff_frequency
six_db_span = (
upper_six_db_cutoff_frequency - lower_six_db_cutoff_frequency)

self.six_db_span_label.setText(
format_frequency(six_db_span))
Expand All @@ -281,7 +294,8 @@ def runAnalysis(self):
break

if sixty_db_location > 0:
sixty_db_cutoff_frequency = self.app.data.s21[sixty_db_location].freq
sixty_db_cutoff_frequency = (
self.app.data.s21[sixty_db_location].freq)
self.upper_sixty_db_label.setText(
format_frequency(sixty_db_cutoff_frequency))
elif ten_db_location != -1 and twenty_db_location != -1:
Expand Down
Loading

0 comments on commit 6630568

Please sign in to comment.