Gi-z / CSIKit

Python CSI processing and visualisation tools for Atheros, Intel, Nexmon, ESP32, FeitCSI, and PicoScenes (USRP, etc) formats.
https://Gi-z.github.io/CSIKit/
MIT License
207 stars 52 forks source link

generates correct Phase Difference #5

Closed helloworld1973 closed 3 years ago

helloworld1973 commented 3 years ago

Thanks a lot for your work.

  1. I am new in CSI and saw your code here, is there any clearer calculation on phase?

metric == "phasediff": if scaled_entry.shape[1] >= 2:

Not 100% sure this generates correct Phase Difference.

  1. I know the complex number is (gain, phase). how to transfer it to amplitude? why you use 20*log(gain)?
Gi-z commented 3 years ago

Hi, thanks for the issue.

  1. I'm not particularly knowledgeable about phase difference calculation, however this is a valid method to calculate phase difference using the phase values from two different receiving antennas. The problem with this is that the phase values generated this way have an unknown (random) offset applied to each one. There are a few methods for getting around this. I would suggest reading this paper for a thorough analysis on the subject with context.

  2. CSI amplitude is typically measured in dB/dBm. Daniel Halperin's examples from their Linux CSI Tool (supplementary code) use the db function from Matlab. Using 20*log(gain), we can replicate this behaviour. Note that this conversion can be used for either voltage or power, and the calculation used as such varies. As we're converting for amplitude, the power variant should be used.

Hope this clears up any questions. Happy to point to any other useful sources.

tweigel-dev commented 3 years ago

Hay @helloworld1973 , you can calculate the phase by using cmath.phase(complex) or you can calculate the amplitude by using abs(complex) This is valid because the csi is assembled like that: image