Monitor with Python and RTL-SDR

Python, RTL-SDR, numpy

This is modified version based on rtl-sdr-close-call-monitor https://github.com/nootedandrooted/rtl-sdr-close-call-monitor

It scans tetra uplink european frequencies.

import sys

import time

import numpy as np

from rtlsdr import RtlSdr


sdr = RtlSdr()


sr = 2.4e6

shift = 1.2e6

start_freq = 380.0125e6

end_freq = 0

freq = 381.2125e6


sdr.sample_rate = sr  # Hz

sdr.freq_correction = 1  # PPM

sdr.gain = 30  # dB

num_samples = 2**16

squelch_level = -30

n = 0


while True:

    gain_question = str(input("Do you want to use the default gain? (30dB) (y/n): "))

    if gain_question == 'y':

        print("Using the default gain (30 dB)")

        break

    elif gain_question == 'n':

        gain_custom = int(input("Please enter the gain (in dB): "))

        sdr.gain = gain_custom

        break

    else:

        print("Error in input. Please choose y or n.")


while True:

    squelch_question = str(input("Do you want to use the default threshold for the squelch level? (y/n): "))

    if squelch_question == 'y':

        print("Using the default threshold for the squelch level (-30)")

        squelch_level = -30

        break

    elif squelch_question == 'n':

        squelch_custom = int(input("Please enter the threshold for the squelch level: "))

        squelch_level = squelch_custom

        break

    else:

        print("Error in input. Please choose y or n.")


print("Start monitoring")

try:

    while True:

        sdr.center_freq = freq

        if n < 3:

            start_freq = start_freq + sr

            freq = freq + sr

            end_freq = start_freq + sr

            n = n + 1

        else:

            start_freq = 380.0125e6

            end_freq = 0

            freq = 381.2125e6

            n = 0

            

        samples = sdr.read_samples(num_samples)


        freq_range = np.linspace(start_freq, end_freq, num_samples, endpoint=False)


        spectrum = np.abs(np.fft.fftshift(np.fft.fft(samples)))


        peak_index = np.argmax(spectrum)

        peak_freq = freq_range[peak_index]


        peak_freq_mhz = f"{peak_freq / 1e6:.3f}"


        # Only print the peak frequency if it exceeds the squelch level

        if spectrum[peak_index] > squelch_level:

            pass

        else:

            print(f"Peak frequency detected: {peak_freq_mhz}Mhz")

            print("\a")

except KeyboardInterrupt:

    sdr.close()

    print("Bye!")

finally:

    sdr.close()



Comments

Popular posts from this blog

Telive-2 how-to

Inspecting Alinco DJ-X100E firmware updater

Modifying LILYGO T3 LoRa32 RTL_433 ESP OOK receiver example - log found devices to file