Link Search Menu Expand Document

CSI processing and Plotting

The tutorial reported here is backed-up by the files/resources hosted on our Gitlab in the csi_process_and_plot branch of the documentation_resources project.

Link to Gitlab project/branch

1. Compile csireader

gcc -o csireader csireader.c -lpcap

2. Extracting CSI-data from PCAPs

The csireader extracts csi-data (amplitude and phase for each subcarrier) from all packets. The syntax for using the csireader is the following:

./csireader -f <input> -o <output> -a

For example, in this repo we have 2 pcap files that can be processed this way:

./csireader -f aoa_160ax_00.pcap -o data00.txt
./csireader -f aoa_160ax_01.pcap -o data01.txt

3. Process CSI-data for Matlab use

The Matlab script extract.m asks as input some raw (text-format) csi-data (as those output by csireader) and converts them into a structured format for ease of use in Matlab. The Matlab structured data are output on .mat files for later use (i.e., for plotting)

matlab -nodisplay -nosplash -nodesktop -r "extract "data00.txt"; exit;"

matlab -nodisplay -nosplash -nodesktop -r "extract "data01.txt"; exit;"

The above produces as output:

  • data00.txt.mat
  • data01.txt.mat

In particular, each mat file contains an alldata variables which stores, for each packet, a structure full of useful content :)

alldata structure

4. Plotting CSI with Matlab

Plotting Amplitude, for each subcarrier for each packet

load("data00.txt.mat", '-mat') %after this you have 'alldata' and 'packets' variables ;)

for nn = 1:packets
    normdata = abs(alldata(nn).core{1}.nss{1}.data);
    plot(normdata);
end

Plotting Phase in radiants, for each subcarrier for each packet

for nn = 1:packets
    phasedata = unwrap(angle(alldata(nn).core{1}.nss{1}.data)); 
    plot(phasedata);
end

A more complete Matlab script to generate a plot of both CSI and Phase processing both pcap files is available and is called plotterCSI.m

It produces a Figure like the following one:

5. [Alternative] Load .mat files and manipulate them with Python

from scipy.io import loadmat
mat = loadmat("data00.txt.mat", struct_as_record=False, squeeze_me=True)


print(mat.keys())
print(mat['packets'])

print(mat['alldata'])

print(mat['alldata'][0].core[0].nss[0].data)

More on this alternative here: