Faster FRA from scope by external control over VISA - Page 1
Forum section: electronics / testgear

author: Someone
author_rank: Super Contributor
timestamp: March 20, 2019, 07:49:28 am
content: For those who haven't used it, the built in Frequency Response Analysis tool on Keysight scopes is a little clunky and slow. Along with a lack of control over the parameters it can fail to scale well and just give up on some runs. While working on some other automation it struck me how fast these scopes respond to visa commands, so an afternoon later we have a reimplementation of the FRA except from a host computer.Code:import visaimport usbimport numpy as npf_min = 100;f_max = 10e6;f_points_decade = 50;f_vector = np.append(10**np.arange(np.log10(f_min),np.log10(f_max),1/float(f_points_decade)),f_max)gain_vector = np.zeros_like(f_vector)phase_vector = np.zeros_like(f_vector)input_scales = [500e-6,1e-3,2e-3,5e-3,10e-3,20e-3,50e-3,100e-3,200e-3,500e-3,1e0,2e0,5e0,10e0]input_scale = 10probe_scale = 10#reset usb to recover from unclosed resource#dev = usb.core.find(idVendor=0x2a8d, idProduct=0x1797)#print(dev)#dev.reset()rm = visa.ResourceManager()print(rm.list_resources())o_scope = rm.open_resource(rm.list_resources())#print(o_scope.query('*IDN?'))o_scope.write('ACQuire:TYPE HRESolution')o_scope.write('TIMebase:POSition 0E0;RANGe 100E-3')o_scope.write('WGEN:FUNCtion SINusoid;OUTPut ON')o_scope.write('MEASure:CLEar')#;VRMS CYCLe,AC,CHANnel1;VRMS CYCLe,AC,CHANnel2;PHASe CHANnel1,CHANnel2')o_scope.write('CHANnel1:COUPling AC;PROBe 1E0;OFFSet 0 V;SCALe '+("{:.0e}".format(input_scales)))o_scope.write('CHANnel2:COUPling AC;PROBe 1E0;OFFSet 0 V;SCALe '+("{:.0e}".format(input_scales)))o_scope.write(':RUN')for i,frequency in enumerate(f_vector):o_scope.write('WGEN:FREQuency '+("{:.3e}".format(frequency)))o_scope.write('TIMebase:POSition 0E0;RANGe '+("{:.3e}".format(4/frequency)))if (frequency > 10e3):o_scope.write('ACQuire:TYPE AVERage;COUNt 128')o_scope.write(':DIGitize')data_good = Falsewhile (data_good == False):data_good = True # think positive!v_source = o_scope.query_ascii_values('MEASure:VRMS? DISPlay,AC,CHANnel1')v_probe = o_scope.query_ascii_values('MEASure:VRMS? DISPlay,AC,CHANnel2')if (v_source > 2*input_scales):if (input_scale == (len(input_scales)-1)):print('Data Clipped at max range!')else:input_scale = input_scale + 1o_scope.write('CHANnel1:SCALe '+("{:.0e}".format(input_scales)))data_good = Falseelse:if (v_source*2 < input_scales) & (input_scale != 0):input_scale = input_scale - 1o_scope.write('CHANnel1:SCALe '+("{:.0e}".format(input_scales)))data_good = Falseif (v_source > 2*input_scales):if (probe_scale == (len(input_scales)-1)):print('Data Clipped at max range!')else:probe_scale = probe_scale + 1o_scope.write('CHANnel2:SCALe '+("{:.0e}".format(input_scales)))data_good = Falseelse:if (v_source*2 < input_scales) & (probe_scale != 0):probe_scale = probe_scale - 1o_scope.write('CHANnel2:SCALe '+("{:.0e}".format(input_scales)))data_good = Falseif (data_good == True):d_phase = o_scope.query_ascii_values('MEASure:PHASe? CHANnel1,CHANnel2')if (d_phase > 1e6):data_good = Falsegain_vector = v_probe/v_sourcephase_vector = d_phaseo_scope.close()Wonder of wonders, its 3 times faster than using the scope its self and you end up with the data neatly stored on your computer ready for use. Its not as accurate on the phase measurement (the built in might be using a separate optimised capture window to get that measurement) but does better for gain using averaging for higher frequencies. With the ability to customise this for your specific needs you can optimise it easily.Future work for an FFT based FRA from the step response could be very interesting.

