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))
71 [[maybe_unused]] vk::raii::CommandBuffer& cmdBuf,
72 [[maybe_unused]] std::shared_ptr<QueueHandle> queue)
75 AssertTypeIsAnalogWaveform(cap);
79 size_t nouts = cap->size();
80 if( (max_peaks == 0) || (nouts < 2) )
85 cap->PrepareForCpuAccess();
87 std::vector<Peak> peaks;
92 int64_t search_bins = ceil(search_hz / binsize);
93 int64_t search_rad = search_bins/2;
94 search_rad = std::max(search_rad, (int64_t)1);
99 ssize_t nend = nouts-1;
102 for(ssize_t i=minpeak; i<(ssize_t)nouts; i++)
105 ssize_t left = std::max((ssize_t)minpeak, (ssize_t)(i - search_rad));
106 ssize_t right = std::min((ssize_t)(i + search_rad), (ssize_t)nend);
108 float target = cap->m_samples[i];
110 for(ssize_t j=left; j<=right; j++)
114 if(cap->m_samples[j] >= target)
130 ssize_t fine_rad = 10;
131 left = std::max((ssize_t)1, i - fine_rad);
132 right = std::min(i + fine_rad, (ssize_t)nouts-1);
136 for(ssize_t j=left; j<=right; j++)
138 total += GetSampleTimesIndex(cap, j);
139 count += cap->m_samples[j];
141 ssize_t peak_location = round(total / count);
148 hmtarget = target - 3;
150 hmtarget = (target - baseline)/2 + baseline;
151 ssize_t hmleft = target;
152 ssize_t hmright = target;
153 for(ssize_t j=i; j >= 0; j--)
156 if(cap->m_samples[j] <= hmtarget)
162 for(ssize_t j=i; j < (ssize_t)nouts; j++)
165 if(cap->m_samples[j] <= hmtarget)
173 peaks.push_back(
Peak(peak_location, target, fwhm));
181 std::sort(peaks.rbegin(), peaks.rend(), std::less<Peak>());
183 for(
size_t i=0; i<(size_t)max_peaks && i<peaks.size(); i++)
186 m_peaks.push_back(peaks[i]);
195 std::vector<Peak> m_peaks;
217 void FindPeaks(T* cap, vk::raii::CommandBuffer& cmdBuf, std::shared_ptr<QueueHandle> queue)
219 PeakDetector::FindPeaks(
221 m_parameters[m_numpeaksname].GetIntVal(),
222 m_parameters[m_peakwindowname].GetFloatVal(),
228 std::string m_numpeaksname;
229 std::string m_peakwindowname;
Encapsulates a Vulkan compute pipeline and all necessary resources to use it.
Definition: ComputePipeline.h:55
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:480
Category
Category the filter should be displayed under in the GUI.
Definition: Filter.h:108
virtual Unit GetYAxisUnits(size_t stream)
Returns the Y axis unit for a specified stream.
Definition: InstrumentChannel.h:140
A filter that does peak detection.
Definition: PeakDetectionFilter.h:209
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:741