Generate signal pulses Description

This example shows how to generate signal pulses of predefined signal waveforms like sine, triangle, square, ramp up, ramp down or pwm. Generated signal can be observed by an Oscilloscope. Required hardware

  • Red Pitaya device

../../_images/output_y49qDi.gif Code - MATLAB®

The code is written in MATLAB. In the code we use SCPI commands and TCP/IP communication. Copy code from below to MATLAB editor, save project and press run.

%% Define Red Pitaya as TCP/IP object
clear all
close all
IP= '';          % Input IP of your Red Pitaya...
port = 5000;                    % If you are using WiFi then IP is:
tcpipObj=tcpip(IP, port);       %

tcpipObj.Terminator = 'CR/LF';

%% The example generate sine bursts every 0.5 seconds indefinety

fprintf(tcpipObj,'SOUR1:FUNC SINE');
fprintf(tcpipObj,'SOUR1:FREQ:FIX 1000');     % Set frequency of output signal
fprintf(tcpipObj,'SOUR1:VOLT 1');            % Set amplitude of output signal

fprintf(tcpipObj,'SOUR1:BURS:STAT BURST');      % Set burst mode to ON
fprintf(tcpipObj,'SOUR1:BURS:NCYC 1');       % Set 1 pulses of sine wave
fprintf(tcpipObj,'SOUR1:BURS:NOR 1000');     % Infinity number of sine wave pulses
fprintf(tcpipObj,'SOUR1:BURS:INT:PER 5000'); % Set time of burst period in microseconds = 5 * 1/Frequency * 1000000
fprintf(tcpipObj,'OUTPUT1:STATE ON');        % Set output to ON

%% Close connection with Red Pitaya

fclose(tcpipObj); Code - C


C code examples don’t require the use of the SCPI server, we have included them here to demonstrate how the same functionality can be achieved with different programming languages. Instructions on how to compile the code are here -> link

/* Red Pitaya C API example Generating signal pulse on an external trigger
* This application generates a specific signal */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include "rp.h"

int main(int argc, char **argv){

        /* Burst count */

        /* Print error, if rp_Init() function failed */
        if(rp_Init() != RP_OK){
                fprintf(stderr, "Rp api init failed!\n");

        rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);
        rp_GenFreq(RP_CH_1, 1000);
        rp_GenAmp(RP_CH_1, 1.0);

        rp_GenMode(RP_CH_1, RP_GEN_MODE_BURST);
        rp_GenBurstCount(RP_CH_1, 1);
        rp_GenBurstRepetitions(RP_CH_1, 10000);
        rp_GenBurstPeriod(RP_CH_1, 5000);
} Code - Python


import sys
import redpitaya_scpi as scpi

rp_s = scpi.scpi(sys.argv[1])

wave_form = 'sine'
freq = 10000
ampl = 1

rp_s.tx_txt('SOUR1:FUNC ' + str(wave_form).upper())
rp_s.tx_txt('SOUR1:FREQ:FIX ' + str(freq))
rp_s.tx_txt('SOUR1:VOLT ' + str(ampl))
rp_s.tx_txt('SOUR1:BURS:NCYC 1')
rp_s.tx_txt('SOUR1:BURS:STAT BURST')
rp_s.tx_txt('SOUR1:TRIG:SOUR INT')
rp_s.tx_txt('OUTPUT1:STATE ON') Code - LabVIEW