Jump to content
  • 0

Using script with Spectrum on AD2


tomtektest

Question

I am trying to find the script commands to access the Spectrum Analyzer in the Analog Discovery 2. I would like to specifically access the THD function to read a series of values at different frequencies (using the Wavegen), plot them and save them to a file. I am generally familiar with the use of scripts and have made them work on the scope, wavegen, etc. but cannot seem to find the commands to access the Spectrum Analyzer in Waveforms 2015. I have also used the debug function as well as the plot function so what I need are the specific access routines for the spectrum analyzer and its subfunctions (like THD, SNR, etc.)

Link to comment
Share on other sites

Recommended Posts

Hi @tomtektest, @abzza

With WaveForms Script THD and other measurement logging and plotting can be automated, like this:

i1.thumb.png.fb3fee13e1cbab2218dc54ae72bd0a47.png

function doTHD(){
    var rgTHD = []
    var rgFreq = []
    for(var idx = 1; idx <= 100; idx++){
       Wavegen1.Channel1.Simple.Frequency.value = 1000*idx
       Wavegen1.run() // start AWG
       wait(0.01) // settle time for the external circuit, expressed in seconds
       Spectrum1.Frequency.Stop.value = 20*Wavegen1.Channel1.Simple.Frequency.value // adjust analyzer stop frequency
       Spectrum1.single() // start acquisition
       if(!Spectrum1.wait()){ // wait to finish
          return;
       }
       rgFreq.push(Spectrum1.Trace1.measureFreq("FF"))
       rgTHD.push(Spectrum1.Trace1.measure("THD"))
    }
    Wavegen1.stop()
    print(rgFreq, rgTHD) // print data for copy paste
    // draw in plot1, View / Add plot
    plot1.X.Units.text = "Hz"
    plot1.Y1.Units.text = "dBc"
    plot1.X.data = rgFreq
    plot1.Y1.data = rgTHD
}
doTHD();

 

Link to comment
Share on other sites

6 hours ago, abzza said:

Excellent, thank you!

@tomtektest - I'm working on a Python script to at least do some basic automation of THD analysis across the 20hz-20khz spectrum. It won't be as pretty as the Audio Analyzer Suite, but it will get the job done. Will send it to you when it's ready to go!

I'm glad to see someone working on this; please keep us informed of your progress. I have not yet found a list of the new SA commands in 3.6.8, have you found them? I also look forward to seeing your script and would appreciate getting a copy (or access to it through the Digilent Forum) I have experience (commercial with languages like Java Script but have only used Python in small applications to help my granddaughters with some Raspberry Pi projects.

Link to comment
Share on other sites

On 8/28/2017 at 3:08 AM, attila said:

Hi @abzza @tomtektest

With WF 3.6.8 you can access Spectrum measurements, like:

print(Spectrum1.Trace1.measureFreq("FF")+" Hz") // fundamental frequency
print(Spectrum1.Trace1.measure("FF")+" dBV") // magnitude
print(Spectrum1.Trace1.measure("THD")+" dBc") // total harmonic distortion

Excellent, thank you!

@tomtektest - I'm working on a Python script to at least do some basic automation of THD analysis across the 20hz-20khz spectrum. It won't be as pretty as the Audio Analyzer Suite, but it will get the job done. Will send it to you when it's ready to go!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...