Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: b2abc4c446ea
Choose a base ref
...
head repository: ngscopeclient/scopehal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9f362a57703f
Choose a head ref
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Sep 28, 2020

  1. Copy the full SHA
    9f362a5 View commit details
Showing with 54 additions and 24 deletions.
  1. +35 −18 scopehal/PeakDetectionFilter.cpp
  2. +19 −6 scopehal/PeakDetectionFilter.h
53 changes: 35 additions & 18 deletions scopehal/PeakDetectionFilter.cpp
Original file line number Diff line number Diff line change
@@ -35,36 +35,22 @@
using namespace std;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction
// PeakDetector

PeakDetectionFilter::PeakDetectionFilter(OscilloscopeChannel::ChannelType type, string color, Category cat)
: Filter(type, color, cat)
PeakDetector::PeakDetector()
{
m_numpeaksname = "Number of Peaks";
m_parameters[m_numpeaksname] = FilterParameter(FilterParameter::TYPE_INT, Unit(Unit::UNIT_COUNTS));
m_parameters[m_numpeaksname].SetIntVal(10);

m_peakwindowname = "Peak Window";
m_parameters[m_peakwindowname] = FilterParameter(FilterParameter::TYPE_FLOAT, Unit(Unit::UNIT_HZ));
m_parameters[m_peakwindowname].SetFloatVal(500000); //500 kHz between peaks
}

PeakDetectionFilter::~PeakDetectionFilter()
PeakDetector::~PeakDetector()
{

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

void PeakDetectionFilter::FindPeaks(AnalogWaveform* cap)
void PeakDetector::FindPeaks(AnalogWaveform* cap, int64_t max_peaks, float search_hz)
{
int64_t max_peaks = m_parameters[m_numpeaksname].GetIntVal();
size_t nouts = cap->m_samples.size();
if(max_peaks > 0)
{
//Get peak search width in bins
float search_hz = m_parameters[m_peakwindowname].GetIntVal();
int64_t search_bins = ceil(search_hz / cap->m_timescale);
search_bins = min(search_bins, (int64_t)512); //TODO: reasonable limit
int64_t search_rad = search_bins/2;
@@ -103,3 +89,34 @@ void PeakDetectionFilter::FindPeaks(AnalogWaveform* cap)
m_peaks.push_back(peaks[i]);
}
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Construction / destruction

PeakDetectionFilter::PeakDetectionFilter(OscilloscopeChannel::ChannelType type, string color, Category cat)
: Filter(type, color, cat)
{
m_numpeaksname = "Number of Peaks";
m_parameters[m_numpeaksname] = FilterParameter(FilterParameter::TYPE_INT, Unit(Unit::UNIT_COUNTS));
m_parameters[m_numpeaksname].SetIntVal(10);

m_peakwindowname = "Peak Window";
m_parameters[m_peakwindowname] = FilterParameter(FilterParameter::TYPE_FLOAT, Unit(Unit::UNIT_HZ));
m_parameters[m_peakwindowname].SetFloatVal(500000); //500 kHz between peaks
}

PeakDetectionFilter::~PeakDetectionFilter()
{

}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Actual decoder logic

void PeakDetectionFilter::FindPeaks(AnalogWaveform* cap)
{
PeakDetector::FindPeaks(
cap,
m_parameters[m_numpeaksname].GetIntVal(),
m_parameters[m_peakwindowname].GetFloatVal());
}
25 changes: 19 additions & 6 deletions scopehal/PeakDetectionFilter.h
Original file line number Diff line number Diff line change
@@ -50,24 +50,37 @@ class Peak
float m_y;
};

class PeakDetector
{
public:
PeakDetector();
virtual ~PeakDetector();

const std::vector<Peak>& GetPeaks()
{ return m_peaks; }

void FindPeaks(AnalogWaveform* cap, int64_t max_peaks, float search_hz);

protected:
std::vector<Peak> m_peaks;
};

/**
@brief A filter that does peak detection
*/
class PeakDetectionFilter : public Filter
class PeakDetectionFilter
: public Filter
, public PeakDetector
{
public:
PeakDetectionFilter(OscilloscopeChannel::ChannelType type, std::string color, Category cat);
virtual ~PeakDetectionFilter();

const std::vector<Peak>& GetPeaks()
{ return m_peaks; }

protected:
void FindPeaks(AnalogWaveform* cap);

std::string m_numpeaksname;
std::string m_peakwindowname;

std::vector<Peak> m_peaks;
};

#endif