REST API for frequency response & THD versus frequency

We use LabView to automate testing in our production lines. Is there any REST API to do fast frequency response and THD (or THD+N) measurement in sweep frequency?

Hi @chris, there’s not currently a way to do an expo sweep via REST, but it could be added pretty easily. It would likely be a POST /AcquisitionSweep or similar. You would then pull over the frequency series and verify that is matches your expectations. Probably we could add an API to compare to a mask for pass/fail. Let me know if you’d like to go that route.

And while it’s possible to to extract THD from a sweep, I prefer an actual sine stimulus. Generally, the allure of a sweep is the ability to get frequency response and THD all at once. However, you need longer sweeps to improve the accuracy and in the end spot checking with tones seems more productive and almost as fast.

I’ve added an example to the QA402_REST_TEST that shows how quickly you can step through 5 tones (50 Hz, 100, 1k, 10k, 20k) and make a THD and level measurement on each. When you think about manufacturing failures you are trying to detect (missing part) most can be readily found usually with some testing at the band edges. It takes about 2 seconds to run amplitude and THD at those 5 frequencies, which is pretty reasonable. You could go even faster by using a smaller FFT at the 1k and higher frequencies.

For frequency response and THD from a sweep, I also prefer actual sine stimulus. Usually, we need more points in a sweep. It will be very good if you can add APIs with sine sweep for frequency response and THD measurement. The API can define the tone frequencies and pass/fail limit mask.

Many audio products has built-in DSP which cause delay in output reference to input. When we use Audio Precision to do sweep measurement, the sweep from 20~20000Hz takes about 2sec. We have to define the delay for the AP to do the amplitude and THD processing. I believe the AP stores all the data in buffer during the sweep and do post processing calculation. This will help to reduce sweep measurement time. Maybe you can consider this.

Hi @chris, I think we can aim to do the sweep and comparison to a mask fairly quickly (maybe next week). But the THD from the sweep will come later. it has been part of the plan for a while, and you can see the UI in the settings.

If you don’t want to test against a mask, then you can run a sweep, and the pull across the freq bins and make whatever comparisons you wish in your code.

Hi @chris,

I misunderstood something on this side–the ability to sweep frequency response via REST is already present in the release (this went in release 0.994 in June). But there wasn’t an example in the QA402_REST_TEST.

I have added an example in the QA402_REST_TEST. If you push the Measure FreqResponse button in the Acquisition section, the sample code will perform an expo chirp, and then you can test the amplitude at whatever frequencies you wish. In the sample code, the checks are made at 100, 1000 and 20000 Hz


I’m not sure when the THD measurements will be added to the QA40x, but it won’t be in the near term as it’s a fairly large work item. But this should let you quickly confirm the frequency response in a sweep.

Sample code from QA402_REST_TEST

 async Task<bool> MeasureFreqResponse()
            double freq, ampDbv;
            int bin;

            // Set defaults and the set options
            await Qa402.SetDefaults();
            await Qa402.SetBufferSize(32768);
            await Qa402.SetInputRange(6);

            // Set up chirp generation
            await Qa402.SetOutputSource(OutputSources.ExpoChirp);
            // Set -10 dBV sweep, with no windowing and no smoothing, and do NOT use right channel as reference
            await Qa402.SetExpoChirpGen(-10, 0.0, 0, false);

            // Do the acqusition. This will take about 1 second (32768/48000 = 682 mS)
            await Qa402.DoAcquisition();

            // Pull across the frequency series. The is an array of doubles for the
            // left channel, and an array of doubles for the right. The Df parameter
            // indicates the bin spacing in Hz
            LeftRightFrequencySeries lrfs = await Qa402.GetInputFrequencySeries();

            // Compute amplitude in dBV at 100 Hz, and deterine if OK
            freq = 100;
            // Find the FFT bin number of the frequency we want
            bin = (int)Math.Round(freq / lrfs.Df);
            // Convert to dBV
            ampDbv = 20 * Math.Log10(lrfs.Left[bin]);

            // Compute amplitude in dBV at 1 kHz, and deterine if OK
            freq = 1000;
            bin = (int)Math.Round(freq / lrfs.Df);
            ampDbv = 20 * Math.Log10(lrfs.Left[bin]);

            // Compute amplitude in dBV at 20 kHz, and deterine if OK
            freq = 20000;
            bin = (int)Math.Round(freq / lrfs.Df);
            ampDbv = 20 * Math.Log10(lrfs.Left[bin]);

            return true;