Generate continuous signal Description

This example shows how to program Red Pitaya to generate analog 2kHz sine wave signal with 1V amplitude. Red Pitaya is able to generate signals in range from DC to 50 MHz with output voltage range from -1 to 1 Volt. Generated signal can be observed by an Oscilloscope. Required hardware

  • Red Pitaya
../../../_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

IP= '';           % Input IP of your Red Pitaya...
port = 5000;
tcpipObj=tcpip(IP, port);

%% Open connection with your Red Pitaya

tcpipObj.Terminator = 'CR/LF';

fprintf(tcpipObj,'SOUR1:FUNC SINE');       % Set function of output signal
                                        % {sine, square, triangle, sawu,sawd, pwm}
fprintf(tcpipObj,'SOUR1:FREQ:FIX 2000');   % Set frequency of output signal
fprintf(tcpipObj,'SOUR1:VOLT 1');          % Set amplitude of output signal
fprintf(tcpipObj,'OUTPUT1:STATE ON');      % Set output to ON

%% Close connection with Red Pitaya

view rawgenerate_continuous.m
Code - C

/* Red Pitaya C API example Generating continuous signal
* This application generates a specific signal */

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

#include "redpitaya/rp.h"

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

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

    /* Generating frequency */
    rp_GenFreq(RP_CH_1, 10000.0);

    /* Generating amplitude */
    rp_GenAmp(RP_CH_1, 1.0);

    /* Generating wave form */
    rp_GenWaveform(RP_CH_1, RP_WAVEFORM_SINE);

    /* Enable channel */

    /* Releasing resources */

    return 0;
view rawgenerate_continuous.c
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))

#Enable output
rp_s.tx_txt('OUTPUT1:STATE ON') Code - LabVIEW