diff --git a/Software/HelperTools/SignalIDSamplerates/.cproject b/Software/HelperTools/SignalIDSamplerates/.cproject
new file mode 100644
index 0000000..0a0b02f
--- /dev/null
+++ b/Software/HelperTools/SignalIDSamplerates/.cproject
@@ -0,0 +1,256 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Software/HelperTools/SignalIDSamplerates/.gitignore b/Software/HelperTools/SignalIDSamplerates/.gitignore
new file mode 100644
index 0000000..3df573f
--- /dev/null
+++ b/Software/HelperTools/SignalIDSamplerates/.gitignore
@@ -0,0 +1 @@
+/Debug/
diff --git a/Software/HelperTools/SignalIDSamplerates/.project b/Software/HelperTools/SignalIDSamplerates/.project
new file mode 100644
index 0000000..261faf8
--- /dev/null
+++ b/Software/HelperTools/SignalIDSamplerates/.project
@@ -0,0 +1,27 @@
+
+
+ SignalIDSamplerates
+
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.genmakebuilder
+ clean,full,incremental,
+
+
+
+
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
+ full,incremental,
+
+
+
+
+
+ org.eclipse.cdt.core.cnature
+ org.eclipse.cdt.core.ccnature
+ org.eclipse.cdt.managedbuilder.core.managedBuildNature
+ org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
+
+
diff --git a/Software/HelperTools/SignalIDSamplerates/.settings/language.settings.xml b/Software/HelperTools/SignalIDSamplerates/.settings/language.settings.xml
new file mode 100644
index 0000000..0c22135
--- /dev/null
+++ b/Software/HelperTools/SignalIDSamplerates/.settings/language.settings.xml
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Software/HelperTools/SignalIDSamplerates/src/SignalIDSamplerates.cpp b/Software/HelperTools/SignalIDSamplerates/src/SignalIDSamplerates.cpp
new file mode 100644
index 0000000..1bad090
--- /dev/null
+++ b/Software/HelperTools/SignalIDSamplerates/src/SignalIDSamplerates.cpp
@@ -0,0 +1,117 @@
+//============================================================================
+// Name : SignalIDSamplerates.cpp
+// Author :
+// Version :
+// Copyright : Your copyright notice
+// Description : Hello World in C++, Ansi-style
+//============================================================================
+
+#include
+#include
+#include
+#include
+using namespace std;
+
+constexpr int32_t freqRange = 20000000;
+constexpr int32_t freqStep = 4000;
+constexpr int32_t FPGA_CLK = 102400000;
+constexpr int32_t IF_freq = 250000;
+constexpr int32_t minAliasDistance = 100000;
+
+constexpr uint8_t minPrescaler = 112;
+constexpr uint8_t maxPrescaler = 180;
+constexpr uint8_t maxPrescalers = 5;
+
+int bestDistance;
+vector bestPrescalers;
+
+int Alias(int f, int f_s) {
+ // move into f_s range
+ f %= f_s;
+ if (f < 0) {
+ f += f_s;
+ }
+ // fold at half the samplerate
+ if(f >= f_s / 2) {
+ f = f_s - f;
+ }
+ return f;
+}
+
+int DistanceToIF(double f, double f_s) {
+ auto alias = Alias(f, f_s);
+ return abs(int(alias - IF_freq));
+}
+
+int farthestDistanceForFrequency(double f, vector &prescalers) {
+ int highestDistance = numeric_limits::min();
+
+ for(auto p : prescalers) {
+ double f_s = (double) FPGA_CLK / p;
+ auto dist = DistanceToIF(f, f_s);
+ if(dist > highestDistance) {
+ highestDistance = dist;
+ }
+ }
+ return highestDistance;
+}
+
+void checkPrescalers(vector &prescalers) {
+// cout << "Checking [" << prescalers[0];
+// for (auto i = prescalers.begin() + 1; i != prescalers.end(); i++) {
+// cout << ',' << *i;
+// }
+// cout << "]... ";
+ int lowestDistance = numeric_limits::max();
+ for(int freq = minAliasDistance + freqStep;freq < freqRange; freq += freqStep) {
+ int dist = farthestDistanceForFrequency(IF_freq + freq, prescalers);
+ if(dist < lowestDistance) {
+ lowestDistance = dist;
+ }
+ if(freq > 2*IF_freq + minAliasDistance) {
+ int dist = farthestDistanceForFrequency(IF_freq - freq, prescalers);
+ if(dist < lowestDistance) {
+ lowestDistance = dist;
+ }
+ }
+ if(lowestDistance < bestDistance) {
+ break;
+ }
+ }
+// cout << lowestDistance << endl;
+ if(lowestDistance > bestDistance) {
+ bestDistance = lowestDistance;
+ bestPrescalers = prescalers;
+ }
+}
+
+void recursivePrescalersTest(vector &prescalers, int depth) {
+ if(prescalers.size() >= depth) {
+ checkPrescalers(prescalers);
+ } else {
+ prescalers.push_back(0);
+ int start = minPrescaler;
+ if(prescalers.size() > 1) {
+ start = prescalers[prescalers.size() - 2] + 1;
+ }
+ for (int i = start; i <= maxPrescaler; i++) {
+ prescalers.back() = i;
+ recursivePrescalersTest(prescalers, depth);
+ }
+ prescalers.pop_back();
+ }
+}
+
+int main() {
+ vector prescalers = {112};
+ for(int d = 2;d<=maxPrescalers;d++) {
+ bestDistance = 0;
+ recursivePrescalersTest(prescalers, d);
+ cout << "Depth " << d <<": best distance: " << bestDistance << " Prescalers: [" << bestPrescalers[0];
+ for (auto i = bestPrescalers.begin() + 1; i != bestPrescalers.end(); i++) {
+ cout << ',' << *i;
+ }
+ cout << "]" << endl;
+ }
+ return 0;
+}
diff --git a/Software/PC_Application/CustomWidgets/siunitedit.cpp b/Software/PC_Application/CustomWidgets/siunitedit.cpp
index b0172f0..c20a9ef 100644
--- a/Software/PC_Application/CustomWidgets/siunitedit.cpp
+++ b/Software/PC_Application/CustomWidgets/siunitedit.cpp
@@ -87,13 +87,7 @@ bool SIUnitEdit::eventFilter(QObject *, QEvent *event)
} else if(event->type() == QEvent::FocusIn) {
// online found clumsy way to select all text when clicked!?!
// just selectAll() alone does _not_ work!
- QTimer::singleShot(0, this, &QLineEdit::selectAll);
- /*
- * However, this widget does not loose focus when clicking on a smith chart from here
- * At the same time, clicking on x-y plot does loose focus as expected
- * This behaviour existed before this mod, but it was not obvious due to properties of placeholdertext
- */
-
+ QTimer::singleShot(0, this, &SIUnitEdit::continueEditing);
}
return false;
}
@@ -102,8 +96,7 @@ void SIUnitEdit::setValueQuiet(double value)
{
_value = value;
clear();
- setPlaceholderText(Unit::ToString(value, unit, prefixes, precision)); // didn't remove it because maybe needed elsewhere
- setText(Unit::ToString(value, unit, prefixes, precision)); // because selectAll() only affects setText() (placeholder text is igonred)
+ setPlaceholderText(Unit::ToString(value, unit, prefixes, precision));
}
void SIUnitEdit::parseNewValue(double factor)
@@ -130,7 +123,7 @@ void SIUnitEdit::parseNewValue(double factor)
} else {
qWarning() << "SIUnit conversion failure:" << input;
}
-// clear(); // removed due to funny behaviour when clicking repeatedly between start, center, span, stop, but without editing anything
+ clear();
}
}
diff --git a/Software/PC_Application/CustomWidgets/siunitedit.h b/Software/PC_Application/CustomWidgets/siunitedit.h
index dc6cc93..7634b7a 100644
--- a/Software/PC_Application/CustomWidgets/siunitedit.h
+++ b/Software/PC_Application/CustomWidgets/siunitedit.h
@@ -24,9 +24,10 @@ signals:
void focusLost();
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
+private slots:
+ void continueEditing();
private:
void parseNewValue(double factor);
- void continueEditing();
QString unit, prefixes;
int precision;
double _value;
diff --git a/Software/PC_Application/SpectrumAnalyzer/spectrumanalyzer.cpp b/Software/PC_Application/SpectrumAnalyzer/spectrumanalyzer.cpp
index 7eecf2e..166246a 100644
--- a/Software/PC_Application/SpectrumAnalyzer/spectrumanalyzer.cpp
+++ b/Software/PC_Application/SpectrumAnalyzer/spectrumanalyzer.cpp
@@ -73,7 +73,9 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
// Sweep toolbar
auto tb_sweep = new QToolBar("Sweep");
auto eStart = new SIUnitEdit("Hz", " kMG", 6);
- eStart->setFixedWidth(100);
+ // calculate width required with expected string length
+ auto width = QFontMetrics(eStart->font()).width("3.00000GHz") + 15;
+ eStart->setFixedWidth(width);
eStart->setToolTip("Start frequency");
connect(eStart, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetStartFreq);
connect(this, &SpectrumAnalyzer::startFreqChanged, eStart, &SIUnitEdit::setValueQuiet);
@@ -81,7 +83,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
tb_sweep->addWidget(eStart);
auto eCenter = new SIUnitEdit("Hz", " kMG", 6);
- eCenter->setFixedWidth(100);
+ eCenter->setFixedWidth(width);
eCenter->setToolTip("Center frequency");
connect(eCenter, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetCenterFreq);
connect(this, &SpectrumAnalyzer::centerFreqChanged, eCenter, &SIUnitEdit::setValueQuiet);
@@ -89,7 +91,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
tb_sweep->addWidget(eCenter);
auto eStop = new SIUnitEdit("Hz", " kMG", 6);
- eStop->setFixedWidth(100);
+ eStop->setFixedWidth(width);
eStop->setToolTip("Stop frequency");
connect(eStop, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetStopFreq);
connect(this, &SpectrumAnalyzer::stopFreqChanged, eStop, &SIUnitEdit::setValueQuiet);
@@ -97,7 +99,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
tb_sweep->addWidget(eStop);
auto eSpan = new SIUnitEdit("Hz", " kMG", 6);
- eSpan->setFixedWidth(100);
+ eSpan->setFixedWidth(width);
eSpan->setToolTip("Span");
connect(eSpan, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetSpan);
connect(this, &SpectrumAnalyzer::spanChanged, eSpan, &SIUnitEdit::setValueQuiet);
@@ -212,7 +214,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
tb_trackgen->addWidget(dbm);
auto tgOffset = new SIUnitEdit("Hz", " kMG", 6);
- tgOffset->setFixedWidth(100);
+ tgOffset->setFixedWidth(width);
tgOffset->setToolTip("Tracking generator offset");
connect(tgOffset, &SIUnitEdit::valueChanged, this, &SpectrumAnalyzer::SetTGOffset);
connect(this, &SpectrumAnalyzer::TGOffsetChanged, tgOffset, &SIUnitEdit::setValueQuiet);
@@ -223,7 +225,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
tb_trackgen->addWidget(normalize.enable);
connect(normalize.enable, &QCheckBox::toggled, this, &SpectrumAnalyzer::EnableNormalization);
normalize.Level = new SIUnitEdit("dBm", " ", 3);
- normalize.Level->setFixedWidth(100);
+ normalize.Level->setFixedWidth(width);
normalize.Level->setValue(0);
normalize.Level->setToolTip("Level to normalize to");
tb_trackgen->addWidget(new QLabel("To:"));
diff --git a/Software/PC_Application/VNA/vna.cpp b/Software/PC_Application/VNA/vna.cpp
index 1168063..5594310 100644
--- a/Software/PC_Application/VNA/vna.cpp
+++ b/Software/PC_Application/VNA/vna.cpp
@@ -171,10 +171,11 @@ VNA::VNA(AppWindow *window)
// Sweep toolbar
- int wid = 80; // propose slight reduction, to fit more widgets comfortably
auto tb_sweep = new QToolBar("Sweep");
auto eStart = new SIUnitEdit("Hz", " kMG", 6);
- eStart->setFixedWidth(wid);
+ // calculate width required with expected string length
+ auto width = QFontMetrics(eStart->font()).width("3.00000GHz") + 15;
+ eStart->setFixedWidth(width);
eStart->setToolTip("Start frequency");
connect(eStart, &SIUnitEdit::valueChanged, this, &VNA::SetStartFreq);
connect(this, &VNA::startFreqChanged, eStart, &SIUnitEdit::setValueQuiet);
@@ -182,7 +183,7 @@ VNA::VNA(AppWindow *window)
tb_sweep->addWidget(eStart);
auto eCenter = new SIUnitEdit("Hz", " kMG", 6);
- eCenter->setFixedWidth(wid);
+ eCenter->setFixedWidth(width);
eCenter->setToolTip("Center frequency");
connect(eCenter, &SIUnitEdit::valueChanged, this, &VNA::SetCenterFreq);
connect(this, &VNA::centerFreqChanged, eCenter, &SIUnitEdit::setValueQuiet);
@@ -190,7 +191,7 @@ VNA::VNA(AppWindow *window)
tb_sweep->addWidget(eCenter);
auto eStop = new SIUnitEdit("Hz", " kMG", 6);
- eStop->setFixedWidth(wid);
+ eStop->setFixedWidth(width);
eStop->setToolTip("Stop frequency");
connect(eStop, &SIUnitEdit::valueChanged, this, &VNA::SetStopFreq);
connect(this, &VNA::stopFreqChanged, eStop, &SIUnitEdit::setValueQuiet);
@@ -198,7 +199,7 @@ VNA::VNA(AppWindow *window)
tb_sweep->addWidget(eStop);
auto eSpan = new SIUnitEdit("Hz", " kMG", 6);
- eSpan->setFixedWidth(wid);
+ eSpan->setFixedWidth(width);
eSpan->setToolTip("Span");
connect(eSpan, &SIUnitEdit::valueChanged, this, &VNA::SetSpan);
connect(this, &VNA::spanChanged, eSpan, &SIUnitEdit::setValueQuiet);
@@ -226,7 +227,8 @@ VNA::VNA(AppWindow *window)
// Acquisition toolbar
auto tb_acq = new QToolBar("Acquisition");
auto dbm = new QDoubleSpinBox();
- dbm->setFixedWidth(80); // propose slight reduction, to fit more widgets when App not maximized
+ width = QFontMetrics(dbm->font()).width("-30.00dBm") + 20;
+ dbm->setFixedWidth(width);
dbm->setRange(-100.0, 100.0);
dbm->setSingleStep(0.25);
dbm->setSuffix("dbm");