Code Monkey home page Code Monkey logo

cnn-rtlsdr's Introduction

CNN-rtlsdr

Deep learning signal classification using rtl-sdr dongle.

Current pre-trained model is able to classify 4 kinds of signals: WFM, TV Secam carrier, DMR signal and "Others".

TEST WITH PRETRAINED MODEL

Unpack software archive into some folder, e.g. C:\rtlsdr

Go to https://www.anaconda.com/download/ and choose Python 3.6 version, 64-Bit Graphical Installer or download directly: https://repo.continuum.io/archive/Anaconda3-5.0.1-Windows-x86_64.exe

If you do not have modern NVIDIA graphics card, to install CPU version, just remove the following line in requirements.txt:

tensorflow-gpu==1.4.0

Run anaconda prompt, change dir to C:\rtlsdr, then run:

conda install pip
pip install -r requirements.txt

Only for CUDA version of Tensorflow, if you have installed CPU version, skip these steps:

Last step is to copy 2 files from x64!!! osmocom rtl-sdr drivers: https://osmocom.org/attachments/download/2242/RelWithDebInfo.zip

Copy these [rtl-sdr-release/x64/]: rtlsdr.dll & libusb-1.0.dll into C:\Windows folder.

Reboot your system.

Now open your anaconda prompt again, change folder to C:\rtlsdr and run:

python predict_scan.py

to scan entire band and predict signal types , or the full version scan:

python predict_scan.py --start 85000000 --stop 108000000 --step 50000 --gain 20 --ppm 56 --threshold 0.9955

Watch CNN-rtlsdr in action on YouTube:

cnn-rtlsdr in action

Some help also available:

python predict_scan.py --help

LINUX INSTALLATION

Linux installation issues discussed here: #1

TRAIN YOUR OWN DATA

To train your own model, edit the settings in file [prepare_data.py] to set own frequencies of local stations and ppm error.

sdr.err_ppm = 56     # change it to yours

collect_samples(104000000, "wfm")
collect_samples(942200000, "gsm")

Then to obtain some samples run:

python prepare_data.py

Delete unnecessary folders under [/testing_data] and [/training_data] as they are responsible for classificator. E.g., if you want to train only WFM and OTHER classes, delete everything, except of:

  • /training_data/wfm/
  • /training_data/other/
  • /testing_data/wfm/
  • /testing_data/other/

Cleanup previous model checkpoint before starting a new train (otherwise it will continue training old model).

cleanup.cmd

Finally, we may now run training (of course, we are still inside anaconda prompt):

python train.py

Best decision is to stop the training [ctrl+c], when validation loss becomes 0.1 - 0.01 or below. Lowest values shows better performance. Really, you may terminate training even after a few (20-30) epochs with values about 0.4 - 0.3 and evaluate the model.

Also, it is better to obtain different samples of signals at different frequencies, gain levels. Edit [prepare_data.py] and run it again. Then train the classifier again to see the difference. Feel free to sample your own signal classes to train a bigger model.

SOME TECH FOR GEEKS

First version of this project was built using adaptation of image classification network, as the RF signal is representating also in 2D . I fed network with raw IQ samples, formed in a square as image, and even this gave me the model, doing it's job! This CNN graph was:

Conv2D (32*3*3) -> Conv2D (32*3*3) -> Conv2D (64*3*3) -> Dense (128) -> Dense (output)

Inspired of success, I began to try different preprocessing methods before feeding the network with complex. Neural networks generally has no idea, which input they serves, so I have tried to form into image shape the following:

FFT data

iq_samples = np.fft.fft(iq_samples)

AM demodulation data

iq_samples = np.sqrt(np.real(iq_samples) ** 2 + np.imag(iq_samples) ** 2)

FM demodulation data

iq_samples = np.unwrap(np.angle(iq_samples))
iq_samples = np.diff(iq_samples)

and all of those gave me some results. FFT version converged very fast, in a 3-5 epochs, while AM demod version showed worst performance. Finally, I've started googling to get more info and found the paper https://arxiv.org/pdf/1602.04105.pdf with all the CNN math great explanation. Then I have adapted network to match paper one, and graph now becomes:

Conv2D (64*1*3) -> Conv2D (16*2*3) -> Dense (128) -> Dense (output)

Feeding it with 1/4 sec raw IQ samples, sampled at 2.4 MSPS, and then decimated to a constant value of 48, left 12500 Hz bandwidth for classification.

KERAS VERSION

This is an optimized version of network, that reaches 99% accuracy while training.

python prepare_data.py
python train_keras.py

Keras network screenshot

cnn-rtlsdr's People

Contributors

dependabot[bot] avatar randaller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cnn-rtlsdr's Issues

Few problemos and some fixes if anyone is interested

"Last step is to copy 2 files from x64!!! osmocom rtl-sdr drivers: https://osmocom.org/attachments/download/2242/RelWithDebInfo.zip""

Skip this
  • Install the pyrtlsdr interface. You can do this in your virtual environment by "pip install pyrtlsdr". Or you can add pyrtlsdr in the requirements.txt.

sdr = RtlSdr()

Replace
  • device_index = RtlSdr.get_device_index_by_serial('00000001')
    sdr = RtlSdr(device_index)
"000....1" should be the default device serial number, that's how this auto-detect should work. Now the world is not perfecto so if not keep the "sdr = RtlSdr()" in the parentheses enter your comport I think IDK maybe. You are a big boy/girl... or soothing's else I guess after the 2016's the world has changed so much, I don't know anything anymore like the pronouns, I'm a sheltered person now. I was not always like this, I was once very social. ooh ya no back to what I was saying you can figure this out, I'm sure of it I promise.

