Skip to content

Commit

Permalink
adc: add marker for frequency
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Suciu <[email protected]>
  • Loading branch information
adisuciu committed Aug 26, 2024
1 parent 32d9fe0 commit b8f3fbe
Show file tree
Hide file tree
Showing 31 changed files with 965 additions and 106 deletions.
5 changes: 4 additions & 1 deletion gr-util/include/gr-util/grfftfloatproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class SCOPY_GR_UTIL_EXPORT GRFFTFloatProc : public GRProxyBlock
public:
GRFFTFloatProc(QObject *parent = nullptr);
void setWindow(gr::fft::window::win_type w);
void setWindowCorrection(bool b);
void setPowerOffset(double);
void setNrBits(int);
void build_blks(GRTopBlock *top);
Expand All @@ -31,7 +32,7 @@ class SCOPY_GR_UTIL_EXPORT GRFFTFloatProc : public GRProxyBlock
int nrBits;
QMap<gr::fft::window::win_type, double> m_wincorr_factor;
gr::fft::fft_v<float, true>::sptr fft;

bool m_windowCorr;
gr::blocks::multiply_const_ff::sptr mult_nrbits;
gr::blocks::complex_to_mag_squared::sptr ctm;
gr::blocks::multiply_const_cc::sptr mult_wind_corr;
Expand All @@ -49,6 +50,7 @@ class SCOPY_GR_UTIL_EXPORT GRFFTComplexProc : public GRProxyBlock
GRFFTComplexProc(QObject *parent = nullptr);
void setWindow(gr::fft::window::win_type w);
void setPowerOffset(double);
void setWindowCorrection(bool b);
void setNrBits(int);
void build_blks(GRTopBlock *top);
void destroy_blks(GRTopBlock *top);
Expand All @@ -57,6 +59,7 @@ class SCOPY_GR_UTIL_EXPORT GRFFTComplexProc : public GRProxyBlock
double m_powerOffset;
QMap<gr::fft::window::win_type, double> m_wincorr_factor;
int nrBits;
bool m_windowCorr;
gr::fft::fft_v<gr_complex, true>::sptr fft_complex;
gr::blocks::multiply_const_cc::sptr mult_nrbits;
gr::blocks::complex_to_mag_squared::sptr ctm;
Expand Down
20 changes: 16 additions & 4 deletions gr-util/src/grfftfloatproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ GRFFTFloatProc::GRFFTFloatProc(QObject *parent)
m_fftwindow = gr::fft::window::WIN_HANN;
m_powerOffset = 0;
nrBits = 12;
m_windowCorr = true;

m_wincorr_factor[gr::fft::window::WIN_HANN] = 2;
m_wincorr_factor[gr::fft::window::WIN_HANNING] = 2;
Expand All @@ -25,8 +26,12 @@ void GRFFTFloatProc::setWindow(gr::fft::window::win_type w)
{
m_fftwindow = w;
Q_EMIT requestRebuild();
/*if(mul)
mul->set_k(m_scale);*/
}

void GRFFTFloatProc::setWindowCorrection(bool b)
{
m_windowCorr = b;
Q_EMIT requestRebuild();
}

void GRFFTFloatProc::setPowerOffset(double val)
Expand All @@ -52,7 +57,7 @@ void GRFFTFloatProc::build_blks(GRTopBlock *top)
auto fft_size = top->vlen();

auto window = gr::fft::window::build(m_fftwindow, fft_size);
auto corr = m_wincorr_factor[m_fftwindow];
auto corr = (m_windowCorr) ? m_wincorr_factor[m_fftwindow] : 1;

fft = gr::fft::fft_v<float, true>::make(fft_size, window, false);
ctm = gr::blocks::complex_to_mag_squared::make(fft_size);
Expand Down Expand Up @@ -101,6 +106,8 @@ GRFFTComplexProc::GRFFTComplexProc(QObject *parent)
m_fftwindow = gr::fft::window::WIN_HANNING;
nrBits = 12;
m_powerOffset = 0;
m_windowCorr = true;

m_wincorr_factor[gr::fft::window::WIN_HANN] = 2;
m_wincorr_factor[gr::fft::window::WIN_HANNING] = 2;
m_wincorr_factor[gr::fft::window::WIN_BLACKMAN] = 2;
Expand All @@ -120,6 +127,11 @@ void GRFFTComplexProc::setWindow(gr::fft::window::win_type w)
mul->set_k(m_scale);*/
}

void GRFFTComplexProc::setWindowCorrection(bool b) {
m_windowCorr = b;
Q_EMIT requestRebuild();
}

