Peak detect

- optional outputs
- make general block

git-svn-id: http://moon:8086/svn/software/trunk/projects/GnuRadio@509 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2019-05-29 16:16:42 +00:00
parent e78ef5b772
commit 0faa5a81db
4 changed files with 38 additions and 16 deletions
+2
View File
@@ -90,11 +90,13 @@
<name>out</name> <name>out</name>
<type>float</type> <type>float</type>
<vlen>$vlen</vlen> <vlen>$vlen</vlen>
<optional>1</optional>
</source> </source>
<source> <source>
<name>pbox</name> <name>pbox</name>
<type>float</type> <type>float</type>
<vlen>$vlen</vlen> <vlen>$vlen</vlen>
<optional>1</optional>
</source> </source>
<source> <source>
<name>status</name> <name>status</name>
+1 -1
View File
@@ -33,7 +33,7 @@ namespace gr {
* \ingroup jay * \ingroup jay
* *
*/ */
class JAY_API peak_detect : virtual public gr::sync_block class JAY_API peak_detect : virtual public gr::block
{ {
public: public:
typedef boost::shared_ptr<peak_detect> sptr; typedef boost::shared_ptr<peak_detect> sptr;
+27 -9
View File
@@ -39,9 +39,9 @@ namespace gr {
* The private constructor * The private constructor
*/ */
peak_detect_impl::peak_detect_impl(int vlen, float framerate, float bandwidth, float fcenter, float peak_height_min, int peak_width_min, int peak_width_max, float alpha_s, float alpha_m) peak_detect_impl::peak_detect_impl(int vlen, float framerate, float bandwidth, float fcenter, float peak_height_min, int peak_width_min, int peak_width_max, float alpha_s, float alpha_m)
: gr::sync_block("peak_detect" : gr::block("peak_detect"
, gr::io_signature::make(1, 1, vlen*sizeof(float)) , gr::io_signature::make(1, 1, vlen*sizeof(float))
, gr::io_signature::make(2, 2, vlen*sizeof(float))) , gr::io_signature::make(0, 2, vlen*sizeof(float)))
, m_vlen(vlen) , m_vlen(vlen)
, m_framerate (framerate) , m_framerate (framerate)
, m_bandwidth (bandwidth) , m_bandwidth (bandwidth)
@@ -128,10 +128,12 @@ namespace gr {
return result; return result;
} }
int void peak_detect_impl::forecast(int noutput_items, gr_vector_int& ninput_items_required)
peak_detect_impl::work(int noutput_items, {
gr_vector_const_void_star &input_items, ninput_items_required[0] = noutput_items;
gr_vector_void_star &output_items) }
int peak_detect_impl::general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
{ {
const int DATA = 0; const int DATA = 0;
const int PBOX = 1; const int PBOX = 1;
@@ -139,10 +141,16 @@ namespace gr {
int nitems_per_block = this->output_signature()->sizeof_stream_item(0)/sizeof(float); int nitems_per_block = this->output_signature()->sizeof_stream_item(0)/sizeof(float);
float *iptr = (float *)input_items[DATA]; float *iptr = (float *)input_items[DATA];
float *optr_data = (float *)output_items[DATA]; float *optr_data = nullptr;
float *optr_pbox = (float *)output_items[PBOX]; float *optr_pbox = nullptr;
for (int k = 0; k < noutput_items; k++) if (output_items.size() > 0)
{
optr_data = (float *)output_items[DATA];
optr_pbox = (float *)output_items[PBOX];
}
for (int k = 0; k < ninput_items[DATA]; k++)
{ {
// Initialization on first frame // Initialization on first frame
if (m_frameCount == 0) if (m_frameCount == 0)
@@ -369,13 +377,23 @@ namespace gr {
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// Output peak box data // Output peak box data
// ----------------------------------------------------------------- // -----------------------------------------------------------------
if (optr_data)
{
for (int i = 0; i < nitems_per_block; i++) for (int i = 0; i < nitems_per_block; i++)
{ {
*(optr_data++) = m_pXs[i]; *(optr_data++) = m_pXs[i];
}
}
if (optr_pbox)
{
for (int i = 0; i < nitems_per_block; i++)
{
*(optr_pbox++) = m_pPeakBox_abs[i]; *(optr_pbox++) = m_pPeakBox_abs[i];
} }
}
m_frameCount++; m_frameCount++;
consume(0, ninput_items[DATA]);
} }
// Tell runtime system how many output items we produced. // Tell runtime system how many output items we produced.
+3 -1
View File
@@ -326,7 +326,9 @@ namespace jay {
~peak_detect_impl(); ~peak_detect_impl();
// Where all the action really happens // Where all the action really happens
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); int general_work (int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
void forecast (int noutput_items, gr_vector_int &ninput_items_required);
private: private:
void fill(float *pDst, int length, float value); void fill(float *pDst, int length, float value);
float mean(float *pSrc, int length); float mean(float *pSrc, int length);