December 05, 2023

SDR calibrate with kalibrate-rtl

Updated 2023-12-05 !! OK, with Bookworm (32/64 bit) !!

To optimize the reception with SDR:s, Software Defined Radios, it is important to receive on the proper frequency. Due to variations in production there could be deviations.


The calibration could be done against standard GSM transmitters which are providing a stable reference frequency.

Another way is found in the AIS-catcher application and use the information supplied in the graphs "Frequency Shift". 

Introduction
It would be wise to let the dongle reach its working temperature, 30 minutes ?, before the calibration takes place.

On this blog I have used 3 different software packages, Package APackage B and the best AIS-catcher to receive AIS information, on a Raspberry Pi(RPi), from passing ships.

I'm using 2 different SDR dongles, the RTL-SDR V3  and NooElec NESDR Nano 3 which both can be used with the software kalibrate-rtl to get the frequency offset.

The fantastic OpenPlotter(OP) project with guys Sailoog/e-sailing have done a package which is very easy to use. I really recommend the OP method, Install A, compared with installing from source. (If You are using OP use the app "SDR VHF" instead)

Update OS
Open a terminal window/ssh to the RPi and start with a update of the OS


sudo apt update && sudo apt full-upgrade -y && sudo apt clean

Installation A, from OP package
Start  with dependencies for KALIBRATE-RTL

sudo apt install librtlsdr-dev librtlsdr0 libfftw3-double3 libfftw3-dev libfftw3-bin

Choose a package file for Your OS. For RPi, 32 bit, download 

$ wget https://launchpad.net/~openplotter/+archive/ubuntu/openplotter/+files/kalibrate-rtl_0.4.2.2-stable_armhf.deb

install with 

$ sudo dpkg -i kalibrate-rtl_0.4.2.2-stable_armhf.deb

For 64 bit 

$ wget https://launchpad.net/~openplotter/+archive/ubuntu/openplotter/+files/kalibrate-rtl_0.4.2.2-stable_arm64.deb

install with 

$ sudo dpkg -i kalibrate-rtl_0.4.2.2-stable_arm64.deb

And go on with "Check install" below

Installation B, from source
The software have not been maintained for some time but there are several forks and hayguen is used here.

Install some dependencies 
  • Bookworm/Bullseye/Buster/Stretch OS 
    • $ sudo apt install librtlsdr-dev libtool libfftw3-dev
  • Stretch also add 
    • $ sudo apt install m4 automake
then download

$ wget https://github.com/hayguen/kalibrate-rtl/archive/master.zip

and unzip the actual software

$ unzip master.zip && mv kalibrate-rtl-master kalibrate-rtl

Install/compile with (For Buster please check remark below !)

$ cd kalibrate-rtl
$ bash bootstrap
$ bash configure
$ make
$ sudo make install

Check install
Check the installation showing help for the program with

kal -h

Calibration
Check which GSM bands are available in Your place.

Living in EU I will use GSM900 and the command


$ sudo kal -s GSM900
Found 1 device(s):
  0:  Generic RTL2832U OEM

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Exact sample rate is: 270833.002142 Hz
[R82XX] PLL not locked!
kal: Scanning for GSM-900 base stations.
GSM-900:
    chan:   44 (943.8MHz + 3.197kHz)    power:   52359.35
    chan:   58 (946.6MHz + 3.014kHz)    power:   98282.66
    chan:   71 (949.2MHz + 3.248kHz)    power:   34079.74
    chan:   79 (950.8MHz + 2.675kHz)    power:   34617.79
    chan:   81 (951.2MHz + 3.682kHz)    power:   26689.15
    chan:   85 (952.0MHz + 2.968kHz)    power:   32904.71
    chan:   88 (952.6MHz + 2.717kHz)    power:   90496.63
    chan:   90 (953.0MHz + 3.777kHz)    power:   33726.00
...chan 119 

We now see that the offset is around -3 ppm(Parts Per Million). For channel 58, strongest channel,  => 3,014/943800 =  0,00000319.

Confirm this with


$ sudo kal -c 58
Found 1 device(s):
  0:  Generic RTL2832U OEM

Using device 0: Generic RTL2832U OEM
Found Rafael Micro R820T tuner
Exact sample rate is: 270833.002142 Hz
[R82XX] PLL not locked!
kal: Calculating clock frequency offset.
Using GSM-900 channel 58 (946.6MHz)
Tuned to 946.600000MHz (reported tuner error: 0Hz)
average [min, max] (range, stddev)
+ 3.038kHz [3013, 3060] (46, 12.023702)
overruns: 0
not found: 0

average absolute error: -3.190 ppm

Go through the channels with the highest gain and wright down an average.

If using aisdeco2 add --freq-correction -3.2 to the call

sudo aisdeco2 --freq-correction -3.2 --udp 127.0.0.1:10110

And using rtl_ais add -p -3.2 to the call   

sudo rtl_ais -R on -n -p -3.2

Remark
Please note that there is a bug in Buster so You have to edit the file /usr/lib/arm-linux-gnueabihf/pkgconfig/librtlsdr.pc before compiling the program

Save a copy and edit


$ sudo cp  /usr/lib/arm-linux-gnueabihf/pkgconfig/librtlsdr.pc /usr/lib/arm-linux-gnueabihf/pkgconfig/librtlsdr_old.pc
$ sudo nano /usr/lib/arm-linux-gnueabihf/pkgconfig/librtlsdr.pc

so that the file contains the following info

prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib/arm-linux-gnueabihf
includedir=${prefix}/include

Name: RTL-SDR Library
Description: C Utility Library
Version: 0.6.0
Cflags: -I${includedir}/
Libs: -L${libdir} -lrtlsdr
Libs.private:  -lusb-1.0 

If You did a "make", and got the error, before the change of the "librtlsdr.pc" do a "make clean" and then a "make" again

8 comments:

  1. nice write up! did manage the installation with RPI Burster.
    you can solve a FFTW3 configure issue with apt install libfftw3-dev pkg-config and then pkg-config all.

    re-run bootstrap and it's gone

    ReplyDelete
    Replies
    1. Thx. Thanks for Your tips, but just to get it right before testing. Will Your commands correct the info in librtlsdr.pc ?

      Delete
  2. Good guide. Having a problem:

    When sudo I run:
    $ kal -s GSM900

    I get:

    Found 1 device(s):
    0: Generic RTL2832U

    Using device 0: Generic RTL2832U
    usb_claim_interface error -6
    Failed to open rtlsdr device #0.

    This is an SLR350 (with a USB ADSB dongle also plugged in). I am currently receiving both AIS and ADSB transmission without any problems.

    Any help would be great. Thank you

    ReplyDelete
    Replies
    1. Just one process can use the USB device, so You have to kill/stop the other process before using "kal".

      Delete
  3. Installing dependencies:
    librtlsdr-dev: OK
    libfftw3-dev: package not available
    libtool: package not available
    automake: package not available

    Any ideas?

    Thanks

    ReplyDelete
  4. No, on Stretch after update/upgrade

    ReplyDelete
    Replies
    1. Sorry but don't have any RPi/Stretch in my surroundings for the moment. But since it's an older OS, test with update/upgrade/install using "apt-get" instead.

      Delete

Feel free to leave a comment ! ... but due to a lot of spam comments I have to moderate them. Will reply ASAP !