josevcm / nfc-laboratory

NFC signal and protocol analyzer using SDR receiver
GNU General Public License v3.0
411 stars 47 forks source link

Direct sampling 13.56Mhz on rtl-sdr #16

Closed vinicentus closed 1 year ago

vinicentus commented 1 year ago

Hi!

I've created a proof of concept for using direct sampling on the rtl-sdr device. This means we can listen directly to the main carrier frequency of 13.56Mhz.

With my limited testing, and completely wrong antenna type, I still got great results. Almost all pakcets are correctly read, as far as I can tell: image

Now in order to include this in the upstream project, some things still need to be done. I'm thinking:

  1. This needs to be configurabe from the config file, instead of being hardcoded in RealtekDevice.cpp#L71
  2. This change needs to be documented, at least in the readme.

So yeah. This is a work in progress, and therefore marked as a draft pull request. But hopefully you find this useful, and hopefully it can be merged at some point!

Best regards, Vincent

josevcm commented 1 year ago

Thank you very much for adding improvements to the project! I will integrate the changes as soon as possible and add the configuration from file.

vinicentus commented 1 year ago

Great! I removed the draft flag from the PR now. So if you want you can merge. You should also have access to push commits to my direct-sampling branch automatically (seems to be a new github feature), if you want to work on this branch before merging.

I tried to make direct sampling configurable from the config file, but ran into an issue: Since only the rtl-sdr can do this (I think?), there needs to be a check that we aren't using some other sdr. I tried checking for the RealtekDevice subclass and casting to it when reading the config, but couldn't figure it out... EDIT: I didn't push those changes

josevcm commented 1 year ago

Support for direct sampling activated by default, pending add configuration from file

josevcm commented 1 year ago

forget to hit merge!

vinicentus commented 1 year ago

Awesome!

Btw this is a super useful project, thanks for creating it!😄

josevcm commented 1 year ago

Please check an test recent commits to the master branch. I have included the configuration from the file but I cannot test it because my RTL-SDR does not support directSampling. When I activate it it does not receive anything :(

vinicentus commented 1 year ago

Ok, I should have time to try it tomorrow

vinicentus commented 1 year ago

I had some time to test the new changes on master. TLDR: it works as expected, but the documentation is slightly incaccurate.

When I run the project using qt creator, the default config seems to be this:

timeFormat=false
followEnabled=true
filterEnabled=true

[device.rtlsdr]
centerFreq=13560000
sampleRate=10000000
gainMode=1
gainValue=439

[decoder.nfca]
enabled=true

[decoder.nfcb]
enabled=true

[decoder.nfcf]
enabled=true

[decoder.nfcv]
enabled=true

With this config, I don't get any usable results.

However by copy pasting the values from dat/config/nfc-lab.conf everything works. The signal I pick up is weak and there are many decoding errors. But this is expected with my setup.

Direct sampling works when I change the config to

centerFreq=13560000
sampleRate=2400000
directSampling=2

About the documentation: At least in my case, I get much better results when enabling direct sampling on the Q-branch (directSampling=2). When using the I-branch (directSampling=1), the signal is too weak to decode. So this should probably be reflected in the readme.

Maybe write something like: You can use direct sampling on either the Q- or I-branch. The Q-branch is preferred due to better results. You can use the Q-branch with directSampling=2 and the I-branch with directSampling=1. directSampling=0 turns off direct sampling.

josevcm commented 1 year ago

Thanks Vincent, I will fix the documentation tomorrow.

vinicentus commented 1 year ago

I saw that you updated the documentation!

Time for a new release build? 😉😅

josevcm commented 1 year ago

Yes! next weekend I will prepare next release.