LoRa modem with LimeSDR

LoRa is a chirp-based modulation format that can operate beneath the noise floor. Its robust, low power, and low rate — and a candidate technology for connecting the Internet of Things. In this blog I will cover the basics of LoRa modulation, show off the LoRa PHY blocks for Pothos, and demonstrate simple relay and client applications using a pair of LimeSDRs.

TLDR; = scroll down for the demo videos!

LoRa Modulation basics

The LoRa modulation is defined by 3 main parameters: spread factor (SF), bandwidth (BW) and carrier frequency. The job of the modulator is to translate symbols consisting of SF bits into chirps that span 2^SF samples at the specified sample rate (BW). A chip is simply a tone that sweeps from -BW/2 to +BW/2. Transmit symbols are modulated into the chirp by circularly shifting the base chirp waveform. Therfore SF bits in the input symbol translate into 2^SF unique shifts of the base chirp waveform.

An important aspect of the modulation is that for every additional symbol bit, we double the number of output samples needed to modulate a symbol. This makes a LoRa a very slow modulation with packets taking 100s of milliseconds to transmit. However, this redundancy also makes LoRa a very robust modulation capable of being demodulated beneath the level of the noise floor. The following plot demonstrates several symbols being modulated into chips. Frequency demodulation is a useful way to visualise this waveform because it shows the shifted chirps as simple ramping waveforms.

plot0_modDemodulation techniques

LoRa demodulation is fairly straightforward. First de-chirp the waveform my multiplying by the conjugate chirp, this turns each modulated symbol into regions of constant frequency. Next take the FFT of each region. The location of the peak bin in the FFT (also known as argmax) will tell us the value of the symbol, even in the presence of very high noise. This is how 2^SF FFT bins become transformed back into SF bits which compose the index of the FFT bin.

But wait! We can’t extract symbols yet, without first aligning to the received chips. Fortunately, the transmitted sequence includes a long detect sequence composed of multiple base chirps. Without knowing the alignment offset, we can simply perform the same detection sequence with the conjugate chirp and the FFT. The measured value will tell us the shift of the chirp — which in this case, tells us show much to shift in time to achieve alignment. In addition, a transmitted frame will also contain known frame synchronization symbols to establish the first symbol of a frame.

The following plot demonstrates the down-conversion of the chirps. An intentional partial chirp was inserted to demonstrate the technique of synchronizing to the detect sequence. And again, the frequency demodulation comes in handy again to visualise the regions of constant frequency.

plot1_demodAnd here we can see the recovered symbol encoded as the peak index in the FFT. Note that this is an idealized demonstration and in practice these index measurements will differ by +/- 1 position. Fortunately, the decoder has multiple ways to recover from single position errors.  plot2_ffts

Digital encoding

Another aspect of LoRa is how arbitrary payloads of bytes are encoded into packets of transmit symbols and decoded back into bytes. The encoding and decoding process is split into several smaller actions, each of which is reversible and may offer its own configuration options. The decoder process is basically the reverse of the encoder, so we will cover the encoder steps in order here:lora_digital_processing

  • Whitening is an optional step that can take the form of Manchester encoding or scrambling. The job of whitening is to ensure that there are no long stretches of all 0’s or all 1’s in the payload that may bias the signal in some way.
  • A header and CRC are added to encode the length of the packet and the checksum of all bytes in the packet. The header can potentially specify the encoding parameters so that the decoder can operate blindly without configuration hints.
  • Every nibble of the input payload is transformed into a codeword with additional error coding bits — the number of redundant bits (RDD) is configurable from 0 to 4. Using Hamming(4, 7) codes and Hamming(4, 8) with additional parity bit we can correct single bit errors.
  • Interleaving is a process of distributing bits from the codewords into the output symbols. Each codeword contains 4+RDD bits, and each output symbol contains SF bits (the spread factor). Therefore it takes SF codewords to produce every (4+RDD) symbols. Its also possible to use a reduced symbol set where the output symbol uses less than SF bits. In this case the packet takes more time in the air but gains increased resilience to measurement error.
  • Finally, the output symbol is Gray decoded to produce the actual value used to shift the base chirp. Notice that this is the opposite process of Gray encoding. When the demodulator measures the frequency, its very likely to exhibit a +/-1 measurement error. Gray encoding the received symbol basically converts this small measurement error into a single bit error which can be easily handled by the error correction.

Using LoRa in Pothos

The MyriadRF LoRa-SDR repository provides modulation and encoding blocks for Pothos that implement the techniques explained above:

lora_blocks1

  • LoRa modulator: The modulation block accepts a packet of transmit symbols and performs the chirp modulation. Detect and frame synchronization symbols are inserted as well.
  • LoRa demodulator: The demodulation block accepts received samples from a SDR source block and performs demodulation searching for the frame sync and extracting a packet of symbols.
  • LoRa encoder: The encoder block is responsible for encoding the user’s payload of bytes into a packet of transmit symbols using configurable bit-rate, error correction, and spreading factor.
  • LoRa decoder: The decoder accepts a packet of received symbols from the demodulation block and performs decoding and error correction. Bad packets can be dropped when they fail CRC.
  • SDR Blocks: The waveform bandwidth and carrier frequency are specified by the sample rate and centre frequency of the SDR blocks.

