35#ifndef PeakDetectionFilter_h
36#define PeakDetectionFilter_h
41 Peak(int64_t x,
float y,
float fwhm)
47 bool operator<(
const Peak& rhs)
const
48 {
return (m_y < rhs.m_y); }
61 const std::vector<Peak>& GetPeaks()
65 __attribute__((noinline))
66 void FindPeaks(T* cap, int64_t max_peaks,
float search_hz)
69 AssertTypeIsAnalogWaveform(cap);
71 size_t nouts = cap->size();
72 if( (max_peaks == 0) || (nouts < 2) )
77 cap->PrepareForCpuAccess();
82 int64_t search_bins = ceil(search_hz / binsize);
83 int64_t search_rad = search_bins/2;
84 search_rad = std::max(search_rad, (int64_t)1);
89 std::vector<Peak> peaks;
90 ssize_t nend = nouts-1;
93 for(ssize_t i=minpeak; i<(ssize_t)nouts; i++)
96 ssize_t left = std::max((ssize_t)minpeak, (ssize_t)(i - search_rad));
97 ssize_t right = std::min((ssize_t)(i + search_rad), (ssize_t)nend);
99 float target = cap->m_samples[i];
101 for(ssize_t j=left; j<=right; j++)
105 if(cap->m_samples[j] >= target)
121 ssize_t fine_rad = 10;
122 left = std::max((ssize_t)1, i - fine_rad);
123 right = std::min(i + fine_rad, (ssize_t)nouts-1);
127 for(ssize_t j=left; j<=right; j++)
129 total += GetSampleTimesIndex(cap, j);
130 count += cap->m_samples[j];
132 ssize_t peak_location = round(total / count);
136 float hmtarget = (target - baseline)/2 + baseline;
137 ssize_t hmleft = target;
138 ssize_t hmright = target;
139 for(ssize_t j=i; j >= 0; j--)
142 if(cap->m_samples[j] <= hmtarget)
148 for(ssize_t j=i; j < (ssize_t)nouts; j++)
151 if(cap->m_samples[j] <= hmtarget)
159 peaks.push_back(
Peak(peak_location, target, fwhm));
167 std::sort(peaks.rbegin(), peaks.rend(), std::less<Peak>());
169 for(
size_t i=0; i<(size_t)max_peaks && i<peaks.size(); i++)
170 m_peaks.push_back(peaks[i]);
175 std::vector<Peak> m_peaks;
192 void FindPeaks(T* cap)
194 PeakDetector::FindPeaks(
196 m_parameters[m_numpeaksname].GetIntVal(),
197 m_parameters[m_peakwindowname].GetFloatVal());
200 std::string m_numpeaksname;
201 std::string m_peakwindowname;
Abstract base class for all filter graph blocks which are not physical instrument channels.
Definition: Filter.h:95
static float GetMinVoltage(SparseAnalogWaveform *s, UniformAnalogWaveform *u)
Gets the lowest voltage of a waveform.
Definition: Filter.h:442
Category
Category the filter should be displayed under in the GUI.
Definition: Filter.h:108
A filter that does peak detection.
Definition: PeakDetectionFilter.h:184
Definition: PeakDetectionFilter.h:56
Definition: PeakDetectionFilter.h:39
int64_t GetOffsetScaled(T *wfm, size_t i)
Returns the offset of a sample from the start of the waveform, in X axis units.
Definition: Waveform.h:702