I' m a newbie and I' m working on this simple project: my aim is to generate an arbitrary function with RP and sample it with RP as well, using SCPI commands in Matlab. I checked the example projects that I found in the RP website, and I' m able to sample the waveform in burst mode with a frequency up to 10K and decimation factor set to 64.
But, when it comes to use an higher freq, I can see the sampled waveform distorted. I think it's because of the decimation, which (correct me if i'm wrong) decreases the sampling rate by dividing it for a factor of 64, so with high frequencies I encounter aliasing. But, even setting DEC=1, I encounter some troubles I cannot explain to myself. For instance, trying to sample 1MHz, I have a double number of burst cycles (4 instead of 2) and a little decreasing envelope at the end of it.
If I try to sample 10MHz, I get this unknown bad thing:
I would like to make this project work for the wide range of frequencies this board can generate, so I would like to know from you what's missing in my code. I think i have misunderstood how the decimation factor operates, so I hope some of you can light up my mind!
Here's the code, slightly modified from a RP example:
Code: Select all
clc
clear all
close all
IP= '192.168.0.15'; % Input IP of your Red Pitaya...
port = 5000;
tcpipObj=tcpip(IP, port);
tcpipObj.InputBufferSize = 16384*64; % do le impostazioni di dimensione buffer al red pitaya
tcpipObj.OutputBufferSize = 16384*64; % in ingresso ed in uscita
%% Open connection with your Red Pitaya
fopen(tcpipObj);
%for i=1:2
tcpipObj.Terminator = 'CR/LF';
flushinput(tcpipObj)
flushoutput(tcpipObj)
%% Calcualte arbitrary waveform with 16384 samples
% Values of arbitrary waveform must be in range from -1 to 1!!!!
N=16383;
t=0:(2*pi)/N:2*pi;
x=1/2*sin(t)+1/3*sin(2*t);
plot(t,x) %viene plottata qui, non in acquisizione!
grid on
%% Convert waveforms to string with 5 decimal places accuracy
waveform_ch_1_0 =num2str(x,'%1.5f,');
% latest are empty spaces ?,?.
waveform_ch_1 =waveform_ch_1_0(1,1:length(waveform_ch_1_0)-3);
%% The example generate sine bursts every 0.5 seconds indefinitely
fprintf(tcpipObj,'GEN:RST');
fprintf(tcpipObj,'ACQ:RST');
fprintf(tcpipObj,'SOUR1:FUNC ARBITRARY');
fprintf(tcpipObj,['SOUR1:TRAC:DATA:DATA ' waveform_ch_1]) % Send waveforms to Red Pitya
fprintf(tcpipObj,'SOUR1:VOLT 1');
fprintf(tcpipObj,'SOUR1:FREQ:FIX 10000000');
fprintf(tcpipObj,'SOUR1:BURS:STAT ON'); % Set burst mode to ON
fprintf(tcpipObj,'SOUR1:BURS:NCYC 2'); % Set 1 pulses of sine wave
fprintf(tcpipObj,'OUTPUT1:STATE ON'); % Set output to ON
%% Set Acquire
fprintf(tcpipObj,'ACQ:DEC 1'); % decimation factor
fprintf(tcpipObj,'ACQ:TRIG:LEV 0'); % trig level
fprintf(tcpipObj,'ACQ:TRIG:DLY 8192'); % delay
%% Start gen % acq
tic
fprintf(tcpipObj,'ACQ:START');
pause(1);
fprintf(tcpipObj,'ACQ:TRIG AWG_PE');
fprintf(tcpipObj,'SOUR1:TRIG:IMM'); % Set generator trigger to immediately
%% Wait for trigger
while 1
trig_rsp=query(tcpipObj,'ACQ:TRIG:STAT?')
if strcmp('TD',trig_rsp(1:2))
break
end
end
%% Read & plot
signal_str=query(tcpipObj,'ACQ:SOUR1:DATA?'); % prendo i dati da source 1
toc
signal_num=str2num(signal_str(1,2:length(signal_str)-3));
figure,plot(signal_num)
hold on
grid on
%end
%% Close connection with Red Pitaya
fclose(tcpipObj);