Skip to content

Commit

Permalink
new math modes DC_CH1 and DC_CH2: display the DC offset of a channel
Browse files Browse the repository at this point in the history
Signed-off-by: Martin <[email protected]>
  • Loading branch information
Ho-Ro committed Feb 18, 2022
1 parent 90bffd5 commit 658d559
Show file tree
Hide file tree
Showing 15 changed files with 267 additions and 177 deletions.
2 changes: 1 addition & 1 deletion openhantek/src/OH_BUILD.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// Do not edit, will be re-created at each commit!
#define OH_BUILD "20220218 - commit 952"
#define OH_BUILD "20220218 - commit 953"
12 changes: 9 additions & 3 deletions openhantek/src/dsosettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,14 @@ void DsoSettings::load() {
scope.voltage[ channel ].gainStepIndex = storeSettings->value( "gainStepIndex" ).toUInt();
if ( storeSettings->contains( "couplingOrMathIndex" ) ) {
scope.voltage[ channel ].couplingOrMathIndex = storeSettings->value( "couplingOrMathIndex" ).toUInt();
if ( channel < deviceSpecification->channels )
if ( channel < deviceSpecification->channels ) {
if ( scope.voltage[ channel ].couplingOrMathIndex >= deviceSpecification->couplings.size() ||
( !scope.hasACcoupling && !scope.hasACmodification ) )
scope.voltage[ channel ].couplingOrMathIndex = 0; // set to default if out of range
} else {
if ( scope.voltage[ channel ].couplingOrMathIndex > unsigned( Dso::LastMathMode ) )
scope.voltage[ channel ].couplingOrMathIndex = 0;
}
}
if ( storeSettings->contains( "inverted" ) )
scope.voltage[ channel ].inverted = storeSettings->value( "inverted" ).toBool();
Expand Down Expand Up @@ -209,9 +213,11 @@ void DsoSettings::load() {
post.spectrumLimit = storeSettings->value( "spectrumLimit" ).toDouble();
if ( storeSettings->contains( "spectrumReference" ) )
post.spectrumReference = storeSettings->value( "spectrumReference" ).toDouble();
if ( storeSettings->contains( "spectrumWindow" ) )
if ( storeSettings->contains( "spectrumWindow" ) ) {
post.spectrumWindow = Dso::WindowFunction( storeSettings->value( "spectrumWindow" ).toInt() );

if ( post.spectrumWindow > Dso::LastWindowFunction )
post.spectrumWindow = Dso::WindowFunction::HAMMING; // fall back to something useful
}
// Analysis
storeSettings->beginGroup( "analysis" );
if ( storeSettings->contains( "dummyLoad" ) )
Expand Down
36 changes: 22 additions & 14 deletions openhantek/src/post/mathchannelgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include "scopesettings.h"

MathChannelGenerator::MathChannelGenerator( const DsoSettingsScope *scope, unsigned physicalChannels )
: physicalChannels( physicalChannels ), scope( scope ) {
: mathChannel( physicalChannels ), scope( scope ) {
if ( scope->verboseLevel > 1 )
qDebug() << " MathChannelGenerator::MathChannelGenerator()";
}
Expand All @@ -22,18 +22,18 @@ MathChannelGenerator::~MathChannelGenerator() {

void MathChannelGenerator::process( PPresult *result ) {
// Math channel enabled?
if ( !scope->voltage[ physicalChannels ].used && !scope->spectrum[ physicalChannels ].used )
if ( !scope->voltage[ mathChannel ].used && !scope->spectrum[ mathChannel ].used )
return;

if ( scope->verboseLevel > 4 )
qDebug() << " MathChannelGenerator::process()" << result->tag;

DataChannel *const channelData = result->modifiableData( physicalChannels );
DataChannel *const channelData = result->modifiableData( mathChannel );
std::vector< double > &resultData = channelData->voltage.sample;

const double sign = scope->voltage[ physicalChannels ].inverted ? -1.0 : 1.0;
const double sign = scope->voltage[ mathChannel ].inverted ? -1.0 : 1.0;

if ( Dso::getMathMode( scope->voltage[ physicalChannels ] ) < Dso::MathMode::AC_CH1 ) { // binary operations
if ( Dso::getMathMode( scope->voltage[ mathChannel ] ) < Dso::MathMode::AC_CH1 ) { // binary operations
if ( result->data( 0 )->voltage.sample.empty() || result->data( 1 )->voltage.sample.empty() )
return;
// Resize the sample vector
Expand All @@ -45,7 +45,7 @@ void MathChannelGenerator::process( PPresult *result ) {
std::vector< double >::const_iterator ch2Iterator = result->data( 1 )->voltage.sample.begin();
double ( *calculate )( double, double );

switch ( Dso::getMathMode( scope->voltage[ physicalChannels ] ) ) {
switch ( Dso::getMathMode( scope->voltage[ mathChannel ] ) ) {
case Dso::MathMode::ADD_CH1_CH2:
calculate = []( double val1, double val2 ) -> double { return val1 + val2; };
break;
Expand All @@ -66,11 +66,13 @@ void MathChannelGenerator::process( PPresult *result ) {
for ( auto it = resultData.begin(), end = resultData.end(); it != end; ++it ) {
*it = sign * calculate( *ch1Iterator++, *ch2Iterator++ );
}
} else { // unary operators (calculate "AC coupling")
} else { // unary operators (calculate "AC coupling" or DC value)
unsigned src = 0;
if ( Dso::getMathMode( scope->voltage[ physicalChannels ] ) == Dso::MathMode::AC_CH1 )
if ( Dso::getMathMode( scope->voltage[ mathChannel ] ) == Dso::MathMode::AC_CH1 or
Dso::getMathMode( scope->voltage[ mathChannel ] ) == Dso::MathMode::DC_CH1 )
src = 0;
else if ( Dso::getMathMode( scope->voltage[ physicalChannels ] ) == Dso::MathMode::AC_CH2 )
else if ( Dso::getMathMode( scope->voltage[ mathChannel ] ) == Dso::MathMode::AC_CH2 or
Dso::getMathMode( scope->voltage[ mathChannel ] ) == Dso::MathMode::DC_CH2 )
src = 1;

// Resize the sample vector
Expand All @@ -84,12 +86,18 @@ void MathChannelGenerator::process( PPresult *result ) {
srcIt != srcEnd; ++srcIt ) {
average += *srcIt;
}
average /= result->data( src )->voltage.sample.size();
average /= double( result->data( src )->voltage.sample.size() );

// ... and remove DC component to get AC
auto srcIt = result->data( src )->voltage.sample.begin();
for ( auto dstIt = resultData.begin(), dstEnd = resultData.end(); dstIt != dstEnd; ++srcIt, ++dstIt ) {
*dstIt = sign * ( *srcIt - average );
}
if ( Dso::getMathMode( scope->voltage[ mathChannel ] ) == Dso::MathMode::AC_CH1 or
Dso::getMathMode( scope->voltage[ mathChannel ] ) == Dso::MathMode::AC_CH2 )
// ... and remove DC component to get AC
for ( auto dstIt = resultData.begin(), dstEnd = resultData.end(); dstIt != dstEnd; ++srcIt, ++dstIt )
*dstIt = sign * ( *srcIt - average );
else if ( Dso::getMathMode( scope->voltage[ mathChannel ] ) == Dso::MathMode::DC_CH1 or
Dso::getMathMode( scope->voltage[ mathChannel ] ) == Dso::MathMode::DC_CH2 )
// ... and show DC component
for ( auto dstIt = resultData.begin(), dstEnd = resultData.end(); dstIt != dstEnd; ++srcIt, ++dstIt )
*dstIt = sign * average;
}
}
2 changes: 1 addition & 1 deletion openhantek/src/post/mathchannelgenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class MathChannelGenerator : public Processor {
void process( PPresult * ) override;

private:
const unsigned physicalChannels;
const unsigned mathChannel;
const DsoSettingsScope *scope;
};
8 changes: 6 additions & 2 deletions openhantek/src/post/postprocessingsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include <QString>

namespace Dso {

Enum< Dso::MathMode, Dso::MathMode::ADD_CH1_CH2, Dso::MathMode::AC_CH2 > MathModeEnum;
// both Enum definitions must match the "extern" declarations in "postprocessingsettings.h"
Enum< Dso::MathMode, Dso::MathMode::ADD_CH1_CH2, Dso::MathMode::DC_CH2 > MathModeEnum;
Enum< Dso::WindowFunction, Dso::WindowFunction::RECTANGULAR, Dso::WindowFunction::FLATTOP > WindowFunctionEnum;

/// \brief Return string representation of the given math mode.
Expand All @@ -27,6 +27,10 @@ QString mathModeString( MathMode mode ) {
return QCoreApplication::tr( "CH1 AC" );
case MathMode::AC_CH2:
return QCoreApplication::tr( "CH2 AC" );
case MathMode::DC_CH1:
return QCoreApplication::tr( "CH1 DC" );
case MathMode::DC_CH2:
return QCoreApplication::tr( "CH2 DC" );
}
return QString();
}
Expand Down
9 changes: 6 additions & 3 deletions openhantek/src/post/postprocessingsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ namespace Dso {

/// \enum MathMode
/// \brief The different math modes for the math-channel.
enum class MathMode : unsigned { ADD_CH1_CH2, SUB_CH2_FROM_CH1, SUB_CH1_FROM_CH2, MUL_CH1_CH2, AC_CH1, AC_CH2 };
extern Enum< Dso::MathMode, Dso::MathMode::ADD_CH1_CH2, Dso::MathMode::AC_CH2 > MathModeEnum;

enum class MathMode : unsigned { ADD_CH1_CH2, SUB_CH2_FROM_CH1, SUB_CH1_FROM_CH2, MUL_CH1_CH2, AC_CH1, AC_CH2, DC_CH1, DC_CH2, SIZE_OF_ENUM };
// this "extern" declaration must match the Enum definition in "postprocessingsettings.cpp"
extern Enum< Dso::MathMode, Dso::MathMode::ADD_CH1_CH2, Dso::MathMode::DC_CH2 > MathModeEnum;
const auto LastMathMode = MathMode::DC_CH2;
template < class T > inline MathMode getMathMode( T &t ) { return MathMode( t.couplingOrMathIndex ); }

/// \enum WindowFunction
Expand All @@ -34,6 +35,8 @@ enum class WindowFunction : int {
BLACKMANNUTTALL, ///< Blackman-Nuttall window
FLATTOP ///< Flat top window
};
const auto LastWindowFunction = WindowFunction::FLATTOP;
// this "extern" declaration must match the Enum definition in "postprocessingsettings.cpp"
extern Enum< Dso::WindowFunction, Dso::WindowFunction::RECTANGULAR, Dso::WindowFunction::FLATTOP > WindowFunctionEnum;

QString mathModeString( MathMode mode );
Expand Down
41 changes: 25 additions & 16 deletions openhantek/translations/openhantek_de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,8 @@
<translation>Zoom --- </translation>
</message>
<message>
<location filename="../src/dsowidget.cpp" line="666"/>
<source>%L1%</source>
<translation>%L1%</translation>
<translation type="vanished">%L1%</translation>
</message>
<message>
<location filename="../src/dsowidget.cpp" line="680"/>
Expand Down Expand Up @@ -1657,72 +1656,82 @@
<translation>CH2 AC</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="41"/>
<location filename="../src/post/postprocessingsettings.cpp" line="31"/>
<source>CH1 DC</source>
<translation>CH1 DC</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="33"/>
<source>CH2 DC</source>
<translation>CH2 DC</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="45"/>
<source>Rectangular</source>
<translation>Rechteck</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="43"/>
<location filename="../src/post/postprocessingsettings.cpp" line="47"/>
<source>Hamming</source>
<translation>Hamming</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="45"/>
<location filename="../src/post/postprocessingsettings.cpp" line="49"/>
<source>Hann</source>
<translation>Hann</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="47"/>
<location filename="../src/post/postprocessingsettings.cpp" line="51"/>
<source>Cosine</source>
<translation>Cosinus</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="49"/>
<location filename="../src/post/postprocessingsettings.cpp" line="53"/>
<source>Lanczos</source>
<translation>Lanczos</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="51"/>
<location filename="../src/post/postprocessingsettings.cpp" line="55"/>
<source>Bartlett</source>
<translation>Bartlett</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="53"/>
<location filename="../src/post/postprocessingsettings.cpp" line="57"/>
<source>Triangular</source>
<translation>Dreieck</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="55"/>
<location filename="../src/post/postprocessingsettings.cpp" line="59"/>
<source>Gauss</source>
<translation>Gauss</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="57"/>
<location filename="../src/post/postprocessingsettings.cpp" line="61"/>
<source>Bartlett-Hann</source>
<translation>Bartlett-Hann</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="59"/>
<location filename="../src/post/postprocessingsettings.cpp" line="63"/>
<source>Blackman</source>
<translation>Blackman</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="63"/>
<location filename="../src/post/postprocessingsettings.cpp" line="67"/>
<source>Nuttall</source>
<translation>Nuttall</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="65"/>
<location filename="../src/post/postprocessingsettings.cpp" line="69"/>
<source>Blackman-Harris</source>
<translation>Blackman-Harris</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="67"/>
<location filename="../src/post/postprocessingsettings.cpp" line="71"/>
<source>Blackman-Nuttall</source>
<translation>Blackman-Nuttall</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="69"/>
<location filename="../src/post/postprocessingsettings.cpp" line="73"/>
<source>Flat top</source>
<translation>Flat Top</translation>
</message>
Expand Down
43 changes: 24 additions & 19 deletions openhantek/translations/openhantek_es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,11 +585,6 @@
<source>/div</source>
<translation></translation>
</message>
<message>
<location filename="../src/dsowidget.cpp" line="666"/>
<source>%L1%</source>
<translation></translation>
</message>
<message>
<location filename="../src/dsowidget.cpp" line="680"/>
<source>%1 %2 %3 %4 %5</source>
Expand Down Expand Up @@ -1443,72 +1438,82 @@
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="41"/>
<location filename="../src/post/postprocessingsettings.cpp" line="31"/>
<source>CH1 DC</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="33"/>
<source>CH2 DC</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="45"/>
<source>Rectangular</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="43"/>
<location filename="../src/post/postprocessingsettings.cpp" line="47"/>
<source>Hamming</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="45"/>
<location filename="../src/post/postprocessingsettings.cpp" line="49"/>
<source>Hann</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="47"/>
<location filename="../src/post/postprocessingsettings.cpp" line="51"/>
<source>Cosine</source>
<translation>Coseno</translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="49"/>
<location filename="../src/post/postprocessingsettings.cpp" line="53"/>
<source>Lanczos</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="51"/>
<location filename="../src/post/postprocessingsettings.cpp" line="55"/>
<source>Bartlett</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="53"/>
<location filename="../src/post/postprocessingsettings.cpp" line="57"/>
<source>Triangular</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="55"/>
<location filename="../src/post/postprocessingsettings.cpp" line="59"/>
<source>Gauss</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="57"/>
<location filename="../src/post/postprocessingsettings.cpp" line="61"/>
<source>Bartlett-Hann</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="59"/>
<location filename="../src/post/postprocessingsettings.cpp" line="63"/>
<source>Blackman</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="63"/>
<location filename="../src/post/postprocessingsettings.cpp" line="67"/>
<source>Nuttall</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="65"/>
<location filename="../src/post/postprocessingsettings.cpp" line="69"/>
<source>Blackman-Harris</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="67"/>
<location filename="../src/post/postprocessingsettings.cpp" line="71"/>
<source>Blackman-Nuttall</source>
<translation></translation>
</message>
<message>
<location filename="../src/post/postprocessingsettings.cpp" line="69"/>
<location filename="../src/post/postprocessingsettings.cpp" line="73"/>
<source>Flat top</source>
<translation></translation>
</message>
Expand Down
Loading

0 comments on commit 658d559

Please sign in to comment.