diff --git a/grc/lora_channelizer.xml b/grc/lora_channelizer.xml
deleted file mode 100644
index 578ae35..0000000
--- a/grc/lora_channelizer.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
- channelizer
- lora_channelizer
-
- import lora
- lora.channelizer($in_samp_rate, $out_samp_rate, $center_freq, $channel_list)
-
-
-
- in
- complex
-
-
-
-
- out
- complex
-
-
diff --git a/grc/lora_receiver.xml b/grc/lora_receiver.xml
index 2b54276..a015256 100644
--- a/grc/lora_receiver.xml
+++ b/grc/lora_receiver.xml
@@ -4,15 +4,14 @@
lora_lora_receiver
[LoRa]
import lora
- lora.lora_receiver($in_samp_rate, $center_freq, $channel_list, $sf, $out_samp_rate, $implicit, $cr, $crc, $reduced_rate, $conj)
+ lora.lora_receiver($samp_rate, $center_freq, $channel_list, $bandwidth, $sf, $implicit, $cr, $crc, $reduced_rate, $conj, $decimation, $disable_channelization, $disable_drift_correction)
set_center_freq($freq)
set_sf($sf)
- set_out_samp_rate($out_samp_rate)
Sample rate
- in_samp_rate
+ samp_rate
1e6
float
@@ -29,6 +28,14 @@
channel_list
[868.1e6]
float_vector
+ $disable_channelization.hide_channels
+
+
+
+ Bandwidth
+ bandwidth
+ 125000
+ int
@@ -115,10 +122,35 @@
- Output sample rate
- out_samp_rate
- 1000000
- float
+ Decimation
+ decimation
+ 1
+ int
+ part
+
+
+
+ Disable channelization
+ disable_channelization
+ enum
+ part
+
+
+
+
+
+ Disable drift correction
+ disable_drift_correction
+ False
+ bool
part
diff --git a/include/lora/channelizer.h b/include/lora/channelizer.h
index 383ebe4..3497c09 100644
--- a/include/lora/channelizer.h
+++ b/include/lora/channelizer.h
@@ -46,7 +46,7 @@ namespace gr {
* class. lora::channelizer::make is the public interface for
* creating new instances.
*/
- static sptr make(float in_samp_rate, float out_samp_rate, float center_freq, std::vector channel_list);
+ static sptr make(float samp_rate, float center_freq, std::vector channel_list, uint32_t bandwidth, uint32_t decimation);
};
} // namespace lora
diff --git a/include/lora/decoder.h b/include/lora/decoder.h
index 23def7d..6f043c2 100644
--- a/include/lora/decoder.h
+++ b/include/lora/decoder.h
@@ -702,7 +702,7 @@ namespace gr {
* class. lora::decoder::make is the public interface for
* creating new instances.
*/
- static sptr make(float samp_rate, int sf, bool implicit, uint8_t cr, bool crc, bool reduced_rate);
+ static sptr make(float samp_rate, uint32_t bandwidth, uint8_t sf, bool implicit, uint8_t cr, bool crc, bool reduced_rate, bool disable_drift_correction);
virtual void set_sf(uint8_t sf) = 0;
virtual void set_samp_rate(float samp_rate) = 0;
diff --git a/lib/channelizer_impl.cc b/lib/channelizer_impl.cc
index f020ab1..3429947 100644
--- a/lib/channelizer_impl.cc
+++ b/lib/channelizer_impl.cc
@@ -29,32 +29,31 @@ namespace gr {
namespace lora {
channelizer::sptr
- channelizer::make(float in_samp_rate, float out_samp_rate, float center_freq, std::vector channel_list) {
+ channelizer::make(float samp_rate, float center_freq, std::vector channel_list, uint32_t bandwidth, uint32_t decimation) {
return gnuradio::get_initial_sptr
- (new channelizer_impl(in_samp_rate, out_samp_rate, center_freq, channel_list));
+ (new channelizer_impl(samp_rate, center_freq, channel_list, bandwidth, decimation));
}
/*
* The private constructor
*/
- channelizer_impl::channelizer_impl(float in_samp_rate, float out_samp_rate, float center_freq, std::vector channel_list)
+ channelizer_impl::channelizer_impl(float samp_rate, float center_freq, std::vector channel_list, uint32_t bandwidth, uint32_t decimation)
: gr::hier_block2("channelizer",
gr::io_signature::make(1, 1, sizeof(gr_complex)),
gr::io_signature::make(channel_list.size(), channel_list.size(), sizeof(gr_complex))),
d_cfo(0.0)
{
- d_lpf = gr::filter::firdes::low_pass(1.0, out_samp_rate, 62500+15000, 10000, gr::filter::firdes::WIN_HAMMING, 6.67);
+ d_lpf = gr::filter::firdes::low_pass(1.0, samp_rate, (bandwidth/2)+15000, 10000, gr::filter::firdes::WIN_HAMMING, 6.67);
d_freq_offset = channel_list[0] - center_freq;
- d_xlating_fir_filter = gr::filter::freq_xlating_fir_filter_ccf::make(1, d_lpf, d_freq_offset, out_samp_rate);
+ d_xlating_fir_filter = gr::filter::freq_xlating_fir_filter_ccf::make(decimation, d_lpf, d_freq_offset, samp_rate);
d_controller = gr::lora::controller::make((void*)this);
- d_resampler = gr::filter::fractional_resampler_cc::make(0, (float)in_samp_rate / (float)out_samp_rate);
- //self.delay = delay(gr.sizeof_gr_complex, int((len(lpf)-1) / 2.0))
+ //d_resampler = gr::filter::fractional_resampler_cc::make(0, (float)in_samp_rate / (float)out_samp_rate);
+ //self.delay = delay(gr.sizeof_gr_complex, int((len(lpf)-1) / 2.0))
//Create message ports
message_port_register_hier_in(pmt::intern("control"));
- connect(self(), 0, d_resampler, 0);
- connect(d_resampler, 0, d_xlating_fir_filter, 0);
+ connect(self(), 0, d_xlating_fir_filter, 0);
connect(d_xlating_fir_filter, 0, self(), 0);
msg_connect(self(), pmt::intern("control"), d_controller, pmt::intern("control"));
diff --git a/lib/channelizer_impl.h b/lib/channelizer_impl.h
index 2683e1e..73b70f7 100644
--- a/lib/channelizer_impl.h
+++ b/lib/channelizer_impl.h
@@ -33,14 +33,14 @@ namespace gr {
class channelizer_impl : public channelizer {
private:
gr::filter::freq_xlating_fir_filter_ccf::sptr d_xlating_fir_filter;
- gr::filter::fractional_resampler_cc::sptr d_resampler;
+ //gr::filter::fractional_resampler_cc::sptr d_resampler;
std::vector d_lpf;
float d_cfo;
uint32_t d_freq_offset;
gr::lora::controller::sptr d_controller;
public:
- channelizer_impl(float in_samp_rate, float out_samp_rate, float center_freq, std::vector channel_list);
+ channelizer_impl(float samp_rate, float center_freq, std::vector channel_list, uint32_t bandwidth, uint32_t decimation);
~channelizer_impl();
void apply_cfo(float cfo);
diff --git a/lib/decoder_impl.cc b/lib/decoder_impl.cc
index cd8a993..76d6b32 100644
--- a/lib/decoder_impl.cc
+++ b/lib/decoder_impl.cc
@@ -37,15 +37,15 @@
namespace gr {
namespace lora {
- decoder::sptr decoder::make(float samp_rate, int sf, bool implicit, uint8_t cr, bool crc, bool reduced_rate) {
+ decoder::sptr decoder::make(float samp_rate, uint32_t bandwidth, uint8_t sf, bool implicit, uint8_t cr, bool crc, bool reduced_rate, bool disable_drift_correction) {
return gnuradio::get_initial_sptr
- (new decoder_impl(samp_rate, sf, implicit, cr, crc, reduced_rate));
+ (new decoder_impl(samp_rate, bandwidth, sf, implicit, cr, crc, reduced_rate, disable_drift_correction));
}
/**
* The private constructor
*/
- decoder_impl::decoder_impl(float samp_rate, uint8_t sf, bool implicit, uint8_t cr, bool crc, bool reduced_rate)
+ decoder_impl::decoder_impl(float samp_rate, uint32_t bandwidth, uint8_t sf, bool implicit, uint8_t cr, bool crc, bool reduced_rate, bool disable_drift_correction)
: gr::sync_block("decoder",
gr::io_signature::make(1, -1, sizeof(gr_complex)),
gr::io_signature::make(0, 0, 0)),
@@ -65,7 +65,7 @@ namespace gr {
d_dbg.attach();
#endif
- d_bw = 125000u;
+ d_bw = bandwidth;
d_implicit = implicit;
d_reduced_rate = reduced_rate;
d_phdr.cr = cr;
@@ -87,12 +87,16 @@ namespace gr {
d_energy_threshold = 0.0f;
d_whitening_sequence = gr::lora::prng_payload;
d_fine_sync = 0;
+ d_enable_fine_sync = !disable_drift_correction;
set_output_multiple(2 * d_samples_per_symbol);
std::cout << "Bits (nominal) per symbol: \t" << d_bits_per_symbol << std::endl;
std::cout << "Bins per symbol: \t" << d_number_of_bins << std::endl;
std::cout << "Samples per symbol: \t" << d_samples_per_symbol << std::endl;
std::cout << "Decimation: \t\t" << d_decim_factor << std::endl;
+ if(!d_enable_fine_sync) {
+ std::cout << "Warning: clock drift correction disabled" << std::endl;
+ }
if(d_implicit) {
std::cout << "CR: \t\t" << (int)d_phdr.cr << std::endl;
std::cout << "CRC: \t\t" << (int)d_phdr.has_mac_crc << std::endl;
@@ -481,7 +485,8 @@ namespace gr {
uint32_t bin_idx = max_frequency_gradient_idx(samples);
//uint32_t bin_idx = get_shift_fft(samples);
- fine_sync(samples, bin_idx, std::max(d_decim_factor / 4u, 2u));
+ if(d_enable_fine_sync)
+ fine_sync(samples, bin_idx, std::max(d_decim_factor / 4u, 2u));
// DBGR_INTERMEDIATE_TIME_MEASUREMENT();
diff --git a/lib/decoder_impl.h b/lib/decoder_impl.h
index 31a8dab..4ad3a50 100644
--- a/lib/decoder_impl.h
+++ b/lib/decoder_impl.h
@@ -120,7 +120,8 @@ namespace gr {
uint32_t d_decim_factor; ///< The number of samples (data points) in each bin.
float d_cfo_estimation; ///< An estimation for the current Center Frequency Offset.
double d_dt; ///< Indicates how fast the frequency changes in a symbol (chirp).
- int32_t d_fine_sync;
+ bool d_enable_fine_sync; ///< Enable drift correction
+ int32_t d_fine_sync; ///< Amount of drift correction to apply for next symbol
/**
* \brief TODO
@@ -415,7 +416,7 @@ namespace gr {
* \param sf
* The expected spreqding factor.
*/
- decoder_impl(float samp_rate, uint8_t sf, bool implicit, uint8_t cr, bool crc, bool reduced_rate);
+ decoder_impl(float samp_rate, uint32_t bandwidth, uint8_t sf, bool implicit, uint8_t cr, bool crc, bool reduced_rate, bool disable_drift_correction);
/**
* Default destructor.
diff --git a/python/lora_receiver.py b/python/lora_receiver.py
index cf0356d..6cd6a6d 100644
--- a/python/lora_receiver.py
+++ b/python/lora_receiver.py
@@ -27,37 +27,52 @@ class lora_receiver(gr.hier_block2):
"""
docstring for block lora_receiver
"""
- def __init__(self, in_samp_rate, center_freq, channel_list, sf, out_samp_rate, implicit, cr, crc, reduced_rate=False, conj=False):
+ def __init__(self, samp_rate, center_freq, channel_list, bandwidth, sf, implicit, cr, crc, reduced_rate=False, conj=False, decimation=1, disable_channelization=False, disable_drift_correction=False):
gr.hier_block2.__init__(self,
"lora_receiver", # Min, Max, gr.sizeof_
gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
gr.io_signature(0, 0, 0)) # Output signature
# Parameters
- self.in_samp_rate = in_samp_rate
+ self.samp_rate = samp_rate
self.center_freq = center_freq
- self.sf = sf
- self.out_samp_rate = out_samp_rate
self.channel_list = channel_list
+ self.bandwidth = bandwidth
+ self.sf = sf
+ self.implicit = implicit
+ self.cr = cr
+ self.crc = crc
+ self.decimation = decimation
self.conj = conj
+ self.disable_channelization = disable_channelization
+ self.disable_drift_correction = disable_drift_correction
# Define blocks
self.block_conj = gnuradio.blocks.conjugate_cc()
- self.channelizer = lora.channelizer(in_samp_rate, out_samp_rate, center_freq, channel_list)
- self.decoder = lora.decoder(out_samp_rate, sf, implicit, cr, crc, reduced_rate)
+ self.channelizer = lora.channelizer(samp_rate, center_freq, channel_list, bandwidth, decimation)
+ self.decoder = lora.decoder(samp_rate / decimation, bandwidth, sf, implicit, cr, crc, reduced_rate, disable_drift_correction)
# Messages
self.message_port_register_hier_out('frames')
# Connect blocks
- self.connect((self, 0), (self.channelizer, 0))
- if self.conj:
- self.connect((self.channelizer, 0), (self.block_conj, 0))
- self.connect((self.block_conj, 0), (self.decoder, 0))
+ if self.disable_channelization:
+ self.resampler = gnuradio.filter.fractional_resampler_cc(0, float(decimation))
+ self.connect((self, 0), (self.resampler, 0))
+ self._connect_conj_block_if_enabled(self.resampler, self.decoder)
else:
- self.connect((self.channelizer, 0), (self.decoder, 0))
+ self.connect((self, 0), (self.channelizer, 0))
+ self._connect_conj_block_if_enabled(self.channelizer, self.decoder)
+ self.msg_connect((self.decoder, 'control'), (self.channelizer, 'control'))
+
self.msg_connect((self.decoder, 'frames'), (self, 'frames'))
- self.msg_connect((self.decoder, 'control'), (self.channelizer, 'control'))
+
+ def _connect_conj_block_if_enabled(self, source, dest):
+ if self.conj:
+ self.connect((source, 0), (self.block_conj, 0))
+ self.connect((self.block_conj, 0), (dest, 0))
+ else:
+ self.connect((source, 0), (dest, 0))
def get_sf(self):
return self.sf