LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

distance between two consecutive elements in array and calculate the average

Solved!
Go to solution

Hello guys,

I'm new to labview and I have a problem: I need to calculate the difference between two consecutive elements in an array (output array in my program), and do the average of that distance.

Since my program uses a peak detector to calculate a frequency, I need the average value of all the distances between consecutive peaks (and that would be my period average, 1/period average I get frequency average). 

In my program I try doing a for cycle with N=#number of peaks found and it calculates the distance between the first element of the array and the 0-index. I thought it would work like this:

for(i=0;i<N;i++)

peak[i+1]-peak[i]=distance[i]

 

then do the average of the distance.

 

My program calculates that after N time.. when it reaches N, the Numeric 2 turns 0. 

I am trying to learn labview as quickly as I can, so any help is VERY appreciated. 

 

0 Kudos
Message 1 of 3
(3,515 Views)
Solution
Accepted by topic author deuchi

Sorry, I don't understand your code, but to calculate the pairwise difference of the elements in a 1D array, just subtract a copy with the first element deleted to get the new 1D array. No loop needed.

 

diff.png

 

 

  • Why are you operating on an evergrowing 2D array? You'll run out of memory?
  • Why are you prepending instead of appending? That's much more expensive in terms of memory management.
  • Your first small FOR loop belongs outside the while loop (Yes, the compiler optimization will probably do that anyway, but still....)
  • Index array is resizeable.
  • there is a primitive for 1/x
  • Don't randomly mix datatypes, e.g. don't make an array of clusters, one containing two 1D arrays and one containing an 1D array and a waveform. Not sure if LabVIEW will actually do what you think it should. Carefully inspect all red coercion dots.
  • ...

I don;t have Drivers, so I cannot see most of your IO functions or help further. Can you make a version that generates synthetic data instead to show the behavior?

Message 2 of 3
(3,503 Views)

You are absolutely right! it's true you don't need a loop for that, sorry I'm an amateur to labview...

I need the array for now to show me the time values of peaks, but I will delete it when I finalize my program.

I will also try to look for the primitive 1/x!

Thank you a lot!!!

0 Kudos
Message 3 of 3
(3,475 Views)