In this section, i have tried to summarize my understanding on the LoRa PHY.
For a better view, please DOWNLOAD the full PDF : https://drive.google.com/file/d/15Ws8bH7jLC_f4jJf9uanbV0ZX779Ili3/view?usp=sharing
A capture of LoRa Signal on Signal Analyzer at Microwave lab lnmiit :-
Chapter 1: Encoding Step 1: Whitening. 3
1.5 DC-Free Data Mechanism.. 5
Chapter 2: Encoding Step 2: HEADER + CRC.. 8
Chapter 3: Codewords and Interleaving. 10
3.1 Systematic/Non-Systematic Code Words. 10
Chapter 4: Decoding LoRa signal 13
4.1 Disintegrating the Original LoRa Signal 13
4.2 Prerequisites to abstract a Symbol 14
4.3 Why Dechirping? (Things getting way too Interesting) 15
To understand which part of the packet is introduced with the whitening, I have learnt about the following first.
Two modes: Continuous mode and Packet mode
· FIFO and Packet Handler Disabled.
· Direct NRZ data fed to uC.
· Fixed length Packet Format:
1. Bit “packet format” is set to 0.
2. “payload length” >0
3. Used when packet length is fixed => No length byte field is required.
4. Payload length now is just “message + optional address byte”
See Figure 1. Fixed length packet format
· Variable length Packet Format:
1. Bit “packet format” is set to 1.
2. Payload length varies over time.
3. Length byte field is must for receiver to operate properly.
4. First byte of FIFO represents length byte.
See Figure 2. Variable length Packet Format
· Unlimited length Packet Format
1. Bit “packet format” is set to 0.
2. “payload length” is also set to 0.
3. No address filtering, Manchester encoding if SyncOn=0.
4. No CRC detection, no interrupts like “CRCok” or “PayloadReady”.
See Figure 3. Unlimited length packet format
Steps that happen at Transmitter side:
· Adding Programmable Number of Preamble Bytes
· Adding Programmable Number of Synch Word
· Calculating CRC for opt. Length byte + optional Address byte + Message appending 2 bytes at end.
· Optional DC Free Encoding (Whitening or Manchester).
· Fixed length payload: Payload length is given by “Payload Length” parameter.
· In variable length payload: First byte after SYNC word is Payload Length.
1. Payload Length parameter is set to max length.
2. If incoming payload has Payload length lesser than max: Packet is discarded.
· If “address check” is enabled: -
1. Second byte in Variable length will represent the address byte.
2. First byte in Fixed length will represent the address byte.
3. If address matches with “Node Address field”, reception continues ow halt.
· If “CRCon” is enabled: -
1. If CRC check is successful => “CRCok” is set to 1.
2. “PayloadReady” interrupt is generated.
3. If CRC check is failed => No “PayloadReady” =>FIFO Cleared.
4. This CRC function can be stopped using CRCAutoClearOff = 1.
SX1276/77/78/79 packet handler provides a plenty of packet filtering ensuring only the useful packets are transferred to the uC.
Discussed in the next section.
· Received address is compared with internal node register Node Address
· Received address is compared with internal node register Node Address/Broadcast Address.
· If doesnot match, packet is discarded.
· Stripped off.
· Not stripped off, sent to FIFO.
· Checksum is calculated on the Received Payload.
· Compared with two bytes Checksum received.
· If CRC check is failed, normally halt. This function can be changed.
· This is also stripped off.
Payload may contain long chains of 1’s and 0’s. This introduces DC Biasing in the tx signal. To avoid that, two techniques are used:
· NRZ data 1 is represented ‘10’, 0 as ‘01’.
· Reduces bit rate to half.
· Only applied to payload and CRC Checksum.
· Data whitened using random sequence on tx side.
· Payload and CRC Check sum is XORed with this random sequence.
· Advantage over Manchester: NRZ data rate is maintained (no half).
· Rx again XORes the payload with the same random sequence.
· CCIT Whitening
1. Say, this is the data to be whitened.
2. This is the generated random sequence using flip-flops.
(How exactly such a sequence is generated takes me back to using the flip-flops. Thankful to the NPTEL lecture that I referred than to understand the basics right).
3. Converting Random Sequence into Bytes
4. XORing the FIFO and LFSR to get the Whitened Data.
See figure 4. Final Whitened Data
The second part of the encoding involves introducing encoding parameters in the packet to help the receiver treat the packet perfectly.
Another important feature of this part introducing the correct CRC.
Header of the tx symbol is flexible to be adjusted by using different modes.
· The header in this mode contains the following information:
1. Payload length in bytes.
2. FEC coding rate
3. Presence of CRC.
Figure 5. Requirements on the registers for CRC to be introduced.
· Both the tx and rx have the information about encoding parameters.
· This is advantageous to reduce ToA.
Figure 6. Requirements on the register for CRC to be introduced.
· Uses maximum correct code (4/8) i.e., out of RDD (0,1,2,3,4), its RDD is 4.
· It also has its own CRC.
Figure 7. LoRa Packet Structure
Addition of Redundancy bits in the information bits makes a codeword.
· When the arrangement of the codeword is such that the information bits are grouped together in one part of the code and Parity bits are grouped together.
· Example of Systematic Code:
· Arrangement of message bits and parity bits can be non-systematic as well, which coins the name Non-Systematic Coding.
· A turbo encoder is comprised of two identical convolutional codes of special type, such as, recursive systematic (RSC) type with parallel concatenation.
· An individual encoder is termed a component encoder. An interleaver separates the two component encoders. The interleaver is a device that arranges the data sequence in some predetermined manner.
· Types of interleavers a) Block interleaver, b) Diagonal interleaver, c) Odd-even block interleaver, d) Pseudo-random interleaver, e) Convolutional interleaver, f) Helical interleaver, g) Uniform interleaver, h) Cyclic shift interleaver and i) Code matched interleaver.
This was the toughest part for me to understand and I still have doubts in it. I will try to get rid of the doubts by myself in another 15 hours. I have also red highlighted the doubts.
· When the code word = symbol length (Symbol is output bitset).
· 320,321,322 represent different codewords.
· There bits are interleaved and distributed at cyclically increasing position
· First four bits = info bits; Another 3 bits = redundant bits.
· Each column is now representing a symbol.
· Each code word contains 4+RDD bits, and each output symbol contains SF bits (Spreading Factor). (This took time to catch, I am yet to confirm it from you if its right)
Figure 8. Diagonal Interleaving when Codeword length = Symbol Length
When Symbol length is greater than the code word length.
Figure 9. Diagonal Interleaving when Symbol Length > Code word Length
· When Symbol length is lesser than the code word length
Figure 10. Diagonal Interleaving for Code Word Length > Symbol Length
· It is because of not giving my 100%, I am still having these doubts. I will try to give my full to decode them by myself before I will have short interaction with you on Sunday.
· Repeated Upchirps (10): Preamble which signifies the packet has arrived. The receiver it is in stand-by mode than it wakes up in this preamble period time and gets back into RX mode.
· Down Chirps (2.25): This is frame Sync which signifies that the preamble has ended, and you got to treat the upcoming frame as a payload.
· Then the chopped chirps are what that represent the data. They seem to be arbitrarily spread across the chirp time period, but this is not actually arbitrary. That is our encoded data.
· Zooming into the Data:
1. We see the rate of change of frequency is fixed for all the encoded symbols.
2. Although, there are spikes or we can say, the instantaneous frequency changes at some points in the band.
3. These instantaneous frequency changes represent our encoded data.
4. So, it is just like Frequency modulation, in which we used to see different symbols were given different carriers. There we were modulating the data by imposing different carriers.
5. Here, we are modulating the continuous Chirp to modulate the symbol. The rate is fixed though.
This is frequency modulated Chirp.
· Our demodulator will quantify where the Chirp is breaking discontinuity.
v Multiplication of two signals of frequencies f1 and f2 will result into a signal of frequency f1+f2.
v
v And if the signals hold the properties of complex conjugate to each other.
v in the case of no phase difference between the two.
v If there is a phase difference, the multiplication will give a constant frequency signal.
v What does a negative frequency denote? => On say 125Khz BW, Centre of Band is considered to Zero, so frequencies left to this are Negative Frequencies.
v Multiplying a upchirp and downchirp:
v I was stuck here for a while and had a hard time understanding this part.
v It is best to understand physical significance through pictures.
v I found a simulator named GNUradio Companion, it is a Software Defined Radio (SDR) and one of its branches named Pothos had very interesting Simulation Blocks.
v I started tinkering with the simulator for a while to understand how to effectively use it.
v And I found LoRa blocks as well!
v Luckily, I found one GitHub repository which had a LoRa simulation Project.
v I cloned it and spent almost two days to debug the error on CMD. (That took literally two days, but voila! the project final was on my PC, running!)
VICTORY! IT WAS
Figure 11. Lora Modem
Figure 12. Widgets of LoRa Modem
· In figure 9, the received signal is dechirped using the locally generate downchirp.
· Advantage of which is seen in the Freq Demoded-dechirped widget.
· The spread spectrum of the symbols in the forms of chirps either in forms of Ramps or in the form of discontinued Ramps are now constant frequencies.
· After Dechirping with the locally generated downchirp, we have constant frequencies representing our symbols.
· One by one N-FFT over these constant frequencies where N = Number of possible symbols or frequencies in this case.
· After FFT, the frequency having the maximum power will represent our Symbol.
· Advantage of Dechirping is that the spread frequency spectrum is now pushed into one bin.
1. FFT of preamble would be having all its energy constrained to only one bin of the FFT.
Figure 13. Highlighting FFT Bin of Preamble
2. Here is now you will find the reason behind having a good synch. If you don’t have a good Synch, you will end up having half of the samples from nth chirp and half of the samples from the (n+1)th chirp winded up in the same FFT.
Figure 14. Overlapping FFT (Bad Synch)
3. Applying Overlapping FFT to reduce the ambiguity.
As we already read in Chapter 1 about encoding, we will now be able to acknowledge the reason behind encoding. This is the picture of 900 MHz band in USA.
Figure 15. 900 MHz spectrum in the US
They can ruin our data, that’s why we did the encoding on to our transmitted symbols.
· Gray Indexing (As it was referred in the patent)
· Data Whitening (Read in the AN1200.18)
· Interleaving (As it was referred in the patent)
· Forward Error Correction (Hamming (8,4))
· We forcefully introduce more bits to represent our signal.
· We compare the hamming distance of the received signal with all the codewords.
· We detect the codeword by checking which one of those has the least hamming distance.
· Let’s fix the FEC Hamming (8,4) for now.
Figure 16. Example FEC
· Hamming code for nibble of payload would be .
· Thus, FEC for nibble 0000 out of 16 combos will add no bits in the nibble.
· The detailed description of Interleaving is in the 3.2 Section.
· But, interleaving of would shuffle the zeros around
· Resulting sequence would still be the same.
· As the is received and XORed with the Whitening Sequence.
· Any sequence XORed with gives back the sequence itself.
· Voila! The data Whitening sequence is revealed too.
https://www.youtube.com/watch?v=NoquBA7IMNc&t=2028s
To pictorially represent the Effects of SF on the Signal, I used the simulator. I will attach the link video in the mail thread.