Created
December 23, 2023 07:56
-
-
Save ParkWardRR/80f74e2531278115db3b6e447cca6ecd to your computer and use it in GitHub Desktop.
freq_analysis.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
: ' | |
File: freq_analysis.sh | |
This is a Unix shell script designed to provide a frequency analysis based on the output from software-defined radio (SDR) scans. The script reads from specified CSV files that contain the SDR scan data, recognizes the frequencies with the highest signal strength, and presents a list of the top frequencies. | |
This script serves as a preliminary tool for users looking to explore frequency ranges for the SDRTrunk application. Its primary tasks include sorting the frequencies based on signal strength and outputting potential frequency ranges for further analysis and use in SDRTrunk. | |
Note: Ensure the SDR scan CSV files are placed in the appropriate directory (default: /tmp/sdrOut); adjust the CSV_DIR variable in the script according to your setup. This script is geared towards educational and research applications. Compliance with all applicable laws pertaining to radio frequency use is strongly advised. | |
' | |
# User configured variables | |
CSV_DIR=/tmp/sdrOut | |
OUTPUT_FILE=/tmp/freq_analysis_$(date +"%Y%m%d%H%M%S").txt | |
NB_TOP_FREQS=10 | |
# Validate if CSV directory exists | |
if [ ! -d "$CSV_DIR" ]; then | |
echo "Error: Source directory $CSV_DIR not found." | |
exit 1 | |
fi | |
CSV_FILES=($(ls $CSV_DIR/*.csv 2> /dev/null)) | |
if [ ${#CSV_FILES[@]} -eq 0 ]; then | |
echo "No CSV files found in the directory: $CSV_DIR" | |
exit 1 | |
fi | |
echo "Starting frequency analysis on CSV files in directory: $CSV_DIR" | |
echo "Analysing..." | |
# Use awk to print out the maximum signal strength (Max dB) for each frequency | |
awk -F, -v OFS=',' '{ freq = ($2 + $3) / 2; max = $7; print $1, freq, max }' ${CSV_FILES[@]} | sort -t, -k3nr | head -n ${NB_TOP_FREQS} > ${OUTPUT_FILE} | |
echo "Analysis complete. Results are located in $OUTPUT_FILE" | |
# Output table with highest activity frequencies | |
echo "| Time of Scan | Frequency (Hz) | Maximum dB | Center Frequency (kHz) |" | |
echo "|--------------|----------------|------------|---------------------------|" | |
while IFS=',' read -r timestamp frequency max_signal; do | |
CENTER_FREQ=$(echo "scale=5; $frequency / 1000" | bc) # convert to kHz for SDRTrunk | |
printf '| %-12s | %-14f | %-10f | %-25f |\n' "$timestamp" "$frequency" "$max_signal" "$CENTER_FREQ" | |
done < "$OUTPUT_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment