LoRaPHY is a complete MATLAB implementation of LoRa physical layer, including baseband modulation, baseband demodulation, encoding and decoding.
LoRaPHY is organized as a single file LoRaPHY.m for ease of use (copy it and run everywhere).
This repo is the implementation of the following paper:
Zhenqiang Xu, Pengjin Xie, Shuai Tong, Jiliang Wang. From Demodulation to Decoding: Towards Complete LoRa PHY Understanding and Implementation. ACM Transactions on Sensor Networks 2022. [pdf]
The real-time SDR implementation based on GNU Radio can be accessed via gr-lora.
MATLAB >= R2019b
Git clone this repo or just download LoRaPHY.m.
Put your MATLAB script, e.g., test.m, in the same directory of LoRaPHY.m.
Below is an example showing how to generate a valid baseband LoRa signal and then extract the data with the decoder.
See more examples in directory examples.
(LoRaPHY provides fast mode which enables 10x speedup comparing to normal demodulation with a little sensitivity degradation. See ./examples/test_fast_mode.m.)
% test.m
rf_freq = 470e6; % carrier frequency 470 MHz, used to correct clock drift
sf = 7; % spreading factor SF7
bw = 125e3; % bandwidth 125 kHz
fs = 1e6; % sampling rate 1 MHz
phy = LoRaPHY(rf_freq, sf, bw, fs);
phy.has_header = 1; % explicit header mode
phy.cr = 4; % code rate = 4/8 (1:4/5 2:4/6 3:4/7 4:4/8)
phy.crc = 1; % enable payload CRC checksum
phy.preamble_len = 8; % preamble: 8 basic upchirps
% Encode payload [1 2 3 4 5]
symbols = phy.encode((1:5)');
fprintf("[encode] symbols:n");
disp(symbols);
% Baseband Modulation
sig = phy.modulate(symbols);
% Demodulation
[symbols_d, cfo, netid] = phy.demodulate(sig);
fprintf("[demodulate] symbols:n");
disp(symbols_d);
% Decoding
[data, checksum] = phy.decode(symbols_d);
fprintf("[decode] data:n");
disp(data);
fprintf("[decode] checksum:n");
disp(checksum);