LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing an element of an array with the previous element in that array.

First post, please let me know if there's anything I should do differently.

 

I'm grabbing a scope measurement in the form of a triangle waveform, and want only the parts of it with a positive differential - essentially a sawtooth. The waveform is stored in a one-dimensional array. Also, there is no way for me to trigger the measurement, so there is likely an incomplete bit of waveform before the first lowest value.

 

To prepare the data I decided to do two things:

-Cycle through the array and delete everything until I find the first lowest value.

-Save the values from lowest to highest, then delete everything until the next lowest value. Do this n times.

 

Does anyone have any good examples of cycling through an array in such a manner, or is there simply an easier way of going about it?

0 Kudos
Message 1 of 5
(2,766 Views)

This is a very straight-forward problem.  I'm sure we will have no difficulty helping you solve it.

 

However, it's always easier if you have some code written already that you can show us so that we can make concrete suggestions.

 

For the first part, it's not necessary to cycle through the array and delete each value.  Use the Array Min/Max function.  This will automatically find the lowest value for you (and tell you at which index value it occurs).  That way you can delete the first part without using a one-at-a-time search.

 

If you have any code written, please post it.

 

 

Message 2 of 5
(2,764 Views)

This is one way to do it.... if I understood you correctly.

 

 

 

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 3 of 5
(2,761 Views)

Thank you very much for the response!

 

Unfortunately I don't have any code to post at the moment, but you can assume the input would be an array of voltage values that comprise a triangle wave. Good suggestion about the array min/max function, however I forsee a potential issue with it.

 

It's possible that the triangle wave won't be 'perfect.' That is, the voltage of one peak or valley might not be exactly identical as measured from one to the other. It would be really nice if I could count on them to be identical, then I could min/max and just search for the min and max values. If I min/max, it's possible I could come up with a point at the middle or end of my waveform and lose useful data before it. There are two likely scenarios for the start of the waveform, so...

 

-We start on the downward slope of the triangle wave somewhere in the middle of it.

if array[x+1] is less than array[x], delete array[x]. If it's not, exit the loop.

 

-We start on the upward slope of the triangle wave somewhere in the middle of it.

This one is tougher. I could use Min/Max and make the determination based on how close to the min value we are within some margin of error.

 

-We could start exactly on the peak or valley of the triangle, but this is very unlikely with the number of measurements taken.

 

Is there a min/max that would allow for some margin of error?

 

0 Kudos
Message 4 of 5
(2,749 Views)

Hi all,

 

After some further consideration, I've decided to just use a trigger to gather the data I need rather than post-process it. It appears that there might be an issue with that as I'm using a PXIe-1075, so on to the next thread. Thanks for your suggestions!

 

Jon

0 Kudos
Message 5 of 5
(2,711 Views)