Change the quadrature demod filter to sync block

Seems that there is a probleb with general blocks and the history, so
the filter cannot act as valve. However, it produces zeros, in the
presence of noise.
This commit is contained in:
Manolis Surligas 2018-01-17 14:16:41 +02:00
parent 0d5b295969
commit c1677c8104
4 changed files with 33 additions and 29 deletions

View File

@ -8,9 +8,16 @@
<param> <param>
<name>Threshold</name> <name>Threshold</name>
<key>thresh</key> <key>thresh</key>
<value>math.pi</value> <value>1.0</value>
<type>real</type> <type>real</type>
</param> </param>
<param>
<name>Window Size</name>
<key>win</key>
<value>80</value>
<type>int</type>
</param>
<!-- Make one 'sink' node per input. Sub-nodes: <!-- Make one 'sink' node per input. Sub-nodes:
* name (an identifier for the GUI) * name (an identifier for the GUI)

View File

@ -23,7 +23,7 @@
#define INCLUDED_SATNOGS_QUAD_DEMOD_FILTER_FF_H #define INCLUDED_SATNOGS_QUAD_DEMOD_FILTER_FF_H
#include <satnogs/api.h> #include <satnogs/api.h>
#include <gnuradio/block.h> #include <gnuradio/sync_block.h>
namespace gr { namespace gr {
namespace satnogs { namespace satnogs {
@ -50,7 +50,7 @@ namespace gr {
* \ingroup satnogs * \ingroup satnogs
* *
*/ */
class SATNOGS_API quad_demod_filter_ff : virtual public gr::block class SATNOGS_API quad_demod_filter_ff : virtual public gr::sync_block
{ {
public: public:
typedef boost::shared_ptr<quad_demod_filter_ff> sptr; typedef boost::shared_ptr<quad_demod_filter_ff> sptr;
@ -58,8 +58,8 @@ namespace gr {
/** /**
* Creates a Quadrature Demodulate filter. The block will output samples * Creates a Quadrature Demodulate filter. The block will output samples
* only in signal presence acting as a valve to reduce false alarms of * only in signal presence acting as a "valve" to reduce false alarms of
* the FSK decoders. * the FSK decoders. In case of no signal, zero samples are produced.
* *
* @param gain this MUST be the gain set on the quadrature demodulate * @param gain this MUST be the gain set on the quadrature demodulate
* gain or an appropriate value if the amplitude of the quadrature * gain or an appropriate value if the amplitude of the quadrature

View File

@ -40,9 +40,9 @@ namespace gr {
*/ */
quad_demod_filter_ff_impl::quad_demod_filter_ff_impl (float gain, quad_demod_filter_ff_impl::quad_demod_filter_ff_impl (float gain,
int window) : int window) :
gr::block ("quad_demod_filter_ff", gr::sync_block ("quad_demod_filter_ff",
gr::io_signature::make (1, 1, sizeof(float)), gr::io_signature::make (1, 1, sizeof(float)),
gr::io_signature::make (1, 1, sizeof(float))), gr::io_signature::make (1, 1, sizeof(float))),
d_gain (gain), d_gain (gain),
d_norm (1.0f / window), d_norm (1.0f / window),
d_win (window), d_win (window),
@ -53,7 +53,7 @@ namespace gr {
if(window < 1) { if(window < 1) {
throw std::invalid_argument ("Window must be a positive"); throw std::invalid_argument ("Window must be a positive");
} }
set_history (2 * window); set_history (window);
} }
/* /*
@ -86,15 +86,12 @@ namespace gr {
} }
int int
quad_demod_filter_ff_impl::general_work ( quad_demod_filter_ff_impl::work (int noutput_items,
int noutput_items, gr_vector_int &ninput_items, gr_vector_const_void_star &input_items,
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
gr_vector_void_star &output_items)
{ {
const float *in = (const float *) input_items[0]; const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0]; float *out = (float *) output_items[0];
int available = std::min(ninput_items[0], noutput_items);
int produced = 0;
float m; float m;
float m_sq; float m_sq;
float snr; float snr;
@ -102,9 +99,9 @@ namespace gr {
float in_new; float in_new;
float diff; float diff;
for(int i = 0; i < available; i++) { for (int i = 0; i < noutput_items; i++) {
in_old = std::abs(in[i + d_win]); in_old = std::abs (in[i]);
in_new = std::abs(in[i + 2*d_win - 1]); in_new = std::abs (in[i + d_win - 1]);
d_sum -= in_old; d_sum -= in_old;
d_sum += in_new; d_sum += in_new;
d_sum_sq -= (in_old * in_old); d_sum_sq -= (in_old * in_old);
@ -112,7 +109,7 @@ namespace gr {
m = (d_sum * d_norm); m = (d_sum * d_norm);
m_sq = (d_sum_sq * d_norm); m_sq = (d_sum_sq * d_norm);
snr = m * inv_sqrt(m_sq - m*m); snr = m * inv_sqrt (m_sq - m * m);
/* /*
* If the SNR is high enough start passing the data to the output. * If the SNR is high enough start passing the data to the output.
@ -120,19 +117,21 @@ namespace gr {
* from the buffered and let a window of samples to pass after the * from the buffered and let a window of samples to pass after the
* trigger is off * trigger is off
*/ */
if(snr > d_gain * 1.8) { if (snr > d_gain * 1.8) {
d_remaining = 2*d_win; d_remaining = 2 * d_win;
} }
if(d_remaining) { if (d_remaining) {
out[produced++] = in[i]; out[i] = in[i];
d_remaining--; d_remaining--;
} }
else {
out[i] = 0.0f;
}
} }
// Tell runtime system how many output items we produced. // Tell runtime system how many output items we produced.
consume_each(available); return noutput_items;
return produced;
} }
} /* namespace satnogs */ } /* namespace satnogs */

View File

@ -40,11 +40,9 @@ namespace gr {
quad_demod_filter_ff_impl(float gain, int window); quad_demod_filter_ff_impl(float gain, int window);
~quad_demod_filter_ff_impl(); ~quad_demod_filter_ff_impl();
// Where all the action really happens
int int
general_work (int noutput_items, gr_vector_int &ninput_items, work (int noutput_items, gr_vector_const_void_star &input_items,
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
gr_vector_void_star &output_items);
}; };
} // namespace satnogs } // namespace satnogs