DAC Streaming Example (Command Line)
This example demonstrates how to generate a custom sine wave signal on the DAC outputs using the rpsa_client command-line tool. This tutorial covers the complete workflow from creating a waveform to streaming it to the Red Pitaya.
Note
This tutorial uses the rpsa_client command-line tool, not the Python/C++ API. For API-based DAC streaming, see DAC API Streaming Tutorial.
Prerequisites
Before starting this example, ensure you have:
Red Pitaya board with OS version 2.07-43 or newer
Command line client installed on your computer
Enough DMM memory reserved for DAC streaming (at least 100 MB recommended)
Python 3 with numpy and scipy.io.wavfile libraries (for waveform creation)
SSH access to your Red Pitaya board
Overview
This example will guide you through:
Creating a custom sine wave waveform in Python
Establishing SSH connection to Red Pitaya
Loading the FPGA and starting the streaming application
Configuring the DAC streaming parameters
Starting the DAC streaming
The example uses one-pack mode for maximum performance, where the entire waveform fits in DDR memory, allowing full 125 MS/s output rate. For network streaming limitations, see Streaming Performance Limits.
Step-by-step tutorial
Step 1: Create a custom waveform
Create a Python script to generate a sine wave signal with 1024 samples. This waveform will be saved as a WAV file.
import numpy as np
from scipy.io import wavfile
import matplotlib.pyplot as plt
# Waveform parameters
N = 1024 # Number of samples in a period
num_periods = 1 # Number of periods in the signal
num_bits = 16
max_val = 2**(num_bits-1) - 1 # 32767
min_val = -2**(num_bits-1) # -32768
# Generate sine wave
t = np.linspace(0, 1, N*num_periods)*2*np.pi
y = np.sin(num_periods*t)*max_val # FPGA divides the signal by 4
# Convert to signed 16-bit integers
y_signed16 = np.int16(y)
# Optional: Plot to verify waveform
plt.plot(y_signed16)
plt.title('Custom waveform')
plt.xlabel('Sample')
plt.ylabel('Amplitude')
plt.grid(True)
plt.show()
# Save as WAV file
sample_rate = 44100 # (Doesn't matter) Standard audio sample rate
wavfile.write('arb_waveform_signed16.wav', sample_rate, y_signed16)
print(f"Waveform created with {len(y_signed16)} samples")
print(f"File size: {len(y_signed16) * 2} bytes")
Save this script as create_waveform.py and run it:
python create_waveform.py
This will create arb_waveform_signed16.wav in your current directory.
Step 2: Establish SSH connection
Connect to your Red Pitaya board using SSH. Replace <IP_ADDRESS> with your Red Pitaya’s IP address or use the .local address.
ssh root@<IP_ADDRESS or .LOCAL_ADDRESS>
For example:
ssh root@192.168.1.100
# or
ssh root@rp-f0xxxx.local
The default password is root.
Step 3: Load FPGA and start streaming application
Once connected via SSH, load the streaming FPGA image and start the streaming server:
redpitaya> overlay.sh stream_app
redpitaya> streaming-server
You should see LED 2 turn on and LED 0 blinking, indicating the streaming application is running.
Note
Keep this SSH terminal open. The streaming server must be running for the next steps.
Step 4: Get and edit the configuration file
Open a new terminal or command prompt window on your computer (don’t close the SSH session). Navigate to the directory where the command line client is installed.
Download the configuration file:
computer> .\rpsa_client.exe -c -g F
The configuration file will be downloaded to the configs folder of the command line client.
Edit the configuration file:
Open the downloaded configuration file (usually named something like streaming_config.json) with your favorite text editor.
For this example, configure DAC streaming at maximum rate with the generated waveform:
{
"dac_streaming" : {
"channel_gain_1" : "X1",
"dac_pass_mode" : "DAC_NET",
"dac_rate" : 125000000,
"file_sd" : "arb_waveform_signed16.wav",
"file_type_sd" : "WAV",
"repeat" : "DAC_REP_ON",
"repeatCount" : 1,
...
},
"memory_manager" : {
"block_size" : 8388608,
"dac_size" : 104857600,
...
}
}
Key parameters:
dac_rate: 125000000- 125 MS/s output rate (when waveform fits in memory)block_size: 8388608- 8 MiB network packet size (max supported)dac_size: 104857600- 100 MiB reserved for DAC bufferrepeat: "DAC_REP_ON"- Enable waveform repetitionrepeatCount: 1- Number of times to repeat (or use infinite mode)
For complete configuration options and DAC rate limitations, see DAC Configuration Reference
Note
1 MiB = 1024×1024 Bytes = 2^20 Bytes = 1,048,576 Bytes. We are using Mebibytes (MiB) instead of Megabytes (MB) to avoid confusion with the decimal system.
Save the edited configuration file as config_dac.json.
Upload the configuration file:
Upload the edited configuration file to the Red Pitaya board:
computer> .\rpsa_client.exe -c -s F -f .\configs\config_dac.json
Step 5: Start the DAC streaming
Now start the DAC streaming using the command line client. The DAC streaming will generate the sine wave signal on OUT1.
computer> .\rpsa_client.exe -o -f wav -d <path_to_wav_file>\arb_waveform_signed16.wav -r inf
Replace <path_to_wav_file> with the actual path to your WAV file.
For example:
computer> .\rpsa_client.exe -o -f wav -d C:\Users\YourName\Documents\arb_waveform_signed16.wav -r inf
Parameters explained:
-o- Output (DAC streaming mode)-f wav- WAV file format-d <path>- Path to the data file-r inf- Repeat infinitely
Step 6: Verify the output
You can now verify the sine wave output on OUT1 using:
An oscilloscope connected to the output
The Red Pitaya Oscilloscope application
A spectrum analyzer
The output should be a clean sine wave at the frequency determined by:
Step 7: Stop the streaming
To stop the DAC streaming, press Ctrl+C in the command line client terminal.
Troubleshooting
Waveform not generated
Problem: No output signal
Solutions:
Verify the streaming server is running on Red Pitaya
Check that the configuration file was uploaded successfully
Ensure the WAV file path is correct
Verify sufficient memory is allocated (
dac_sizein config)Check that the waveform file is not corrupted
Data loss or unstable signal
Problem: Signal has glitches or discontinuities
Solutions:
Ensure the waveform fits completely in reserved DDR memory (file size < dac_size)
When the waveform fits entirely in the reserved region, Red Pitaya can generate data at full speed (125 MSps)
If the file is larger than the reserved region, it will be continuously streamed to the board, significantly reducing performance and maximum output sampling speed
This is the most effective way to avoid glitches and achieve optimal performance
Reduce the
dac_rateif using true streaming modeIncrease
block_sizeto 8 MBEnsure the waveform has at least 1024 samples
Check network stability
Configuration errors
Problem: Configuration file rejected
Solutions:
Validate JSON syntax using a JSON validator
Check all parameter values are within valid ranges
Ensure memory allocations don’t exceed reserved DMM size
Verify file paths and names are correct
Variations and extensions
Multiple periods
To generate multiple periods of the sine wave, modify the Python script:
num_periods = 10 # 10 periods
t = np.linspace(0, num_periods, N*num_periods)*2*np.pi
y = np.sin(t)*max_val
Different waveforms
Generate other waveforms by modifying the generation equation:
Square wave:
y = np.sign(np.sin(num_periods*t))*max_val
Sawtooth wave:
from scipy import signal
y = signal.sawtooth(num_periods*t)*max_val
Triangle wave:
from scipy import signal
y = signal.sawtooth(num_periods*t, width=0.5)*max_val
Two-channel output
Create a WAV file with two channels to use both OUT1 and OUT2:
# Generate two different waveforms
y1 = np.sin(num_periods*t)*max_val # OUT1: sine
y2 = np.sin(2*num_periods*t)*max_val # OUT2: sine at 2x frequency
# Stack as stereo (2 channels)
y_stereo = np.column_stack((y1, y2)).astype(np.int16)
wavfile.write('stereo_waveform.wav', sample_rate, y_stereo)
Next steps
Experiment with different waveforms and parameters
Learn about DAC Configuration for more control options
Optimize performance by disabling the web interface
Review Data Generation Limitations to understand performance boundaries
Try combining with ADC streaming to create a signal processing loop
Explore Advanced Configuration for fine-tuning