void GRFFTComplexProc::setPowerOffset(double val)
{
m_powerOffset = val;
Expand All @@ -142,7 +154,7 @@ void GRFFTComplexProc::build_blks(GRTopBlock *top)
m_top = top;
auto fft_size = top->vlen();
auto window = gr::fft::window::build(m_fftwindow, fft_size);
auto corr = m_wincorr_factor[m_fftwindow];
auto corr = (m_windowCorr) ? m_wincorr_factor[m_fftwindow] : 1;
mult_nrbits = gr::blocks::multiply_const_cc::make(gr_complex(1.0 / (1<<nrBits), 1.0 / (1<<nrBits)), fft_size);
fft_complex = gr::fft::fft_v<gr_complex, true>::make(fft_size, window, true);

Expand Down
4 changes: 2 additions & 2 deletions gr-util/src/griiocomplexchannelsrc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void GRIIOComplexChannelSrc::build_blks(GRTopBlock *top)

s2v = gr::blocks::stream_to_vector::make(sizeof(gr_complex), top->vlen());

top->connect(s2f[0], 0, f2c, 1);
top->connect(s2f[1], 0, f2c, 0);
top->connect(s2f[0], 0, f2c, 0);
top->connect(s2f[1], 0, f2c, 1);
top->connect(f2c, 0, s2v, 0);
start_blk.append(s2f[0]);
start_blk.append(s2f[1]);
Expand Down
1 change: 1 addition & 0 deletions gui/include/gui/plotchannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class SCOPY_GUI_EXPORT PlotChannel : public QObject
void setYAxis(PlotAxis *newYAxis);

void setXAxis(PlotAxis *newXAxis);
double getValueAt(double pos);

public Q_SLOTS:
void raise();
Expand Down
1 change: 0 additions & 1 deletion gui/include/gui/plotcursors.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public Q_SLOTS:
void initUI();
void connectSignals();
void updateTracking();
double getHorizIntersectionAt(double pos);
};
} // namespace scopy

Expand Down
1 change: 1 addition & 0 deletions gui/include/gui/widgets/measurementpanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,6 @@ public Q_SLOTS:
QHBoxLayout *panelLayout;
QList<StatsLabel *> m_labels;
};

} // namespace scopy
#endif // MEASUREMENTPANEL_H
14 changes: 14 additions & 0 deletions gui/include/gui/widgets/measurementsettings.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef MEASUREMENTSETTINGS_H
#define MEASUREMENTSETTINGS_H

#include "menusectionwidget.h"
#include "scopy-gui_export.h"

#include <QPushButton>
Expand All @@ -23,6 +24,13 @@ class SCOPY_GUI_EXPORT MeasurementSettings : public QWidget

bool measurementEnabled();
bool statsEnabled();
bool markerEnabled();

MenuSectionWidget *getMarkerSection() const;

MenuSectionWidget *getStatsSection() const;

MenuSectionWidget *getMeasureSection() const;

Q_SIGNALS:
void toggleAllMeasurements(bool);
Expand All @@ -31,10 +39,16 @@ class SCOPY_GUI_EXPORT MeasurementSettings : public QWidget
void sortStats(MeasurementSortingType type);
void enableMeasurementPanel(bool b);
void enableStatsPanel(bool b);
void enableMarkerPanel(bool b);

private:
MenuOnOffSwitch *measurePanelSwitch;
MenuOnOffSwitch *statsPanelSwitch;
MenuOnOffSwitch *markerPanelSwitch;

MenuSectionWidget *markerSection;
MenuSectionWidget *statsSection;
MenuSectionWidget *measureSection;
};
} // namespace scopy

Expand Down
57 changes: 57 additions & 0 deletions gui/src/plotchannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,61 @@ void PlotChannel::setStyle(int newStyle)
setStyleInternal(newStyle);
Q_EMIT styleChanged();
}


double PlotChannel::getValueAt(double pos)
{
auto tmp = this;
QwtSeriesData<QPointF> *curve_data = tmp->curve()->data();
int n = curve_data->size();

if(n == 0) {
return -1;
} else {
double leftTime, rightTime, leftCustom, rightCustom;
int rightIndex = -1;
int leftIndex = -1;
int left = 0;
int right = n - 1;

if(curve_data->sample(right).x() < pos || curve_data->sample(left).x() > pos) {
return -1;
}

while(left <= right) {
int mid = (left + right) / 2;
double xData = curve_data->sample(mid).x();

if(xData == pos) {
if(mid > 0) {
leftIndex = mid - 1;
rightIndex = mid;
}
break;
} else if(xData < pos) {
left = mid + 1;
} else {
right = mid - 1;
}
}

if((leftIndex == -1 || rightIndex == -1) && left > 0) {
leftIndex = left - 1;
rightIndex = left;
}
if(leftIndex == -1 || rightIndex == -1) {
return -1;
}

leftTime = curve_data->sample(leftIndex).x();
rightTime = curve_data->sample(rightIndex).x();

leftCustom = curve_data->sample(leftIndex).y();
rightCustom = curve_data->sample(rightIndex).y();

double value = (rightCustom - leftCustom) / (rightTime - leftTime) * (pos - leftTime) + leftCustom;

return value;
}
}
#include "moc_plotchannel.cpp"
60 changes: 3 additions & 57 deletions gui/src/plotcursors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ void PlotCursors::displayIntersection()
plotMarker1->setAxes(xaxis, yaxis);
plotMarker2->setAxes(xaxis, yaxis);

