Posted Wed, 27 Dec 2023 18:45:43 GMT by Zemlyansky, Maxim
Hi,
I'm using buffer.getstats().max.reading() to find out if there was a low voltage read that's not releavt.
But I would love to know if there is a way to know how many peaks there is? I have 12,000 measurements and I want to filter out measurement that's only 1 peak and not 2 or more...
Bottom line:
Is there a way to find out how many 'max' values found in the buffer.stats?

Thanks,
Maxim
 
Posted Wed, 27 Dec 2023 18:46:50 GMT by Zemlyansky, Maxim
I mean find out without reading all 12,000 values and filtering it after reading.. I mean by one command read number of peaks.
Posted Tue, 02 Jan 2024 21:20:09 GMT by Odhner, Bradley
Need some clarification here, do you want to find how many times a value (the max value) is repeated in a buffer? Or do you want to find multiple local maximum values?

For the former, I don't think there's a faster way to count the number of occurrences in a buffer than iterating through and using a helper variable to count the number of times you see the value you want. You mentioned you're searching for a low voltage condition though? You might be able to use limits to get what you want, see the dmm.measure.limit commands.

For the later, I think using a bit of calculus would be the best bet to find the number of local maxima. A compact way would be to use buffer.channelmath() with a created full buffer (not defbuffer1 or defbuffer2) and the buffer.EXPR_SUBTRACT expression. This creates a new column on the reading buffer that records the difference between the current reading and the previous reading. There is a local maximum wherever this column changes from positive to negative. Though, you will need to search through the data to find those changes, I'm not sure of a great way to do that automatically...
Another way could be to perform a binary search on the buffer by using timestamps to cordon off parts of the buffer to search in, using the buffer.getstats(bufferVar, relStartTime, relEndTime) syntax for example.
 
Posted Wed, 03 Jan 2024 21:21:34 GMT by Zemlyansky, Maxim
Hi Bradley,
Thanks for answering. first - I ment on how to find how many times a value (the max value) is repeated in a buffer.
But i found a workaround, using printbuffer and baudrate of 115,200kbps I found 12k counts to be fairly fast read, so I calculate how many max values there is myself. 
Thanks anyways!
Posted Wed, 03 Jan 2024 22:16:46 GMT by Odhner, Bradley

Ah glad you found a solution!

I would think it would be faster to do the search on the instrument using the TSP engine, did you try that? Unless you needed all the readings on your PC anyway. Or it sounds like things are running fast enough for you already.

This TSP code searches through defbuffer1 to find all instances of num within a tolerance (since defbuffer1[i] returns more digits than the measurement resolution).

function countInstance(num, tolerance)
    local count = 0
    local high = num + tolerance
    local low = num - tolerance

    for i = 1, defbuffer1.n do
        if high > defbuffer1[i] and defbuffer1[i] > low then
            count = count+1
        end
    end

    return count
end

After putting this function on your DAQ6510, you simply run print(countInstance(num, tolerance)) to return the count to the terminal.

Posted Thu, 04 Jan 2024 18:07:39 GMT by Zemlyansky, Maxim
Hi,
I'm using MATLAB with visadev to connect to the instrument & sending TSP commands remotly.
At first the baudrate was 9600 and it took 2.1minutes to read 12k readings from buffer using this method.
Then I found this and upped the baudrate to 115200 which is 12x times lower in time (around 20s),
I'm doing Acceptance tests with this equipment which is very important for me to be accurate, so I prefer read everything and process myself.
This is perfect for production environments.

Thanks again Bradley!

You must be signed in to post in this forum.