Skip to content

Commit

Permalink
Channel Analyzer: display trace max and average power. Interim state #1
Browse files Browse the repository at this point in the history
  • Loading branch information
f4exb committed Oct 27, 2015
1 parent 681863b commit ed6e078
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 5 deletions.
5 changes: 5 additions & 0 deletions include/gui/glscope.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ class SDRANGEL_API GLScope: public QGLWidget {
std::vector<Complex> m_rawTrace;
std::vector<Complex> m_mathTrace;
std::vector<Complex>* m_displayTrace;
std::vector<Real> m_powTrace;
Real m_maxPow;
Real m_sumPow;
int m_oldTraceSize;
int m_sampleRate;
Real m_amp1;
Expand All @@ -110,6 +113,7 @@ class SDRANGEL_API GLScope: public QGLWidget {
ScopeVis::TriggerChannel m_triggerChannel;
Real m_triggerLevel;
Real m_triggerPre;
int m_nbPow;

// graphics stuff
QRectF m_glScopeRect1;
Expand Down Expand Up @@ -145,6 +149,7 @@ class SDRANGEL_API GLScope: public QGLWidget {

void handleMode();
void applyConfig();
void drawPowerOverlay();

protected slots:
void tick();
Expand Down
56 changes: 51 additions & 5 deletions sdrbase/gui/glscope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#include <algorithm>
#include <QDebug>

/*
#ifdef _WIN32
static double log2f(double n)
{
return log(n) / log(2.0);
}
#endif
#endif*/

GLScope::GLScope(QWidget* parent) :
QGLWidget(parent),
Expand Down Expand Up @@ -360,7 +361,8 @@ void GLScope::paintGL()
}

// paint trace
if(m_displayTrace->size() > 0) {
if(m_displayTrace->size() > 0)
{
glPushMatrix();
glTranslatef(m_glScopeRect1.x(), m_glScopeRect1.y() + m_glScopeRect1.height() / 2.0, 0);
glScalef(m_glScopeRect1.width() * (float)m_timeBase / (float)(m_displayTrace->size() - 1), -(m_glScopeRect1.height() / 2) * m_amp1, 1);
Expand All @@ -375,20 +377,55 @@ void GLScope::paintGL()
start--;
float posLimit = 1.0 / m_amp1;
float negLimit = -1.0 / m_amp1;

glBegin(GL_LINE_STRIP);
for(int i = start; i < end; i++) {

for(int i = start; i < end; i++)
{
float v = (*m_displayTrace)[i].real() + m_ofs1;
if(v > posLimit)
v = posLimit;
else if(v < negLimit)
v = negLimit;
glVertex2f(i - start, v);

if (m_mode == ModeMagdBPha)
{
if (i == start)
{
m_maxPow = m_powTrace[i];
m_sumPow = m_powTrace[i];
}
else
{
if (m_powTrace[i] > m_maxPow)
{
m_maxPow = m_powTrace[i];
}

m_sumPow += m_powTrace[i];
}
}
}

m_nbPow = end - start;

glEnd();

//glDisable(GL_LINE_SMOOTH);
glPopMatrix();
}

// Paint powers overlays

if (m_mode == ModeMagdBPha)
{
if (m_nbPow > 0)
{
qDebug("%.1f %.1f", 10.0f * log10f(m_maxPow), 10.0f * log10f(m_sumPow / m_nbPow));
}
}

// paint trigger time line if pretriggered
/*
if ((m_triggerPre > 0.0) &&
Expand Down Expand Up @@ -716,11 +753,15 @@ void GLScope::handleMode()
}
case ModeMagdBPha: {
m_mathTrace.resize(m_rawTrace.size());
m_powTrace.resize(m_rawTrace.size());
std::vector<Complex>::iterator dst = m_mathTrace.begin();
Real mult = (10.0f / log2f(10.0f));
std::vector<Real>::iterator powDst = m_powTrace.begin();
//Real mult = (10.0f / log2f(10.0f));
for(std::vector<Complex>::const_iterator src = m_rawTrace.begin(); src != m_rawTrace.end(); ++src) {
Real v = src->real() * src->real() + src->imag() * src->imag();
v = (100.0 - m_ofs*100.0 + (mult * log2f(v))) / 100.0; // TODO: first term is the offset
*powDst++ = v;
//v = (100.0 - m_ofs*100.0 + (mult * log2f(v))) / 100.0; // TODO: first term is the offset
v = (100.0f - m_ofs*100.0f + (10.0f * log10f(v))) / 100.0f; // TODO: first term is the offset
*dst++ = Complex(v, arg(*src) / M_PI);
}
m_displayTrace = &m_mathTrace;
Expand Down Expand Up @@ -764,6 +805,11 @@ void GLScope::handleMode()
}
}

void GLScope::drawPowerOverlay()
{

}

void GLScope::applyConfig()
{
m_configChanged = false;
Expand Down

0 comments on commit ed6e078

Please sign in to comment.