[Peak Detector]

- added callbacks for dynamic parameter change

git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@535 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-06-01 09:38:51 +00:00
parent 560e8f95ec
commit a4626e99fc
4 changed files with 68 additions and 3 deletions
+6
View File
@@ -5,6 +5,12 @@
<category>[jay]</category>
<import>import jay</import>
<make>jay.peak_detect($vlen, $framerate, $bandwidth, $fcenter, $peak_thresh, $peak_hysteresis, $peak_width_min, $peak_width_max, $alpha_s, $alpha_m)</make>
<callback>set_bandwidth($bandwidth)</callback>
<callback>set_centerFrequency($fcenter)</callback>
<callback>set_peakThresh($peak_thresh)</callback>
<callback>set_peakHysteresis($peak_hysteresis)</callback>
<callback>set_peakWidthMin($peak_width_min)</callback>
<callback>set_peakWidthMax($peak_width_max)</callback>
<!-- Make one 'param' node for every Parameter you want settable from the GUI.
Sub-nodes:
* name
+7
View File
@@ -47,6 +47,13 @@ namespace gr {
* creating new instances.
*/
static sptr make(int vlen, float framerate, float bandwidth, float fcenter, float peak_thresh, float peak_hysteresis, float peak_width_min, float peak_width_max, float alpha_s, float alpha_m);
virtual void set_bandwidth(float bandwidth_Hz) = 0;
virtual void set_centerFrequency(float freq_Hz) = 0;
virtual void set_peakThresh(float thresh_dB) = 0;
virtual void set_peakHysteresis(float hysteresis_dB) = 0;
virtual void set_peakWidthMin(float width_Hz) = 0;
virtual void set_peakWidthMax(float width_Hz) = 0;
};
} // namespace jay
+44 -2
View File
@@ -48,8 +48,8 @@ namespace gr {
, m_fcenter (fcenter)
, m_peak_thresh (peak_thresh)
, m_peak_hysteresis (peak_hysteresis)
, m_peak_width_min ((int)((float)m_vlen/bandwidth*peak_width_min + 0.5f))
, m_peak_width_max ((int)((float)m_vlen/bandwidth*peak_width_max + 0.5f))
, m_peak_width_min ((int)((float)m_vlen/m_bandwidth*peak_width_min + 0.5f))
, m_peak_width_max ((int)((float)m_vlen/m_bandwidth*peak_width_max + 0.5f))
, m_alpha_s (alpha_s)
, m_alpha_m(alpha_m)
, m_frameCount(0)
@@ -98,6 +98,48 @@ namespace gr {
delete [] m_pX;
}
void peak_detect_impl::set_bandwidth(float bandwidth_Hz)
{
boost::mutex::scoped_lock guard(m_mutex);
m_bandwidth = bandwidth_Hz;
fprintf(stderr, "set_bandwidth(%f)\n", bandwidth_Hz);
}
void peak_detect_impl::set_centerFrequency(float freq_Hz)
{
boost::mutex::scoped_lock guard(m_mutex);
m_fcenter = freq_Hz;
fprintf(stderr, "set_centerFrequency(%f)\n", freq_Hz);
}
void peak_detect_impl::set_peakThresh(float thresh_dB)
{
boost::mutex::scoped_lock guard(m_mutex);
m_peak_thresh = thresh_dB;
fprintf(stderr, "set_peakThresh(%f)\n", thresh_dB);
}
void peak_detect_impl::set_peakHysteresis(float hysteresis_dB)
{
boost::mutex::scoped_lock guard(m_mutex);
fprintf(stderr, "set_peakHysteresis(%f)\n", hysteresis_dB);
m_peak_hysteresis = hysteresis_dB;
}
void peak_detect_impl::set_peakWidthMin(float width_Hz)
{
boost::mutex::scoped_lock guard(m_mutex);
fprintf(stderr, "set_peakWidthMin(%f)\n", width_Hz);
m_peak_width_min = (int)((float)m_vlen/m_bandwidth*width_Hz + 0.5f);
}
void peak_detect_impl::set_peakWidthMax(float width_Hz)
{
boost::mutex::scoped_lock guard(m_mutex);
fprintf(stderr, "set_peakWidthMax(%f)\n", width_Hz);
m_peak_width_max = (int)((float)m_vlen/m_bandwidth*width_Hz + 0.5f);
}
float peak_detect_impl::mean(float* pSrc, int length)
{
float res = 0;
+10
View File
@@ -262,6 +262,8 @@ namespace jay {
};
private:
boost::mutex m_mutex;
void check_pair(pmt::pmt_t pair)
{
pmt::pmt_t key = pmt::car(pair);
@@ -360,6 +362,14 @@ namespace jay {
float mean(float *pSrc, int length);
std::vector<int> findPeakPos(float* pSrc, int length, float thresh);
// Callbacks
void set_bandwidth(float bandwidth_Hz) override;
void set_centerFrequency(float freq_Hz) override;
void set_peakThresh(float thresh_dB) override;
void set_peakHysteresis(float hysteresis_dB) override;
void set_peakWidthMin(float width_Hz) override;
void set_peakWidthMax(float width_Hz) override;
void sort(std::vector<Peak>&peaks)
{
int n = peaks.size();