Notes on the completeness of the LoRa phy blocks: As of posting this blog, the LoRa demodulator block is capable of demodulating and synchronizing to the waveform transmitted by the RN2483. However the decoder does not currently match the exact header and bit patterns exhibited by the RN2483. More work will be needed on the encoder and decoder blocks to support the exact packet format used by the RN2483 and possibly other existing LoRa-capable devices. The reversing LoRa document by Matt Knight is an excellent breakdown of the decoding process and should help to close this gap.

Modem and channel simulation

The following screencast demonstrates the use of the Pothos LoRa blocks in a loop-back environment and how added noise affects the system. The topology used in the screencast can be found in the LoRa-SDR examples directory.

LoRa relay with LimeSDR

In this replay demonstration, I show two PCs exchanging messages over the LimeSDR using the LoRa blocks. The first PC will act as a simple relay, demodulating and decoding LoRa packets and re-encoding and re-transmitting the packets using a different synchronization word and frequency. The second PC will be a manned client which will transmit messages based on user input and receive them back re-transmitted through the relay.

Conclusions

LoRa was an interesting protocol to learn about. I found the chirp demodulation technique intriguing yet simple, and I enjoyed understanding the design trade-offs for robustness vs. over-the-air time. Moving forward, I think the demodulator may be able to benefit from some additional synchronization tweaks; and I would like to improve the encoder and decoder blocks to be able to handle the format for off-the-shelf LoRa chips such as RN2483. It would be also interesting to see what sort of line-of-sight distance can be achieved with LimeSDR using higher transmit power comparable to an existing LoRa solution.

References:

 

9 Responses to “LoRa modem with LimeSDR”

  1. Thanks for the very informative post and video. I see that you were able to use the LimeSDR to generate a single channel of LoRa, is it possible to use the same setup to handle several channels of LoRa, I think there are eight? So the question is could/should you use a LimeSDR as a gateway?
    The cost of a gateway at 915mhz varies greatly and there is always a need to connect the gateway to the Internet to store view and process data. I am always looking for a better, cheaper way to build a gateway.
    Your thought?
    Thanks,
    Kevin

    • It should be possible to run the LimeSDR at a higher sample rate through a filterbank which feeds N copies of the demodulator. If that’s too heavy-weight, there might be a way to replace the filterbank with a smarter block which searches for possible activate channels and selects them per demodulator rather than feeding all demodulators all of the time.

      Now transmit isnt always producing data, so one would need to decide if there will be simultaneous transmission on multiple channels, or transmissions will be serialized one channel at a time. The first approach is like the reverse of the filterbank, but which some careful batching because not all channels are producing streams to combine. The second approach could run at the rate of a single channel and just tune the LimeSDR NCO before each transmit packet.

  2. how you konw the lora using the Hamming_code ? and where to find the documents about the lora modulation detail about the FEC and whiting?

  3. Really interesting. I’ve wanted to find out a bit about LoRa modulation for some time but it’s proven difficult. This page is the most complete explanation I’ve seen.

  4. after installing the software and open the LoRa-simulation.pth, activate the topology and get the following result:

    [11:29:40.078000] Pothos.PluginLoader.load: Plugin Module Error: Pothos::PluginModule(C:\Program Files\PothosSDR\lib\Pothos\modules0.5\proxy\environment\PythonSupport.dll): failed safe load

    one question: is LimeSDR hardware connected to the software be must?

  5. Hi @vejenifu, I would have thought you could run the simulation without LimeSDR hardware, but in any case I’d try resolving any missing software dependencies.

  6. Hello, I’m trying to run RN2483.py but I have the error: could not open port /dev/ttyACM0: [Errno 2] No such file or directory: ‘/dev/ttyACM0’.
    After search in /dev I found that when I plug in the LimeSDR, it appear stream-2-1 and not ttyACM0. I modified in line 74 of file RN2483.py /dev/ttyACM0 to /dev/stream-2-1 but I have a new error: Could not configure port: (25, ‘Inappropriate ioctl for device’)
    Could someone help me on this problem ? Thank you a lot.

    What I understand in this example is, we will transmit a LoRa signal by RN2483.py and receive signal by rx_RN2483.pth. We use just one LimeSDR to do 2 jobs. But I don’t know how to choose which antenna to use ? (LimeSDR have 6 RX and 4 TX), by now I use RX1_L and TX1_1

  7. @Dien the Python script communicates with the RN2483 module and not the LimeSDR, so it needs to open whatever device corresponds to the serial port connected to the module.

Leave a Reply