ADALM Pluto
Windows 10
Python 3.11.2 64-bit
Numpy 1.24.2
Pyadi-iio 0.0.14
Pylibiio 0.23.1

This is modified version based on rtl-sdr-close-call-monitor https://github.com/nootedandrooted/rtl-sdr-close-call-monitor
Blacklist frequencies feature is not implemented/alarm sound uses winsound in monitor_with_pluto.py


monitor_with_pluto.py

import sys
import time
import numpy as np
import winsound
import adi

# Open the Pluto
sdr = adi.Pluto('ip:192.168.2.1')

# Set default values
center_freq = 446e6 # Hz
sample_rate = 2.5e6  # Hz Minimum is 520.83 KSPS
num_samples = 2**16
squelch_level = -30

sdr.gain_control_mode_chan0 = 'manual'
sdr.rx_hardwaregain_chan0 = 56.0 # allowable range is 0 to 74.5 dB
sdr.rx_lo = int(center_freq)
sdr.sample_rate = int(sample_rate)
sdr.rx_rf_bandwidth = int(sample_rate) # filter width, just set it to the same as sample rate for now
sdr.rx_buffer_size = num_samples

# Set user input variables
while True:
    # Set the Pluto device sample rate
    sample_rate_question = str(input("Do you want to use the default sample rate (2.5 MHz)? (y/n): "))
    if sample_rate_question == 'y':
        print("Using the default sample rate (2.5 MHz)")
        break
    elif sample_rate_question == 'n':
        sample_rate_custom = int(input("Please enter the sample rate (in Hz): "))
        sdr.sample_rate = int(sample_rate_custom)
        sdr.rx_rf_bandwidth = int(sample_rate_custom)
        break
    else:
        print("Error in input. Please choose y or n.")

while True:
    # Set the Pluto device gain
    gain_question = str(input("Do you want to use the default gain? (56dB) (y/n): "))
    if gain_question == 'y':
        print("Using the default gain (56 dB)")
        break
    elif gain_question == 'n':
        gain_custom = int(input("Please enter the gain (in dB): "))
        sdr.rx_hardwaregain_chan0 = gain_custom
        break
    else:
        print("Error in input. Please choose y or n.")

while True:
    # Set the scan start frequency
    start_frequency_custom = int(input("Please enter the start frequency (in Hz): "))
    if start_frequency_custom <= 325000000 or start_frequency_custom >= 3800000000:
        print("Error in input. Please type a correct start frequency (in Hz).")
    else:
        start_freq = start_frequency_custom
        break

while True:
    # Set the scan end frequency
    end_frequency_custom = int(input("Please enter the stop frequency (in Hz): "))
    if end_frequency_custom <= 325000000 or end_frequency_custom >= 3800000000:
        print("Error in input. Please type a correct stop frequency (in Hz).")
    else:
        end_freq = end_frequency_custom
        break

while True:
    # Set the Pluto device samples
    num_samples_question = str(input("Do you want to use the default number of samples (2**16)? (y/n): "))
    if num_samples_question == 'y':
        print("Using the default number of samples (2**16)")
        break
    elif num_samples_question == 'n':
        num_samples_custom = str(input("Please enter the number of samples (x**xx): "))
        sdr.rx_buffer_size = num_samples_custom
        break
    else:
        print("Error in input. Please choose y or n.")

while True:
    # Set the Pluto device squelch level
    squelch_question = str(input("Do you want to use the default threshold for the squelch level (-30)? (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.")

# Set the center freq

sdr.rx_lo = int((start_freq + end_freq) / 2)

# The main loop with exception handling
try:
    while True:
        # Read samples from the Pluto device
        samples = sdr.rx()

        # Calculate the frequency range of the samples
        freq_range = np.linspace(start_freq, end_freq, num_samples, endpoint=False)

        # Convert the samples to a power spectrum
        spectrum = np.abs(np.fft.fftshift(np.fft.fft(samples)))

        # Find the peak frequency in the spectrum
        peak_index = np.argmax(spectrum)
        peak_freq = freq_range[peak_index]

        # Convert peak frequency to MHz
        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")
            winsound.PlaySound("SystemExclamation", winsound.SND_ALIAS)
except KeyboardInterrupt:
    print("Keyboard exit")
finally:
    print("Exit")