Phil_D

Members
  • Content Count

    26
  • Joined

  • Last visited

Posts posted by Phil_D

  1. Hello,

    I see in the specs that the max buffer size is over 16k points, but it seems that I can only get 8192 samples from this code. "FDwfAnalogInBufferSizeInfo" returns 8192.  How can I get the 16k samples?  I would like to get 16k samples for each ADC channel.  I am using the Analog Discovery 2. Thanks!

    int main(int carg, char **szarg)
    {
        HDWF hdwf;
        STS sts;
        double* rgdSamples;
        int cSamples;
        int cChannel;
        char szError[512] = { 0 };

        int channum = 0;

        cout << "hello world!";

        remove("ADC_results.txt");

        printf("Open automatically the first available device\n");
        if (!FDwfDeviceOpen(-1, &hdwf)) {
            FDwfGetLastErrorMsg(szError);
            printf("Device open failed\n\t%s", szError);
            return 0;
        }

        // get the number of analog in channels
        FDwfAnalogInChannelCount(hdwf, &cChannel);

        // enable channels
        for (int c = 0; c < cChannel; c++) {
            FDwfAnalogInChannelEnableSet(hdwf, c, true);
        }

        // set 5V pk2pk input range for all channels
        FDwfAnalogInChannelRangeSet(hdwf, channum, 5);

        // 10MHz sample rate
        FDwfAnalogInFrequencySet(hdwf, 10000000.0);


        // get the maximum buffer size
        FDwfAnalogInBufferSizeInfo(hdwf, NULL, &cSamples);
        FDwfAnalogInBufferSizeSet(hdwf, cSamples);

        // acquisition mode set added by Phil
        FDwfAnalogInAcquisitionModeSet(hdwf, acqmodeSingle);

        rgdSamples = new double[cSamples];

        // configure trigger
        FDwfAnalogInTriggerSourceSet(hdwf, trigsrcNone);

        Wait(2);

        // start
        FDwfAnalogInConfigure(hdwf, 0, true);

        printf("Waiting for triggered or auto acquisition\n");
        do {
            FDwfAnalogInStatus(hdwf, true, &sts);
        } while (sts != stsDone);

        FDwfAnalogInStatusData(hdwf, channum, rgdSamples, cSamples);
        fopen_s(&gDatLog, "ADC_results.txt", "a");

        for (int i = 0; i < cSamples; i++)
        {
            fprintf(gDatLog, "%lg\n", rgdSamples);
        }
        fclose(gDatLog);


        // close the device
        FDwfDeviceClose(hdwf);
        //}


        return 0;
    }

  2. Hello,

    I'm using the Analog Discovery 2, and am using the API to basically use it as a high speed digitizer.

    What signal level would it take to drive the scope channels to full-scale on the ADC?  I see that there are different gain options as well, but I also don't know how to control that with the API, if I even can?

    We'd like to set our max swing at full scale so we can get the best SNR.

    Thanks,

    Phil

  3. One more hopefully quick question here:

    I would like to export the data after all of the windowing/padding/averaging is complete.

    I'm using:

    Spectrum1.Export("C:/Users/User/pjm_2019/data.txt")

    ...but this gives me the results for Trace1, Trace5, and Trace 6.

    Is there a way to export only Trace 6? 

    I tried:

    Spectrum1.Trace6.Export("C:/Users/User/pjm_2019/data.txt")

    but that gave me an error.

    Thanks!

  4. Thank  you for the continued support on this, @attila!

    However, I think that the FFT window function is not working right when we pad before doing the windowing function.  I'll explain:

    I'm using another signal processing program called Sigview, and I can add zero padding there as well. I did a bunch of exporting and graphing in Excel to compare padding between Sigview and Waveforms:

    These are the two FFTs I'm getting in Waveforms, no padding in red and 2x padding in green. You can see that the 2x padding trace in green does not look at all like the red trace without padding.
    image.png.5248a59808899903267a491e4a205724.png

    This graph below is comparing Waveforms and Sigview, both Hann windows, both using no padding. They are basically identical, except for a 3dB offset. I used magnitude in Sigview and RMS (dB) in Waveforms, which I think accounts for that 3dB. But the important thing is that the shape of the FFTs is identical.  Same data in both cases, same window (Hann), both programs produce the same FFT.

    image.png.175614447dff12ed2ab62b3d6a09fc6d.png

    Now, I add padding in Sigview.  Blue is 2x padding, magenta is no padding. The traces are nearly identical, except the padding in the blue trace helps smooth out the peaks. I think this is how the padding should work.
    image.png.8a9d70bd1ad3a759e72a4d47844e44d1.png

    We were wondering if it would be possible to do the math to apply the Hann window on the data array in the script *before* adding the padding?  So the order of operations would be:
    1. Apply the Hann window to the data

    2. Add zero padding

    3. Take the FFT

    It looks like you added the padding, then did the window, then did the FFT.  As you mentioned, applying the window after the padding really attenuates the actual data and adds more emphasis to the 0's.

    I would like to add the padding in Waveforms so we can take advantage of the averaging. With Sigview, I'd have to import many static datasets, process each one separately, and then average in C++, which would be much more laborious and time consuming.

    We found a couple of links that talk about this padding and windowing:
    https://dsp.stackexchange.com/questions/13736/zero-pad-before-or-after-windowing-for-fft/13740

    http://www.mechanicalvibration.com/Zero_Padding_FFTs.html

    Thanks!

     

     

  5. This is great! Thanks @attila!

    Does this script end up with a rectangular window?   The padded, averaged result from the script looks very different from our previous unpadded result.  Is there a way to set the type of windowing function that is used in your script?  We'd like to use a Hann window.  I tried to look through other objects/functions with cntrl+space, but didn't see any way to set the window type.

    Also, if I wanted more than 2x padding, would I do something like

    for(var i = 0; i < 2*c; i++) rg.push(t) //4x padding???

    Thanks!

     

  6. Is there a way for a script function to have a delay that will wait for a certain number of averages to take place before stopping the trace?

    Right now, I'm doing this:

    Spectrum1.run()
    wait(1.1)
    Spectrum1.stop()
    Spectrum1.Export("C:/Users/User/pjm_2019/acquisition410.doc")

    For the few times I tried this by hand, 1.1 seconds was enough time to get at least 50 averages in my trace. I'm just wondering if there isn't something a little more precise than this, that would maybe get feedback from the Spectrum display and know exactly when 50 averages was achieved.

    Thanks!

  7. Thank you @attila!  This update seems to be working for me!

    Also, thank you for the suggestion @bvleo!

    For anyone reading this thread and trying to do something similar, I created a python script with these commands:

    import subprocess
    subprocess.Popen(['C:/Program Files (x86)/Digilent/WaveForms3/WaveForms.exe','C:/Users/User/pxm_2019/pn_410.dwf3work'])
    subprocess.Popen(['C:/Program Files (x86)/Digilent/WaveForms3/WaveForms.exe','C:/Users/User/pxm_2019/pn_410.dwf3work','-runscript'])

    This opens Waveforms, opens my workspace with the saved script (that is open within the saved workspace), and then runs the script.

    If Waveforms is already open, then I can just create a second python script with the second line deleted.

    ps: If you try to copy and paste code out of here into notepad, you'll probably get some extra characters and python will give errors, so watch out for that.

     

  8. Thanks @attila.

    Now, I'm using this:

    import subprocess
    subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe','C:/Users/phild/Documents/phase_noise_408.dwf3work'])
    subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe','-runscript'])

    At this point, Waveforms opens, and the specified workspace does load automatically now, which is good! 🤩 (Side note: I had to move the workspace to a different directory so that it could be found.  Originally, it was in the same directory as WaveForms.exe, but it wouldn't load from there.) The script is still not running automatically though.

    Any thoughts on why the script isn't running automatically?

    Thanks,

    Phil

    ps: I am running Waveforms Version 3.8.2 32-bit Qt 5.6.3 Windows 7

  9. Hi @attila,

    Not sure if I should start a new thread, but I'm struggling with the stuff being discussed here.  I'm trying to use Python to open a workspace and then run a script in the workspace.

    import subprocess
    subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe', 'phase_noise_237.dwf3work'])

    subprocess.Popen(['C:/Program Files/Digilent/WaveForms3/WaveForms.exe', '-runscript export_data.dwf3script'])

     

    I want to open the "phase_noise_237.dwf3work" workspace, and then run the script "export_data.dwf3script", which is saved as a part of that workspace.

    Waveforms opens, but does not open the workspace. Then I open the workspace by hand, and then run the python code to run the script, it tries to open Waveforms again.

    Thanks,
    Phil

  10. Is there source code available for DWFCMD.EXE?

    I've found source code examples for many other functions using the C++ and python APIs, so I'm just wondering if source code was available for DWFCMD.EXE.  It's a really useful program, by the way, and it's made getting up-and-running with the AD2 much faster.  But now we have reached a point where it's too slow to call as stand-alone executable.

    Thanks.

  11. On 6/11/2018 at 5:27 AM, attila said:

    Hi @Phil_D @rprr

    The problem is that the USB IN packets/bytes are randomly lost/altered.
    I tried various kernel options, limiting the USB transfer rates but had no luck. The data corruption reduced from one in 1-60 seconds to one in 10-60 minutes, which it is still not good...

    It seems that the root of the problem is in the low level FTDI library, kernel or USB modules, or between them...
    The Analog Discovery is working fine with other SOCs but not with the RPi.
    I also notice issue with the USB keyboard I use with the RPi, time to time key presses are not received. 
    You can find many similar RPi issues on the net:
    https://www.raspberrypi.org/forums/viewtopic.php?f=28&amp;t=5249&amp;sid=8839659cb92b7475fa196b2fad775d9f&amp;start=250
    http://www.ftdicommunity.com/index.php?topic=40.0

    Is it possible to have a software mod that would check for missed packets and if the expected packet is not there, the software just requests another, until it gets a packet?  I guess there'd have to be some kind of time out, or limit to how many missed packets would be allowed before terminating the request. Obviously, you wouldn't want to keep requesting packets indefinitely.

     

  12. I'm using the program DWFCMD.exe and the analogin.txt file (from the directory C:\Program Files\Digilent\WaveFormsSDK\samples\dwfcmd) to acquire data from the Analog Discovery 2 channel 1. The file analogin.txt file has a comment that says, "#Wait a bit for device analog circuit to stabilize" and then is followed by a 2 second pause.

    Is the 2 second pause necessary?  I would like to use a much smaller pause here, or none at all.

    Thanks.

  13. Is it possible to run FFTs with the API?

    I really like the Spectrum Analyzer feature in the Waveforms application -- are any of those features available in the API?  Specifically, I'd like to use the API to acquire time domain data from the Analog Discovery 2 (I do see the functions to do this), but then I'd also like to convert the time domain data to frequency domain.

    I combed through the SDK, but I didn't see anything.

    Thanks,

    Phil