Handshaker
A lightweight and educational Python-based audio modem that converts text into sound using digital modulation techniques. This project demonstrates how to encode and transmit data via audio signals, exploring concepts like Frequency Shift Keying (FSK), signal smoothing, and robust transmission strategies.
Install / Use
/learn @andrea-shhz/HandshakerREADME
🎧 Python Audio Modem
A lightweight and educational Python-based audio modem that converts text into sound using digital modulation techniques. This project demonstrates how to encode and transmit data via audio signals, exploring concepts like Frequency Shift Keying (FSK), signal smoothing, and robust transmission strategies.
📦 Installation
Set up your environment and install the required libraries:
python -m venv .venv
source .venv/bin/activate # On Windows: .\.venv\Scripts\Activate.ps1
pip install --upgrade pip
pip install numpy scipy sounddevice
🛠 Features
- Bit-wise and Byte-wise Encoding: Supports both granular bit-level and byte-level signal generation.
- Hard vs. Smooth Transitions: Choose between raw signal transitions or smoothed ones using Hann windows.
- Sync Sequence: Adds a synchronization sequence to improve decoding accuracy.
- WAV Export: Automatically saves generated signals as
.wavfiles with timestamped filenames. - Real-Time Playback: Play the generated signal directly through your audio device.
📡 Signal Transmission Techniques
To improve reliability and robustness, the following strategies are considered:
-
Sync Sequence
A known bit pattern (e.g.,10101010) is sent before the actual data to help the receiver align and synchronize. -
Advanced Modulation
Beyond binary FSK, multi-frequency schemes (e.g., 4-level FSK for 2-bit symbols) can increase efficiency and resilience. -
Error Detection & Correction
Add parity bits or implement error-correcting codes like Hamming or Reed-Solomon to detect and fix transmission errors. -
Bandpass Filtering
Apply filters (e.g., 900 Hz to 2100 Hz) to isolate relevant frequencies and reduce ambient noise. -
Robust Windowing
Use longer analysis windows and techniques like moving averages or cross-correlation to improve frequency detection. -
Preamble & Postamble
Clearly mark the start and end of the signal to help the receiver extract the payload accurately. -
Adaptive Thresholding
Use energy-based detection rather than fixed thresholds to handle variations in volume and recording quality.
🔍 Signal Preprocessing (Reception Side)
- Amplitude normalization
- DC offset removal
- Hann window application to reduce edge effects
🧪 Decoding Improvements
- Precomputed filters for efficient frequency isolation
- Sync sequence detection via correlation
- Frequency band energy analysis for bit decoding
- Parity bits for error detection
- Robust binary conversion handling
📁 Output Example
Generated audio files are saved with a timestamped filename:
modem_2025-09-23-18-57-48.wav
💡 Usage Tips
- Test in environments with varying noise levels
- Tune
FREQ_0andFREQ_1based on your hardware - Increase
SYNC_SEQUENCElength for better synchronization
📜 License
This project is licensed under the MIT License. Feel free to use, modify, and share it.
🔬 Perfect for learning about digital signal processing, audio-based data transmission, and Python's capabilities in real-time signal generation.
