### Arbitrary waveform generator

Posted:

**Fri Jan 06, 2023 9:06 am**Dear all,

it's my first time playing around with the AWG using SCPI Server. I want to generate a signal that is a summation of a sine signal and a cosine signal which are different frequencies. I create the samples of two waveforms in Matlab and use the SCPI function to create the waveform from Red Pitaya at output 1. However, I cannot see the waveform since I connect output 1 and an oscilloscope. I cannot know the problem. Please help me to solve this problem. This is my Matlab code to generate. Thank you so much

///////////////////////////////////////////

%% Define Red Pitaya as TCP client object

clc

clear all

close all

IP = '192.168.0.21'; % Input IP of your Red Pitaya...

port = 5000;

RP = tcpclient(IP, port);

RP.ByteOrder = "big-endian";

configureTerminator(RP, "CR/LF")

Ac=1; % Amplitude of carrier signal

mc=4; % fc>>fs fc=mc*fs fs=1/Tb

fc=mc*(1/Tb); % frequency of cosine signal.

fr = (fc-250e3); % frequency of cosine signal.

fi1=0; % phase for bit 1

fi2=pi; % phase for bit 0

N=5; % Number of bits , size of transmitted signal x_inp=[x_1 x_2 ... x_N]

x_inp= randi([0,1], 1, N) ; % binary signal 0 or 1 % message to be transmitted

Tb=4E-6; % bit period (second)

x_bit=[];

nb=100; % bbit/bit

for n=1:1:N %

if x_inp(n)==1; %

x_bitt=ones(1,nb);

else x_inp(n)==0;

x_bitt=zeros(1,nb);

end

x_bit=[x_bit x_bitt];

end

t1=Tb/nb:Tb/nb:nb*N*(Tb/nb); % time of the signal

t2=Tb/nb:Tb/nb:Tb;

t2L=length(t2);

x_mod=[];

x_ref =[];

for (i=1:1:N)

x_ref0 = Ac*sin(2*pi*fr*t2);

if (x_inp(i)==1)

x_mod0=Ac*cos(2*pi*fc*t2+fi1);%modulation signal with carrier signal 1

else

x_mod0=Ac*cos(2*pi*fc*t2+fi2);%modulation signal with carrier signal 2

end

x_mod=[x_mod x_mod0];

x_ref = [x_ref x_ref0];

end

x_t = x_mod + x_ref;

waveform_ch_1_0 = num2str(x_t,'%1.5f,');

writeline(RP,'GEN:RST'); % Reset Generator

writeline(RP,'SOUR1:FUNC ARBITRARY'); % Set function of output signal

writeline(RP,['SOUR1:TRAC:DATA:DATA '' waveform_ch_1]);

writeline(RP,'SOUR1:VOLT 0.5'); % Set amplitude of output signal

writeline(RP,'OUTPUT1:STATE ON');

writeline(RP,'SOUR1:TRIG:INT');

//////////////////////////////////////////////////////////////

it's my first time playing around with the AWG using SCPI Server. I want to generate a signal that is a summation of a sine signal and a cosine signal which are different frequencies. I create the samples of two waveforms in Matlab and use the SCPI function to create the waveform from Red Pitaya at output 1. However, I cannot see the waveform since I connect output 1 and an oscilloscope. I cannot know the problem. Please help me to solve this problem. This is my Matlab code to generate. Thank you so much

///////////////////////////////////////////

%% Define Red Pitaya as TCP client object

clc

clear all

close all

IP = '192.168.0.21'; % Input IP of your Red Pitaya...

port = 5000;

RP = tcpclient(IP, port);

RP.ByteOrder = "big-endian";

configureTerminator(RP, "CR/LF")

Ac=1; % Amplitude of carrier signal

mc=4; % fc>>fs fc=mc*fs fs=1/Tb

fc=mc*(1/Tb); % frequency of cosine signal.

fr = (fc-250e3); % frequency of cosine signal.

fi1=0; % phase for bit 1

fi2=pi; % phase for bit 0

N=5; % Number of bits , size of transmitted signal x_inp=[x_1 x_2 ... x_N]

x_inp= randi([0,1], 1, N) ; % binary signal 0 or 1 % message to be transmitted

Tb=4E-6; % bit period (second)

x_bit=[];

nb=100; % bbit/bit

for n=1:1:N %

if x_inp(n)==1; %

x_bitt=ones(1,nb);

else x_inp(n)==0;

x_bitt=zeros(1,nb);

end

x_bit=[x_bit x_bitt];

end

t1=Tb/nb:Tb/nb:nb*N*(Tb/nb); % time of the signal

t2=Tb/nb:Tb/nb:Tb;

t2L=length(t2);

x_mod=[];

x_ref =[];

for (i=1:1:N)

x_ref0 = Ac*sin(2*pi*fr*t2);

if (x_inp(i)==1)

x_mod0=Ac*cos(2*pi*fc*t2+fi1);%modulation signal with carrier signal 1

else

x_mod0=Ac*cos(2*pi*fc*t2+fi2);%modulation signal with carrier signal 2

end

x_mod=[x_mod x_mod0];

x_ref = [x_ref x_ref0];

end

x_t = x_mod + x_ref;

waveform_ch_1_0 = num2str(x_t,'%1.5f,');

writeline(RP,'GEN:RST'); % Reset Generator

writeline(RP,'SOUR1:FUNC ARBITRARY'); % Set function of output signal

writeline(RP,['SOUR1:TRAC:DATA:DATA '' waveform_ch_1]);

writeline(RP,'SOUR1:VOLT 0.5'); % Set amplitude of output signal

writeline(RP,'OUTPUT1:STATE ON');

writeline(RP,'SOUR1:TRIG:INT');

//////////////////////////////////////////////////////////////