# A Survey of LoRaWAN for IoT: From Technology to Application
## 2 Introduction to LoRa and LoRaWAN
### LoRa  
The LoRa physical layer has been patented by Semtech in 2014 [1]. Its modulation is based on [2] and produces a chirp signal where all chirps will have practically the same time duration. A chirp is characterized by a time profile of the instantaneous frequency that changes over the time interval \(T\) from a frequency \(f_{0}\) to \(f_{1}\). In LoRa, two different types of chirps have been defined [1]: the base chirp whose frequency time profile starts with the minimal frequency \(f_{min}=-\frac{BW}{2}\) and ends with the maximal frequency \(f_{max}=+\frac{BW}{2}\), BW being the spreading bandwidth of the signal, and modulated chirps that are cyclically time shifted base chirps. The chirp that starts with frequency \(f_{1}=+\frac{BW}{2}\) and ends with \(f_{2}=-\frac{BW}{2}\) is referred to as a down-chirp, practically being the complex conjugate of the base chirp. For different digital inputs, a modulator will produce different chirps that will have certain time shift compared to base chirp. The time shift of each chirp at the receiver side can be determined after the alignment of the time reference between receiver and transmitter by means of preamble detection. The time shift of each chirp is determined by multiplying the chirp itself with a down-chirp and finding the Fast Fourier Transform (FFT) of the multiplication. The maximum of the FFT output will indicate the time shift of the transmitted chirp that consequently will determine the transmitted digital symbol. If \(N\) is the chirp length of a symbol, then there can be \(N\) possible different cyclic shifts of the base chirp, and the value of the cyclic shift can be coded using \(log_{2}N\) bits that gives the spreading factor (SF) of the communication. To further improve the robustness against noise and burst interference, LoRa uses diagonal interleaving as well as forward error correction (FEC) codes with code rates from 4/5 to 4/8. The data rate and symbol rate depends on the SF and the bandwidth used. The symbol rate is given by the formula:  
\[R_{s}=SF\cdot\frac{BW}{2^{SF}} \tag{1}\]  
where SF is the spreading factor and BW is the bandwidth in Hz. From Equation (1), it is seen that the symbol time is increased by increasing the SF, decreasing the symbol rate. The data rate is given by the formula:  
\[R_{b}=SF\cdot\frac{\frac{4}{2^{SF}}}{\frac{2^{SF}}{BW}}\cdot 1000 \tag{2}\]  
where SF is the spreading factor, CR is the code rate and BW is the bandwidth in KHz. The data rate in this formula is expressed in bps. From Equation (2), it can be noticed that by increasing the SF less bits per symbol will be encoded, decreasing the data rate. The packet structure at the physical layer includes a preamble, an optional header and the data payload. The preamble is used to synchronize the receiver with the transmitter and can have a length from 10 up to 65,536 symbols in total. The fixed part of the preamble consists of four symbols, and the rest is programmable with a minimal length of six symbols and a maximal length of 65,532 [3]. According to [PERSON] and [PERSON] [1], the preamble starts with a sequence of constant upchirp symbols that is programmable and helps to detect the start of the frame. The programmable part is followed by two chirp symbols encoding the sync word that is used for frame synchronization. Usually, the two chirps will modulate opposite values, e.g., \(x\) and \(N-x\). When the receiver detects three consecutive chirps, with the first one unmodulated (upchirp), the second one modulated with the first value \(x\) and the third one modulated with the opposite value \(N-x\)), a new frame is detected. The sync word can also be used to distinguish between devices from different networks by using different values for each network. Next to this, the preamble ends with two downchirp symbols that are used for frequency synchronization. After the last two symbols, a 0.25 symbol time represents a silence time used to let the receiver align the time [1].