author: analogRF
author_rank: Super Contributor
timestamp: January 22, 2021, 11:55:19 am
content: Great stuff, thanks for sharing

author: analogRF
author_rank: Super Contributor
timestamp: February 08, 2021, 01:31:10 pm
content: There is a measurement trend math function also available in 3000A.So I guess if you let the function gen sweep (perhaps not too fast so to let the measurement and math do their job)and plot the "trend" of the output amplitude measurement (a math trace), you will get the freq response.The only caveat is that the horizontal axis is still vs time but that's ok. if you choose your sweep time and freq span wisely,the relationship between the time axis and frequency is simple like e.g. 10MHz span is equivalent to 100msyou may also plot the trend of output phase relative to input phaseI have not done that myself yet since I got my 3054A recently and it is not fixed yet (waiting for part to repair the softkey buttons)

author: analogRF
author_rank: Super Contributor
timestamp: February 08, 2021, 09:23:28 pm
content: I just checked with my scope (still opened up on the bench) and the WAVEGEN does not have sweep at allI also checked that Measurement Trend math function and it sucks big time unless for very very slowly varying variables and you are very limited on what measurements you can choose for trend plotI tried to for example plot the trend of frequency for an FM modulated signal and even at 10Hz modulation frequencystill it could not recover the modulating signal cleanly.I have used the Trend plot on my old WavePro 7300A for plotting frequency response and even AM /FM demodulation.

author: Someone
author_rank: Super Contributor
timestamp: February 12, 2021, 08:02:59 am
content: Quote from: analogRF on February 08, 2021, 09:23:28 pmDont know what licenses/versions you were using but sweep is just a ramp FM modulation, triggers integrated (1000, 2000, or 3000 series all have this). But the onboard processing/calculating is limited/restricting which is why its better to use an external computer to do that, hence the example posted for this thread. They are all surprising fast at offloading data or measurements over VISA to a computer where you have complete flexibility of an open system.

author: joseangel
author_rank: Contributor
timestamp: June 04, 2025, 08:02:47 am
content: Quote from: Someone on March 20, 2019, 07:49:28 amThanks a lot for sharing. Your results are awesome!I have only started automating some measurements with VISA, mostly coordinating bench equipment slow measurements, nothing fancy. My next goal is trying to automate jitter measurements with VISA for capturing a bunch of waveforms, then Python for statistics and report. May I ask you some questions?- I've had tons of connectivity and compatibility issues with drivers. I can work with Linux, MacOS or Windows. MacOS was the worst (couldn't make it work at all). On windows, I had a lot of intermittent disconnects. What's your experience on this? Can you recommend a reliable platform and/or VISA driver?- Just a thought... What do you thing of Jupyter notebooks (or similar) for this sort of application. I normally use VS Code for my projects, but in this case, the integration with code snippets and images sounds like a treat.

author: Someone
author_rank: Super Contributor
timestamp: June 04, 2025, 08:34:04 am
content: Quote from: joseangel on June 04, 2025, 08:02:47 amTo minimise variables I've tried to stick to linux with pyvisa-py and network connectivity wherever possible, USB as a fallback. Instruments often have their peculiarities and don't always respond/work reliably even if using the vendors preferred software stack on the computer side.Quote from: joseangel on June 04, 2025, 08:02:47 amJupyter Notebooks are great for playing around and "interactive" (short runtime) uses, at some point you end up click around too much and it becomes easier to script/automate more of it.

author: joseangel
author_rank: Contributor
timestamp: June 04, 2025, 11:46:48 am
content: Quote from: Someone on June 04, 2025, 08:34:04 amI will try with Linux and pyvisa-py next, avoiding for now USB at all costs.You are absolutely right, with one specific programmable Siglent Power Supply, I ended having to write a low level TCP/telnet Python script to avoid VISA altogether (which was annoying to say the least). Will try again with Linux, as I suspect it was a problem related to the VISA Windows driver I was using, not to the Power Supply itself.Quote from: Someone on June 04, 2025, 08:34:04 amAgree. I find Jupyter very useful as "notebooks" during research, proof of concepts or silly tests.