Commit c1677c81 authored by Manolis Surligas's avatar Manolis Surligas

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.
parent 0d5b2959
......@@ -8,9 +8,16 @@
<param>
<name>Threshold</name>
<key>thresh</key>
<value>math.pi</value>
<value>1.0</value>
<type>real</type>
</param>
<param>
<name>Window Size</name>
<key>win</key>
<value>80</value>
<type>int</type>
</param>
<!-- Make one 'sink' node per input. Sub-nodes:
* name (an identifier for the GUI)
......
......@@ -23,7 +23,7 @@
#define INCLUDED_SATNOGS_QUAD_DEMOD_FILTER_FF_H
#include <satnogs/api.h>
#include <gnuradio/block.h>
#include <gnuradio/sync_block.h>
namespace gr {
namespace satnogs {
......@@ -50,7 +50,7 @@ namespace gr {
* \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:
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
* only in signal presence acting as a valve to reduce false alarms of
* the FSK decoders.
* only in signal presence acting as a "valve" to reduce false alarms of
* the FSK decoders. In case of no signal, zero samples are produced.
*
* @param gain this MUST be the gain set on the quadrature demodulate
* gain or an appropriate value if the amplitude of the quadrature
......
......@@ -40,9 +40,9 @@ namespace gr {
*/
quad_demod_filter_ff_impl::quad_demod_filter_ff_impl (float gain,
int window) :
gr::block ("quad_demod_filter_ff",
gr::io_signature::make (1, 1, sizeof(float)),
gr::io_signature::make (1, 1, sizeof(float))),
gr::sync_block ("quad_demod_filter_ff",
gr::io_signature::make (1, 1, sizeof(float)),
gr::io_signature::make (1, 1, sizeof(float))),
d_gain (gain),
d_norm (1.0f / window),
d_win (window),
......@@ -53,7 +53,7 @@ namespace gr {
if(window < 1) {
throw std::invalid_argument ("Window must be a positive");
}
set_history (2 * window);
set_history (window);
}
/*
......@@ -86,15 +86,12 @@ namespace gr {
}
int
quad_demod_filter_ff_impl::general_work (
int noutput_items, gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
quad_demod_filter_ff_impl::work (int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
int available = std::min(ninput_items[0], noutput_items);
int produced = 0;
float m;
float m_sq;
float snr;
......@@ -102,9 +99,9 @@ namespace gr {
float in_new;
float diff;
for(int i = 0; i < available; i++) {
in_old = std::abs(in[i + d_win]);
in_new = std::abs(in[i + 2*d_win - 1]);
for (int i = 0; i < noutput_items; i++) {
in_old = std::abs (in[i]);
in_new = std::abs (in[i + d_win - 1]);
d_sum -= in_old;
d_sum += in_new;
d_sum_sq -= (in_old * in_old);
......@@ -112,7 +109,7 @@ namespace gr {
m = (d_sum * 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.
......@@ -120,19 +117,21 @@ namespace gr {
* from the buffered and let a window of samples to pass after the
* trigger is off
*/
if(snr > d_gain * 1.8) {
d_remaining = 2*d_win;
if (snr > d_gain * 1.8) {
d_remaining = 2 * d_win;
}
if(d_remaining) {
out[produced++] = in[i];
if (d_remaining) {
out[i] = in[i];
d_remaining--;
}
else {
out[i] = 0.0f;
}
}
// Tell runtime system how many output items we produced.
consume_each(available);
return produced;
return noutput_items;
}
} /* namespace satnogs */
......
......@@ -40,11 +40,9 @@ namespace gr {
quad_demod_filter_ff_impl(float gain, int window);
~quad_demod_filter_ff_impl();
// Where all the action really happens
int
general_work (int noutput_items, gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
work (int noutput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items);
};
} // namespace satnogs
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment