This directory contains a comprehensive collection of examples demonstrating the capabilities of ka9q-python. The examples are organized by complexity and use case to help you learn progressively.
If you're new to ka9q-python, we recommend following this learning path:
- Read the Getting Started Guide first to understand the basics.
- Start with the Basic Examples below to see simple, working code.
- Move to Intermediate Examples once you're comfortable with the fundamentals.
- Explore Advanced Examples when you need specialized features.
These examples demonstrate fundamental operations with minimal code. Perfect for beginners.
What it does: Creates a simple AM radio channel tuned to WWV 10 MHz.
Concepts demonstrated:
- Connecting to
radiod - Creating a channel with
create_channel() - Basic channel configuration
Run it:
python3 examples/simple_am_radio.pyExpected output: Confirmation that an AM channel has been created. The RTP stream will be available on radiod's multicast address.
What it does: Discovers all active channels on radiod and displays their information.
Concepts demonstrated:
- Using
discover_channels()to find existing channels - Iterating over discovered channels
- Displaying channel metadata (frequency, preset, sample rate, etc.)
Run it:
python3 examples/discover_example.pyExpected output: A list of all active channels with their SSRCs, frequencies, presets, and other details.
What it does: Demonstrates proper channel cleanup by setting frequency to 0 Hz.
Concepts demonstrated:
- Creating a channel
- Removing a channel with
remove_channel() - Understanding the channel cleanup mechanism
Run it:
python3 examples/channel_cleanup_example.pyExpected output: Creates a channel, uses it briefly, then removes it cleanly.
These examples show more sophisticated usage patterns and introduce the stream APIs.
What it does: Receives continuous audio samples from a channel using RadiodStream.
Concepts demonstrated:
- Using
RadiodStreamfor sample delivery - Handling quality metrics (
StreamQuality) - Gap detection and reporting
- Resequencing out-of-order packets
Run it:
# First discover available channels
python3 examples/discover_example.py
# Then stream from a specific SSRC
python3 examples/stream_example.py --ssrc 10000000 --duration 30 --discoverExpected output: Real-time stream statistics including samples delivered, completeness percentage, and RTP packet metrics.
What it does: Records RTP packets with precise timing information.
Concepts demonstrated:
- Using
RTPRecorderfor low-level packet access - Handling RTP headers and timing
- State machine for recording control
- Recording metrics and statistics
Run it:
python3 examples/rtp_recorder_example.py radiod.local --duration 30Expected output: Packet-by-packet information with timestamps, sequence numbers, and final recording statistics.
What it does: Demonstrates programmatic channel tuning (changing frequency).
Concepts demonstrated:
- Using
tune()method for frequency changes - Waiting for channel verification
- Dynamic frequency control
Run it:
python3 examples/tune_example.pyExpected output: Creates a channel and tunes it to different frequencies, showing the tuning process.
What it does: Interactive command-line utility for tuning channels (Python implementation of ka9q-radio's tune).
Concepts demonstrated:
- Interactive channel control
- Real-time frequency adjustment
- Command-line argument parsing
Run it:
python3 examples/tune.py --helpThese examples demonstrate specialized features for specific applications and advanced use cases.
What it does: Showcases all advanced radiod features exposed by ka9q-python.
Concepts demonstrated:
- Doppler tracking for satellites
- PLL configuration for carrier tracking
- SNR-based squelch
- Independent Sideband (ISB) mode
- Secondary filter configuration
- Opus encoding
- Spectrum analyzer mode
- RF hardware controls
- And many more advanced features
Run it:
python3 examples/advanced_features_demo.pyNote: Many features are commented out to prevent unintended changes. Uncomment and adjust as needed for your specific hardware and use case.
What it does: Records ionospheric radar signals from SuperDARN stations.
Concepts demonstrated:
- Application-specific channel configuration
- Long-running recording sessions
- Scientific data collection
Use case: Ionospheric research, space weather monitoring.
What it does: Monitors ocean current radar (CODAR) signals.
Concepts demonstrated:
- Oceanographic radar signal reception
- Multi-frequency monitoring
Use case: Ocean current mapping, coastal monitoring.
What it does: Dynamically scans HF bands and creates channels for active frequencies.
Concepts demonstrated:
- Dynamic channel creation
- Frequency scanning
- Multi-channel management
Use case: Band monitoring, signal hunting, propagation studies.
What it does: Integrates with the HamSCI GRAPE (Grape Radio Amateur Propagation Experiment) project.
Concepts demonstrated:
- Integration with external data collection systems
- Precise timing for scientific applications
- Data formatting and upload
Use case: Citizen science, propagation research.
What it does: Verifies GPS_TIME and RTP_TIMESNAP timing fields in RTP packets.
Concepts demonstrated:
- Precise timing extraction
- GPS time synchronization
- Timing validation
Use case: Applications requiring microsecond-level timing accuracy.
What it does: Receives real-time FFT spectrum data from radiod and prints bin statistics.
Concepts demonstrated:
- Using
SpectrumStreamfor spectrum data - Accessing
bin_power_dbfor dB-scaled FFT bins - Spectrum channel creation and polling
- Frequency axis reconstruction from bin metadata
Run it:
python3 examples/spectrum_example.py bee1-hf-status.local --freq 14.1e6Expected output: Per-frame spectrum statistics (bin count, peak power, noise floor) updated ~10 times per second.
The diagnostics/ subdirectory contains utilities for troubleshooting and testing.
-
Replace the radiod address: Most examples use
"bee1-hf-status.local"as the default. Replace this with your ownradiodinstance address. -
Check for active channels: Before running stream examples, ensure at least one channel is active on
radiod. Usediscover_example.pyto check. -
Multi-homed systems: If you have multiple network interfaces, you may need to specify the
interfaceparameter when creatingRadiodControl. -
Read the code: Each example is heavily commented. Reading the source code is the best way to understand how things work.
-
Experiment: Modify the examples to suit your needs. Change frequencies, presets, sample rates, and other parameters to see how they affect behavior.
- Getting Started Guide: docs/GETTING_STARTED.md
- API Reference: docs/API_REFERENCE.md
- GitHub Issues: https://github.com/HamSCI/ka9q-python/issues
Have an interesting use case or application? We welcome contributions! Please submit a pull request with:
- Your example code (well-commented)
- A brief description of what it does
- Any special requirements or dependencies
Happy experimenting!