sess = tf.Session()

Replace
  • sess = tf.compat.v1.Session()

Or

  • import tensorflow.compat.v1 as tf
    tf.disable_eager_execution()

That worked for me

I want to ask some trivial questions. and I'm still a beginner.Thank you !!!

hi!
I have some issues, I'd like to ask my predecessors.HAHA . Is the project to identify the modulation mode of the signal? I just don't know what WFM and DMR mean. I want to be a little silly...
In addition,Why do I run predict_scan.py programs,it wil stop when it predicts the first WFM ? and no more prediction of another signal..
Thank you very much for being able to answer this question. thank you !!

from rtlsdr import RtlSdr error ModuleNotFoundError: No module named 'rtlsdr'

windows 10 cpu tensorflow1.15 python3.6

Last step is to copy 2 files from x64!!! osmocom rtl-sdr drivers: https://osmocom.org/attachments/download/2242/RelWithDebInfo.zip
Copy these [rtl-sdr-release/x64/]: rtlsdr.dll & libusb-1.0.dll into C:\Windows folder.
Reboot your system.
Now open your anaconda prompt again, change folder to C:\rtlsdr and run:
python predict_scan.py

error ModuleNotFoundError: No module named 'rtlsdr' !!!!!

C:\Windows set in PATH ,the same error !!!1

Broken requirements.txt

Please make the packages in requirements.txt compliant with the current repository versions.

It is possible to install but it's not optimal.

usage of dataset2.py file

Hi,

I would like to know whether the dataset2.py and dataset.py file are used for testing the training model. Please let me know how can I test the trained model?

Error code -8 when reading 1200000 bytes

I'm getting this when trying to run predict_scan.py.

Traceback (most recent call last):
  File "predict_scan.py", line 54, in <module>
    iq_samples = read_samples(sdr, freq)
  File "predict_scan.py", line 13, in read_samples
    return sdr.read_samples(sample_rate * 0.25)
  File "/home/anubis/anaconda3/lib/python3.6/site-packages/rtlsdr/rtlsdr.py", line 407, in read_samples
    raw_data = self.read_bytes(num_bytes)
  File "/home/anubis/anaconda3/lib/python3.6/site-packages/rtlsdr/rtlsdr.py", line 391, in read_bytes
    % (result, num_bytes))
OSError: Error code -8 when reading 1200000 bytes

Data structure and usage without a dongle

Hi,
I am new to this but was wondering if you could tell me a little bit more about what the structure of the numpy files is for the training data (is it the phase of the signals, or just their frequencies?).

Also, I am trying to run the train_keras code using the numpy files already provided to test out the frequencies at the bottom of the code (without having a rtl-sdr dongle present and on Ubuntu 18.04). Is this possible to do since I seem to get the following error:

Traceback (most recent call last):
  File "/home/usr/cnn-rtlsdr-master/train_keras.py", line 83, in <module>
    sdr = RtlSdr()

  File "/home/usr/env/test/lib/python3.6/site-packages/rtlsdr/rtlsdr.py", line 133, in __init__
    self.open(device_index, test_mode_enabled, serial_number)

  File "/home/usr/env/test/lib/python3.6/site-packages/rtlsdr/rtlsdr.py", line 172, in open
    % (result, device_index))

OSError: Error code -1 when opening SDR (device index = 0)
[Finished in 12.6s with exit code 1]

using sdr devices with higher sample rate

Do you know how to use this code with higher end sdr devices?
Because rtlsdr has a limited bandwidth, some signal cannot be viewed inside 2.4MHz.
I wanted to try your program with LimeSDR. But the reshape part seems to causing problem.

LimeSDR can only be set with a sample_rate above 2.5MHz, I am currently using it with 4.8MHz.

Upgrade to TensorFlow 2.3.1

Are there any plans to upgrade this to TensorFlow 2.3.1, or has anyone done this in a fork? I tried myself but I don't have enough experience with TensorFlow and the rabbit hole got too deep.

Could not find a version that satisfies the requirement

I installed Python 3.6 in windows 10 as per instructions but I am getting an error, Could not find a version that satisfies the requirement. please help, thanks

pip install -r requirements.txt
Collecting alabaster==0.7.10 (from -r requirements.txt (line 1))
Using cached https://files.pythonhosted.org/packages/2e/c3/9b7dcd8548cf2c00531763ba154e524af575e8f36701bacfe5bcadc67440/alabaster-0.7.10-py2.py3-none-any.whl
Collecting anaconda-client==1.6.5 (from -r requirements.txt (line 2))
Could not find a version that satisfies the requirement anaconda-client==1.6.5 (from -r requirements.txt (line 2)) (from versions: 1.1.1, 1.2.2)
No matching distribution found for anaconda-client==1.6.5 (from -r requirements.txt (line 2))

running train.py

I'm facing this error when I try to run 'train.py' with your default train data. (also i didn't change anything in code)
Do you have any idea how for solving this?

Traceback (most recent call last):
  File "blablabla/cnn-rtlsdr-master/train.py", line 145, in <module>
    x_batch, y_true_batch, _, cls_batch = data.train.next_batch(batch_size)
  File "blablabla\cnn-rtlsdr-master\dataset2.py", line 191, in next_batch
    assert batch_size <= self._num_examples
AssertionError

(This error doesn't occur when i use 'train_keras.py'.)

Install on Linux

It would be great to have some instructions how to install this on Linux.

There are some DLLs mentioned in the instructions and also I think some stuff from requirements.txt might not apply to Linux.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.