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

There were errors in the files I posted in an earlier post, mostly got confused and used THD+N everywhere.

The math is probably ok, if anyone spot a fault, please let me know.

Also take note that you need to setup your Waveform environment correctly, look at Attila post above to get a visual clue of what you need to enable.

Otherwise there are going to be errors while running the script.

I did not have time to have a shot at measuring IMD, still more to come.

In hope that it is useful, here are some corrected files.

THD_vs_Freq_%.dwf3script

DummyLoad_2.pdf

instructions.txt

DummyLoad.dch

Amplificateur_mesure.ods

THD_vs_Power.dwf3script

Link to comment
Share on other sites

Hello all,

Thank you so much for scripts you posted ! There were very useful for me !

But I noticed something strange: after running a similar script, I found that the script stops by itself after maybe 5 minutes.

I want it to keep running until I decide to stop it. Is there a restriction on that ?

Another question : is there a way to just run a waveform script by an external software, considering a saved workspace ?

It could be someting like calling the application waveforms with 2 arguments like : "waveforms <workspace> <script>"

This could be very useful !!

Thank you in advance

Regards

Link to comment
Share on other sites

Hi @4x4

In newer software versions the Network Analyzer has THD measurement. You may not need or need a simpler script.

To load a workspace and run the script:
waveforms example.dwf3work -runscript
To open and run a script:
waveforms -script example.js 
To run the current script:
waveforms -runscript

The previously posted script performs one sweep of 31 steps, see:
for(var idx = 0; idx <= slices; idx++)

If you want me to look at your script, why does it stop, please post or send it in message.

image.png.98997cb58d42b0434e3f55b2d5671b1f.png

Link to comment
Share on other sites

Any thoughts on building this functionality into Waveforms?  I know the Audio Suite exists, but us Linux and Mac users are left out.  I had asked the author about releasing the source and he was not open to that at all.

Thanks
Cory

 

Link to comment
Share on other sites

Thanks @attila!

Yeah, I'm using the BNC adapter board and some heavy duty, shielded BNC cables for both the AWG and Scope channels - found much cleaner results overall. Thanks for the heads-up though! Busy putting together a selectable 8ohm/4ohm dummy load that can just plug straight into the Analog Discovery via BNC, which will make testing amplifiers much quicker and easier.

Link to comment
Share on other sites

On 10/7/2017 at 6:16 PM, BaffleChallenged said:

There were errors in the files I posted in an earlier post, mostly got confused and used THD+N everywhere.

The math is probably ok, if anyone spot a fault, please let me know.

Also take note that you need to setup your Waveform environment correctly, look at Attila post above to get a visual clue of what you need to enable.

Otherwise there are going to be errors while running the script.

I did not have time to have a shot at measuring IMD, still more to come.

In hope that it is useful, here are some corrected files.

THD_vs_Freq_%.dwf3script

DummyLoad_2.pdf

instructions.txt

DummyLoad.dch

Amplificateur_mesure.ods

THD_vs_Power.dwf3script

Having trouble running the THD vs Freq script.  The line 

if(Spectrum1.Trace1.Config.Count.enable==true)

errors with 

Error in: "file 1" line: 32

TypeError: Result of expression 'Spectrum1.Trace1.Config.Count' [undefined] is not an object.

I googled Spectrum1.Trace1.Config.Count and got nothing, so I don't know where is comes from.  It this a problem with my config?  I'm running Gentoo Linux and WF version 3.12.1  Other than that I'm lost here.  Any suggestions? 

Thanks

Cory

 

 

Link to comment
Share on other sites

Hi tomtektest, I do follow your YouTube channel, I personnaly did not do any video. I do posses a digital photo camera and a tripod, but no editing software. (also note that English is not my primary language)

My interest in audio measurement is sparked from my experiment in amplifier design and build. This script is just one piece of the puzzle. I still miss THD vs power, but that will be trivial to build from the THD vs Freq above, just a few changes i presume.

I do follow a certain sequence, mostly due to setup constraints, and collect information in a spread sheet.

This is still messy at present, it is a work in progress.

If I come with something manageable, perhaps I could make the content puplicly available (spreadsheet, scripts, instructions on setting up and performing measurements).

If you review this content and think it makes senses, perhaps you could do a video on it.

Regards,

Link to comment
Share on other sites

I cannot try this right away, but I appreciate your work and will definitely look more at it in a little while. Keep up the good work and perhaps you could do a video about it at some point and post it on YouTube. Let me know if I can help in any way. I know there are many AD@ users who are looking for something like this for audio testing. tomtektest

 

Link to comment
Share on other sites

here is another version of the script i am working on,

it does both channel

it does scale the frequencies logarithmically

it does the averaging if trace 1 type allows count to be enabled.

it saves to a desktor CSV file for data manipulation in a speadsheet.

 

I made some modifications to the spreadsheet I use in hope it will be more generic and useful to others.

I also wrote some short instructions on how to proceed, but I am afraid it won't be clear for beginners.

I also made a drawing of dummy load and possible attenuator for interconnection with the Analog Discovery.

I

 

 

thd1watt.bmp

 

there were errors in the files, new files will be posted in an other post.

Link to comment
Share on other sites

Thanks @BaffleChallenged - I did much the same, although I incremented the script 1hz at a time for 20000 readings across the spectrum:

for(var idx = 20; idx <= 20000; idx++) // 20hz to 20khz, 1hz increments

The script takes about ~10 minutes to complete. Here was the output from a little LM1875 chip kit driving an 8 ohm dummy load. Neat! This was before I added the conversion from dB to % for THD (thanks this website for the explanation!), but it worked out to an average of -62dB, or 0.079% THD. Not too shabby for an eBay kit running in the open air.

Another useful addition I added was to average all the THD values to give you a single value to compare against, as well as formatting the output into something more CSV friendly in case the results need to be saved and plotted elsewhere. I'll upload my script changes as well when I'm back at my laptop.

Test-Setup.jpg

Screen---THD-Graph.jpg

Link to comment
Share on other sites

Hi, i modified attila script slightly so that the thd values are in % and the range is in the usual audio band.

Hope it could be useful for others.

 

function doTHD(){

var rgTHD = []

var rgFreq = []

for(var idx = 20; idx <= 20000; idx+=19980/30){

Wavegen1.Channel1.Simple.Frequency.value = 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 stopfrequency

 

Spectrum1.single() // start acquisition

if(!Spectrum1.wait()){ // wait to finish

return;

}

rgFreq.push(Spectrum1.Trace1.measureFreq("FF"))

rgTHD.push(100*Math.pow(10,Spectrum1.Trace1.measure("THD")/20))

}

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 = "%"

plot1.X.data = rgFreq

plot1.Y1.data = rgTHD

}

doTHD();

Link to comment
Share on other sites

My question is for attila, I tried your script, and it appears to work, but...

I chose linear db average with a count of 10 for the spectrum traces, but your script behaves like in sample mode, it takes the first reading only.

Is there a way to modify the wait sequence so that the spectrum does the 10 measurement and averaging?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...