Jump to content
  • 0

WaveForms SDK 3.11.5 - Data aquisition and signal generation questions


Andras

Question

Hi,

I combined a few python scripts from the SDK (AnalogIn_Acquisition, AnalogOut_Play and AnalogOut_Sine) to write a script which is intended to run during the night and save the scope's data into a WAV file.

All looks somewhat okay, but there are a few things that don't look perfect.

For this test, I connected CH1 and W1 and started both the Scope and Signal generator in the script. I'm intending to generate a 80 Hz sine wave and record it with the scope running at 8 kHz.

I attach the whole script, and here are the important parts:

# set up signal generation
channel = c_int(0)                                                                                # use W1
dwf.FDwfAnalogOutNodeEnableSet(hdwf, channel, AnalogOutNodeCarrier, c_bool(True))
dwf.FDwfAnalogOutNodeFunctionSet(hdwf, channel, AnalogOutNodeCarrier, funcSine)                    # ! this looks like a square wave
dwf.FDwfAnalogOutNodeFrequencySet(hdwf, channel, AnalogOutNodeCarrier, c_double(signalgenhz))
dwf.FDwfAnalogOutNodeAmplitudeSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1.41))            # ! this doesn't really do anything
dwf.FDwfAnalogOutNodeOffsetSet(hdwf, channel, AnalogOutNodeCarrier, c_double(1.41))

I played around with the parameters and after some investigation with Audacity it seems like the funcSine parameter generates a square wave and the amplitude is always 1.0 no matter what I set.

image.png.5dfede4635e602c17b730c77a6be48cc.png

 

The other problem I have is with the FDwfAnalogInStatusData function, it looks like it doesn't just get the raw data from the scope, is contains something else. So in order to get the scope's CH1 data, I need to have a 2-channel WAV file, and discard its first channel. The second is the data I'm looking for.

waveWrite = wave.open(startfilename, "wb");
waveWrite.setnchannels(2);                # 2 channels for the testing (1 channel would be enough if FDwfAnalogInStatusData returned only 1 channel's data
waveWrite.setsampwidth(4);                # 32 bit / sample
waveWrite.setframerate(samplerate);
waveWrite.setcomptype("NONE","No compression");
dwf.FDwfAnalogInStatusData(hdwf, 0, rgdSamples, buffersize)     # get channel 1 data CH1 - ! it looks like 2 channels get read here and only the second is the data of CH1
waveWrite.writeframes(rgdSamples);

 

I would expect that if I only need the CH1 of the Scope, I could save it into a mono WAV file.

AnalogIn_AcquisitionSaveToWAV.py

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

This script saves data chunks directly to wav file: AnalogIn_Record_Wave_Mono2.py

Note that the WAV file has a 4GB limit, which is about 7 hours for 80kHz 16bit mono!

The Analog Discovery has 5V and 50V pk2pk ranges, you can specify arbitrary values, like for 2.82V the 5V range will be used, for 5.64V 50V
For range setting 2xAmplitude should be used...

Link to comment
Share on other sites

Szia @Andras

The Python should look like this: AnalogIn_Record_Wave_Mono.py
This records and saves raw uncalibrated scope ADC data of 16bit signed values.

Imported looks like this:

image.thumb.png.cdc4bd02ea671760ad14a5c352ba096d.png

In your code with the 1.41V offset and 1.41V amplitude signal top value was 2.82V which with scope range of 5V, +/-2.5V peak entered in limitation. It was appending separate captures to wav file instead of continuously recorded data, the Python wave might not support 32float format.

Link to comment
Share on other sites

Szia @attila,

Cool, I'll try it right away.

The mistake I made is that I supposed that FDwfAnalogInStatusData returns 32-bit floats, not 64-bit doubles. Also, I didn't know about FDwfAnalogInStatusData16 which returns 16-bit integers. The other problems arose from this wrong presumption...

Python's wave supports both the 16-bit integer and the 32-float format, but not the 64-float.

Link to comment
Share on other sites

Hmm, it looks like I configured my Audacity to use 32-bit float sampling by default, and it loads every WAV as it were 32bit-float. Strange, and a little misleading, I need to be more careful next time, because that lead me to believe that 32-floats are supported in Python. My bad, sorry.

Anyway, I'm testing the script, I have a few questions:

The vAmplitude is the amplitude of the wavegen and as I change it I can confirm the change in the WAV file.
The scope also has the vAmplitude parameter, set to the same value as the wavegen. What does that exactly mean for the scope? If both the generator and the scope have the same vAmplitude, shouldn't the captured data (in the WAV file) always reach its peak value when the sine wave is at its peak?

You made a change so that the data is saved into memory during the recording and the file is only written at the end of the acquisition. It could be alright, but when I set the nSamples to a value which covers the whole night, start the script and then stop it within let's say 3 seconds, I'll get a huge file with a tiny amount of usable data at the beginning. Is there a way to change this, and only write the captured data?

Also the nSamples must be fit into a int, so capturing 8 hours can be done only at lower sample rates.
Is there an efficient way to do the wave saving continuously, so that there is no time or sample rate limitation (except the free space on the drive, of course)?

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...