forked from robotastic/trunk-recorder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
why shouldn't we collect Power from pwr_squelch_cc()? 🤔
- Loading branch information
1 parent
761ff94
commit 62f6322
Showing
20 changed files
with
445 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* -*- c++ -*- */ | ||
/* | ||
* Copyright 2006,2012 Free Software Foundation, Inc. | ||
* | ||
* This file is part of GNU Radio | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
*/ | ||
|
||
#ifndef INCLUDED_ANALOG_PWR_SQUELCH_CC_H | ||
#define INCLUDED_ANALOG_PWR_SQUELCH_CC_H | ||
|
||
#include <gnuradio/analog/api.h> | ||
#include <gnuradio/analog/squelch_base_cc.h> | ||
#include <cmath> | ||
|
||
namespace gr { | ||
namespace analog { | ||
|
||
/*! | ||
* \brief gate or zero output when input power below threshold | ||
* \ingroup level_controllers_blk | ||
*/ | ||
class ANALOG_API pwr_squelch_cc : public squelch_base_cc, virtual public block | ||
{ | ||
protected: | ||
void update_state(const gr_complex& in) override = 0; | ||
bool mute() const override = 0; | ||
|
||
public: | ||
// gr::analog::pwr_squelch_cc::sptr | ||
typedef std::shared_ptr<pwr_squelch_cc> sptr; | ||
|
||
/*! | ||
* \brief Make power-based squelch block. | ||
* | ||
* \param db threshold (in dB) for power squelch | ||
* \param alpha Gain of averaging filter. Defaults to 0.0001. | ||
* \param ramp attack / release time in samples; a sinusodial ramp | ||
* is used. set to 0 to disable. | ||
* \param gate if true, no output if no squelch tone. | ||
* if false, output 0's if no squelch tone (default). | ||
* | ||
* The block will emit a tag with the key pmt::intern("squelch_sob") | ||
* with the value of pmt::PMT_NIL on the first item it passes, and with | ||
* the key pmt::intern("squelch_eob") on the last item it passes. | ||
*/ | ||
static sptr make(double db, double alpha = 0.0001, int ramp = 0, bool gate = false); | ||
|
||
std::vector<float> squelch_range() const override = 0; | ||
|
||
virtual double threshold() const = 0; | ||
virtual double get_pwr() const = 0; | ||
virtual void set_threshold(double db) = 0; | ||
virtual void set_alpha(double alpha) = 0; | ||
|
||
int ramp() const override = 0; | ||
void set_ramp(int ramp) override = 0; | ||
bool gate() const override = 0; | ||
void set_gate(bool gate) override = 0; | ||
bool unmuted() const override = 0; | ||
}; | ||
|
||
} /* namespace analog */ | ||
} /* namespace gr */ | ||
|
||
#endif /* INCLUDED_ANALOG_PWR_SQUELCH_CC_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* -*- c++ -*- */ | ||
/* | ||
* Copyright 2004,2006,2010,2012 Free Software Foundation, Inc. | ||
* | ||
* This file is part of GNU Radio | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
*/ | ||
|
||
#ifdef HAVE_CONFIG_H | ||
#include "config.h" | ||
#endif | ||
|
||
#include "pwr_squelch_cc_impl.h" | ||
|
||
namespace gr { | ||
namespace analog { | ||
|
||
pwr_squelch_cc::sptr | ||
pwr_squelch_cc::make(double threshold, double alpha, int ramp, bool gate) | ||
{ | ||
return gnuradio::make_block_sptr<pwr_squelch_cc_impl>(threshold, alpha, ramp, gate); | ||
} | ||
|
||
pwr_squelch_cc_impl::pwr_squelch_cc_impl(double threshold, | ||
double alpha, | ||
int ramp, | ||
bool gate) | ||
: block("pwr_squelch_cc", | ||
io_signature::make(1, 1, sizeof(gr_complex)), | ||
io_signature::make(1, 1, sizeof(gr_complex))), | ||
squelch_base_cc_impl("pwr_squelch_cc", ramp, gate), | ||
d_pwr(0), | ||
d_iir(alpha) | ||
{ | ||
set_threshold(threshold); | ||
} | ||
|
||
pwr_squelch_cc_impl::~pwr_squelch_cc_impl() {} | ||
|
||
std::vector<float> pwr_squelch_cc_impl::squelch_range() const | ||
{ | ||
std::vector<float> r(3); | ||
r[0] = -50.0; // min FIXME | ||
r[1] = +50.0; // max FIXME | ||
r[2] = (r[1] - r[0]) / 100; // step size | ||
|
||
return r; | ||
} | ||
|
||
void pwr_squelch_cc_impl::update_state(const gr_complex& in) | ||
{ | ||
d_pwr = d_iir.filter(in.real() * in.real() + in.imag() * in.imag()); | ||
} | ||
|
||
double pwr_squelch_cc_impl::get_pwr() | ||
{ | ||
double db = 10 * std::log10(d_pwr); | ||
return db; | ||
} | ||
void pwr_squelch_cc_impl::set_threshold(double db) | ||
{ | ||
gr::thread::scoped_lock l(d_setlock); | ||
d_threshold = std::pow(10.0, db / 10); | ||
} | ||
|
||
void pwr_squelch_cc_impl::set_alpha(double alpha) | ||
{ | ||
gr::thread::scoped_lock l(d_setlock); | ||
d_iir.set_taps(alpha); | ||
} | ||
|
||
} /* namespace analog */ | ||
} /* namespace gr */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* -*- c++ -*- */ | ||
/* | ||
* Copyright 2006,2012 Free Software Foundation, Inc. | ||
* | ||
* This file is part of GNU Radio | ||
* | ||
* SPDX-License-Identifier: GPL-3.0-or-later | ||
* | ||
*/ | ||
|
||
#ifndef INCLUDED_ANALOG_PWR_SQUELCH_CC_IMPL_H | ||
#define INCLUDED_ANALOG_PWR_SQUELCH_CC_IMPL_H | ||
|
||
#include "squelch_base_cc_impl.h" | ||
#include <gnuradio/analog/pwr_squelch_cc.h> | ||
#include <gnuradio/filter/single_pole_iir.h> | ||
#include <cmath> | ||
|
||
namespace gr { | ||
namespace analog { | ||
|
||
class ANALOG_API pwr_squelch_cc_impl : public pwr_squelch_cc, squelch_base_cc_impl | ||
{ | ||
private: | ||
double d_threshold; | ||
double d_pwr; | ||
filter::single_pole_iir<double, double, double> d_iir; | ||
|
||
protected: | ||
void update_state(const gr_complex& in) override; | ||
bool mute() const override { return d_pwr < d_threshold; } | ||
|
||
public: | ||
pwr_squelch_cc_impl(double db, | ||
double alpha = 0.0001, | ||
int ramp = 0, | ||
bool gate = false); | ||
~pwr_squelch_cc_impl() override; | ||
|
||
std::vector<float> squelch_range() const override; | ||
|
||
double threshold() const override { return 10 * log10(d_threshold); } | ||
void set_threshold(double db) override; | ||
double get_pwr() ; | ||
void set_alpha(double alpha) override; | ||
|
||
int ramp() const override { return squelch_base_cc_impl::ramp(); } | ||
void set_ramp(int ramp) override { squelch_base_cc_impl::set_ramp(ramp); } | ||
bool gate() const override { return squelch_base_cc_impl::gate(); } | ||
void set_gate(bool gate) override { squelch_base_cc_impl::set_gate(gate); } | ||
bool unmuted() const override { return squelch_base_cc_impl::unmuted(); } | ||
|
||
int general_work(int noutput_items, | ||
gr_vector_int& ninput_items, | ||
gr_vector_const_void_star& input_items, | ||
gr_vector_void_star& output_items) override | ||
{ | ||
return squelch_base_cc_impl::general_work( | ||
noutput_items, ninput_items, input_items, output_items); | ||
} | ||
}; | ||
|
||
} /* namespace analog */ | ||
} /* namespace gr */ | ||
|
||
#endif /* INCLUDED_ANALOG_PWR_SQUELCH_CC_IMPL_H */ |
Oops, something went wrong.