Arbitrary waveform generator

Applications, development tools, FPGA, C, WEB
Post Reply
tiennt
Posts: 1
Joined: Fri Jan 06, 2023 2:45 am

Arbitrary waveform generator

Post by tiennt » 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');

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

User avatar
redpitaya
Site Admin
Posts: 644
Joined: Wed Mar 26, 2014 7:04 pm

Re: Arbitrary waveform generator

Post by redpitaya » Tue Jan 10, 2023 12:10 pm

Dear tinnet,

I'm going to assume that you have specified the signal you want to generate correctly.
To avoid issues in the future, please make sure that the Arbitrary waveform represents ONE period of your signal and that the length of the sent period in samples is 16384. In short, the frequency you set with the SOUR1:FREQ:FIX command is calculated to be precise for 16384 samples (one buffer).

The other things that are preventing the code from working:

Code: Select all

writeline(RP,['SOUR1:TRAC:DATA:DATA '' waveform_ch_1]); 
% The quotations should both be the same
- You are missing this line:

Code: Select all

waveform_ch_1 = waveform_ch_1_0(1, 1:length(waveform_ch_1_0) - 3);
This will get rid of the brackets of the array.

Alternatively, you can send the data like this:

Code: Select all

writeline(RP,"SOUR1:TRAC:DATA:DATA " + waveform_ch_1);
Each parameter that you do not set, will be defaulted to the default value. In the case of frequency, this is 1 kHz.

Post Reply
jadalnie klasyczne ekskluzywne meble wypoczynkowe do salonu ekskluzywne meble tapicerowane ekskluzywne meble do sypialni ekskluzywne meble włoskie

Who is online

Users browsing this forum: No registered users and 7 guests