plotMarker1->setValue(h1CursorPos, getHorizIntersectionAt(h1CursorPos));
plotMarker2->setValue(h2CursorPos, getHorizIntersectionAt(h2CursorPos));
auto ch = m_plot->selectedChannel();
plotMarker1->setValue(h1CursorPos, ch->getValueAt(h1CursorPos));
plotMarker2->setValue(h2CursorPos, ch->getValueAt(h2CursorPos));

Q_EMIT m_yCursors.first->scalePosChanged(plotMarker1->yValue());
Q_EMIT m_yCursors.second->scalePosChanged(plotMarker2->yValue());
Expand All @@ -170,60 +171,5 @@ void PlotCursors::setXHandlePos(HandlePos pos)
m_xCursors.second->handle()->setHandlePos(pos);
}

double PlotCursors::getHorizIntersectionAt(double pos)
{
auto tmp = m_plot->selectedChannel();
QwtSeriesData<QPointF> *curve_data = tmp->curve()->data();
int n = curve_data->size();

if(n == 0) {
return -1;
} else {
double leftTime, rightTime, leftCustom, rightCustom;
int rightIndex = -1;
int leftIndex = -1;
int left = 0;
int right = n - 1;

if(curve_data->sample(right).x() < pos || curve_data->sample(left).x() > pos) {
return -1;
}

while(left <= right) {
int mid = (left + right) / 2;
double xData = curve_data->sample(mid).x();

if(xData == pos) {
if(mid > 0) {
leftIndex = mid - 1;
rightIndex = mid;
}
break;
} else if(xData < pos) {
left = mid + 1;
} else {
right = mid - 1;
}
}

if((leftIndex == -1 || rightIndex == -1) && left > 0) {
leftIndex = left - 1;
rightIndex = left;
}
if(leftIndex == -1 || rightIndex == -1) {
return -1;
}

leftTime = curve_data->sample(leftIndex).x();
rightTime = curve_data->sample(rightIndex).x();

leftCustom = curve_data->sample(leftIndex).y();
rightCustom = curve_data->sample(rightIndex).y();

double value = (rightCustom - leftCustom) / (rightTime - leftTime) * (pos - leftTime) + leftCustom;

return value;
}
}

#include "moc_plotcursors.cpp"
32 changes: 29 additions & 3 deletions gui/src/widgets/measurementsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MeasurementSettings::MeasurementSettings(QWidget *parent)
// setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
lay->setMargin(0);

MenuSectionWidget *measureSection = new MenuSectionWidget(this);
measureSection = new MenuSectionWidget(this);
measurePanelSwitch = new MenuOnOffSwitch("Measure Panel", this);
measurePanelSwitch->onOffswitch()->setChecked(true);
QHBoxLayout *hlay1 = new QHBoxLayout();
Expand Down Expand Up @@ -73,7 +73,7 @@ MeasurementSettings::MeasurementSettings(QWidget *parent)
hlay2->addWidget(mesaureSortByChannel);
hlay2->addWidget(measureSortByType);

MenuSectionWidget *statsSection = new MenuSectionWidget(this);
statsSection = new MenuSectionWidget(this);
statsPanelSwitch = new MenuOnOffSwitch("Stats Panel", this);
connect(statsPanelSwitch->onOffswitch(), &QAbstractButton::toggled, this,
[=](bool b) { Q_EMIT enableStatsPanel(b); });
Expand Down Expand Up @@ -138,14 +138,40 @@ MeasurementSettings::MeasurementSettings(QWidget *parent)
hlay4->addWidget(statsSortByChannel);
hlay4->addWidget(statsSortByType);

markerSection = new MenuSectionWidget(this);
markerPanelSwitch = new MenuOnOffSwitch("Marker Panel", this);
connect(markerPanelSwitch->onOffswitch(), &QAbstractButton::toggled, this,
[=](bool b) { Q_EMIT enableMarkerPanel(b); });
markerSection->contentLayout()->addWidget(markerPanelSwitch);

markerPanelSwitch->onOffswitch()->setChecked(false);

lay->addWidget(measureSection);
lay->addWidget(statsSection);
lay->addWidget(markerSection);


}

MeasurementSettings::~MeasurementSettings() {}

bool MeasurementSettings::measurementEnabled() { return measurePanelSwitch->onOffswitch()->isChecked(); }

bool MeasurementSettings::statsEnabled() { return statsPanelSwitch->onOffswitch()->isChecked(); }
bool MeasurementSettings::markerEnabled() { return markerPanelSwitch->onOffswitch()->isChecked(); }

MenuSectionWidget *MeasurementSettings::getMarkerSection() const
{
return markerSection;
}

MenuSectionWidget *MeasurementSettings::getStatsSection() const
{
return statsSection;
}

MenuSectionWidget *MeasurementSettings::getMeasureSection() const
{
return measureSection;
}

#include "moc_measurementsettings.cpp"
1 change: 0 additions & 1 deletion gui/src/widgets/menuplotchannelcurvestylecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ void MenuPlotChannelCurveStyleControl::setThicknessSlot()
}
}

qInfo() << m_channels.count() << thickness;
cbThicknessW->combo()->setCurrentText(QString::number(thickness));
}

Expand Down
Loading

0 comments on commit b8f3fbe

Please sign in to comment.