<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Erklärungsbedarf gnuradio block]]></title><description><![CDATA[<p>Hallo,<br />
für meine Arbeit möchte ich den folgenden Code modifizieren.<br />
Der Code ist Block gr_peak_detector von Gnuradio (so ungefähr wie peakdet von Matlab). Wenn ich das Messsignal über diesen Block laufen lasse, gibt der Block aus ob er einen Peak gefunden hat oder nicht, also Wert am Ausgang 1 oder 0.</p>
<p>Ich möchte jedoch das er mir Information darüber gibt wo die Peaks waren (Zeitpunkt) und wie hoch die Peaks waren (Amplitude).</p>
<p>Meine Fragen sind:<br />
- Unter welche Variablen kann ich die Information Zeit und Amplitude auslesen ?<br />
- Im Moment hat der Block nur einen Output. Wie kann ich mehr Outputs haben ?</p>
<p>Vielen Dank für Antworten von euch.<br />
VG<br />
cpp007</p>
<pre><code>/* -*- c++ -*- */
/*
 * Copyright 2007 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include &quot;config.h&quot;
#endif

#include &lt;gr_peak_detector2_fb.h&gt;
#include &lt;gr_io_signature.h&gt;
#include &lt;string.h&gt;

gr_peak_detector2_fb_sptr
gr_make_peak_detector2_fb (float threshold_factor_rise,
			   int look_ahead, float alpha)
{
  return gr_peak_detector2_fb_sptr (new gr_peak_detector2_fb (threshold_factor_rise, 
				  look_ahead, alpha));
}

gr_peak_detector2_fb::gr_peak_detector2_fb (float threshold_factor_rise, 
					    int look_ahead, float alpha)
  : gr_sync_block (&quot;peak_detector2_fb&quot;,
		   gr_make_io_signature (1, 1, sizeof(float)),
		   gr_make_io_signature2 (1, 2, sizeof(char), sizeof(float))),
    d_threshold_factor_rise(threshold_factor_rise), 
    d_look_ahead(look_ahead), d_alpha(alpha), d_avg(0.0f), d_found(false)
{
}

int
gr_peak_detector2_fb::work (int noutput_items,
			    gr_vector_const_void_star &amp;input_items,
			    gr_vector_void_star &amp;output_items) {
  float *iptr = (float *) input_items[0];
  char *optr = (char *) output_items[0];

  assert(noutput_items &gt;= 2);

  memset(optr, 0, noutput_items*sizeof(char));

  for (int i = 0; i &lt; noutput_items; i++) {

    if (!d_found) {
      // Have not yet detected presence of peak
      if (iptr[i] &gt; d_avg * (1.0f + d_threshold_factor_rise)) {
	d_found = true;
	d_look_ahead_remaining = d_look_ahead;
        d_peak_val = -(float)INFINITY;
      } 
      else {
	d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg;
      }
    } 
    else {
      // Detected presence of peak
      if (iptr[i] &gt; d_peak_val) {
        d_peak_val = iptr[i];
        d_peak_ind = i;
      } 
      else if (d_look_ahead_remaining &lt;= 0) {
        optr[d_peak_ind] = 1;
        d_found = false;
        d_avg = iptr[i];
      }

      // Have not yet located peak, loop and keep searching.
      d_look_ahead_remaining--;
    }

    // Every iteration of the loop, write debugging signal out if
    // connected:
    if (output_items.size() == 2) {
      float *sigout = (float *) output_items[1];
      sigout[i] = d_avg;
    }
  } // loop

  if (!d_found) 
    return noutput_items;

  // else if detected presence, keep searching during the next call to work.
  int tmp = d_peak_ind;
  d_peak_ind = 1;

  return tmp - 1; 
}
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/topic/267029/erklärungsbedarf-gnuradio-block</link><generator>RSS for Node</generator><lastBuildDate>Wed, 02 Sep 2026 17:20:40 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/267029.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 18 May 2010 08:46:50 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Erklärungsbedarf gnuradio block on Tue, 18 May 2010 08:46:50 GMT]]></title><description><![CDATA[<p>Hallo,<br />
für meine Arbeit möchte ich den folgenden Code modifizieren.<br />
Der Code ist Block gr_peak_detector von Gnuradio (so ungefähr wie peakdet von Matlab). Wenn ich das Messsignal über diesen Block laufen lasse, gibt der Block aus ob er einen Peak gefunden hat oder nicht, also Wert am Ausgang 1 oder 0.</p>
<p>Ich möchte jedoch das er mir Information darüber gibt wo die Peaks waren (Zeitpunkt) und wie hoch die Peaks waren (Amplitude).</p>
<p>Meine Fragen sind:<br />
- Unter welche Variablen kann ich die Information Zeit und Amplitude auslesen ?<br />
- Im Moment hat der Block nur einen Output. Wie kann ich mehr Outputs haben ?</p>
<p>Vielen Dank für Antworten von euch.<br />
VG<br />
cpp007</p>
<pre><code>/* -*- c++ -*- */
/*
 * Copyright 2007 Free Software Foundation, Inc.
 * 
 * This file is part of GNU Radio
 * 
 * GNU Radio is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * GNU Radio is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with GNU Radio; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifdef HAVE_CONFIG_H
#include &quot;config.h&quot;
#endif

#include &lt;gr_peak_detector2_fb.h&gt;
#include &lt;gr_io_signature.h&gt;
#include &lt;string.h&gt;

gr_peak_detector2_fb_sptr
gr_make_peak_detector2_fb (float threshold_factor_rise,
			   int look_ahead, float alpha)
{
  return gr_peak_detector2_fb_sptr (new gr_peak_detector2_fb (threshold_factor_rise, 
				  look_ahead, alpha));
}

gr_peak_detector2_fb::gr_peak_detector2_fb (float threshold_factor_rise, 
					    int look_ahead, float alpha)
  : gr_sync_block (&quot;peak_detector2_fb&quot;,
		   gr_make_io_signature (1, 1, sizeof(float)),
		   gr_make_io_signature2 (1, 2, sizeof(char), sizeof(float))),
    d_threshold_factor_rise(threshold_factor_rise), 
    d_look_ahead(look_ahead), d_alpha(alpha), d_avg(0.0f), d_found(false)
{
}

int
gr_peak_detector2_fb::work (int noutput_items,
			    gr_vector_const_void_star &amp;input_items,
			    gr_vector_void_star &amp;output_items) {
  float *iptr = (float *) input_items[0];
  char *optr = (char *) output_items[0];

  assert(noutput_items &gt;= 2);

  memset(optr, 0, noutput_items*sizeof(char));

  for (int i = 0; i &lt; noutput_items; i++) {

    if (!d_found) {
      // Have not yet detected presence of peak
      if (iptr[i] &gt; d_avg * (1.0f + d_threshold_factor_rise)) {
	d_found = true;
	d_look_ahead_remaining = d_look_ahead;
        d_peak_val = -(float)INFINITY;
      } 
      else {
	d_avg = d_alpha*iptr[i] + (1.0f - d_alpha)*d_avg;
      }
    } 
    else {
      // Detected presence of peak
      if (iptr[i] &gt; d_peak_val) {
        d_peak_val = iptr[i];
        d_peak_ind = i;
      } 
      else if (d_look_ahead_remaining &lt;= 0) {
        optr[d_peak_ind] = 1;
        d_found = false;
        d_avg = iptr[i];
      }

      // Have not yet located peak, loop and keep searching.
      d_look_ahead_remaining--;
    }

    // Every iteration of the loop, write debugging signal out if
    // connected:
    if (output_items.size() == 2) {
      float *sigout = (float *) output_items[1];
      sigout[i] = d_avg;
    }
  } // loop

  if (!d_found) 
    return noutput_items;

  // else if detected presence, keep searching during the next call to work.
  int tmp = d_peak_ind;
  d_peak_ind = 1;

  return tmp - 1; 
}
</code></pre>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1898833</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1898833</guid><dc:creator><![CDATA[cpp007]]></dc:creator><pubDate>Tue, 18 May 2010 08:46:50 GMT</pubDate></item></channel></rss>