I have signal generator 1 connected to the oscilloscope channel 1 and have been using that for testing. However, despite my best efforts, the data I am acquiring is not accurate and contains a lot of noise.
I have attached the code and screenshots of the acquired data for reference. I would be grateful if anyone could take a look and suggest any potential solutions to the problem.
Code: Select all
import matplotlib.pyplot as plot
import sys
import redpitaya_scpi as scpi
import numpy as np
from time import sleep
import time
#Setup the connection to the Red Pitaya
IP = "rp-f0a29f.local"
rp_s = scpi.scpi(IP)
#Set the parameters for the signal generator
wave_form = 'SQUARE'
freq = 2000
ampl = 1
#Decimation factor
dec = 32
#Generate the signal
def set_generator(waveform, frequency, amplitude, offset):
rp_s.tx_txt('GEN:RST')
rp_s.tx_txt('SOUR1:FUNC ' + str(waveform).upper())
rp_s.tx_txt('SOUR1:FREQ:FIX ' + str(frequency))
rp_s.tx_txt('SOUR1:VOLT ' + str(amplitude))
rp_s.tx_txt('SOUR1:VOLT:OFFS ' + str(offset))
rp_s.tx_txt('OUTPUT1:STATE ON')
rp_s.tx_txt('SOUR1:TRIG:INT')
set_generator(wave_form, freq, ampl, 0)
sleep(0.5)
#Define a function to sample the oscilloscope
def sample_oscilloscope():
#Set the parameters for the acquisition
rp_s.tx_txt('ACQ:RST')
rp_s.tx_txt('ACQ:DATA:FORMAT ASCII')
rp_s.tx_txt('ACQ:DATA:UNITS VOLTS')
rp_s.tx_txt(f'ACQ:DEC {dec}')
rp_s.tx_txt('ACQ:SOUR1:GAIN HV')
rp_s.tx_txt('ACQ:TRIG:LEV 0.5')
rp_s.tx_txt('ACQ:TRIG CH1_NE')
rp_s.tx_txt('ACQ:START')
sleep(0.1)
#Wait for the acquisition to finish
while 1:
rp_s.tx_txt('ACQ:TRIG:STAT?')
if rp_s.rx_txt() == 'TD':
break
#Read the data from the acquisition
rp_s.tx_txt('ACQ:SOUR1:DATA?')
print('Reading data...')
#rp_s.tx_txt('ACQ:SOUR1:DATA:STA:N? 0,1000')
buff_string = rp_s.rx_txt()
print('Done reading data!')
#Convert the data to a list of floats
buff_string = buff_string.strip('{}\n\r').replace(" ", "").split(',')
buff = list(map(float, buff_string))
return buff
buff = sample_oscilloscope()
#Plot the data
plot.plot(buff)
plot.ylabel('Voltage')
plot.show()
