LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Difficulty recording data from multiple for loop iterations

Solved!
Go to solution

Hi all,

 

I'm a bit of LabView novice but am having trouble with this likely not too challenging scenario. A picture of the code and the raw signal is attached. Essentially, I want to calculate the initial slope and the 500 ms rolling average peak for each of the plateaus. With my current code, I'm only getting the value for the first plateau for each array output. I'm not sure if my for loop within for loop approach is the issue or something about the code inside. Any assistance would be greatly appreciated.

Download All
0 Kudos
Message 1 of 11
(929 Views)

We typically don't debug images, but this code really has some bad smell. Have you done any tutorials?

 

  • A for loop with one iteration is just a glorified sequence frame.
  • Your inner while loop is basically a threshold array function.
  • It does not help if wires are hidden behinds structure

 

Please attach your VI (save for previous, 2020 or below) and make sure all controls have typical default values. Also include a dataset, unless the 1D array coming in from the left has a control with useful default data. Explain exactly what the code should do.

0 Kudos
Message 2 of 11
(908 Views)

I've done tutorials but my needs don't normally require customizing code so hence my status. Appreciate your input. See the code attached. The data file is too large unfortunately but the raw signal image exhibits its nature. It's muscle force data and I want to calculate the upward slope of each curve (aka RTD) started at 2.5 Nm until 200 ms later. Then, I want the peak 500 ms rolling average (aka PT) for each plateau. Point taken about the for loop with an iteration of 1 being pointless. When I delete it and only have the one for loop with 18 iterations I get the same result which is the RTD and PT data for the first plateau only for all iterations. Not sure what I'm missing to get RTD and PT data for each plateau.

0 Kudos
Message 3 of 11
(869 Views)

Hi ghester,

 


@ghester wrote:

I've done tutorials but my needs don't normally require customizing code so hence my status. Appreciate your input. See the code attached. The data file is too large unfortunately but the raw signal image exhibits its nature. It's muscle force data and I want to calculate the upward slope of each curve (aka RTD) started at 2.5 Nm until 200 ms later. Then, I want the peak 500 ms rolling average (aka PT) for each plateau. Point taken about the for loop with an iteration of 1 being pointless. When I delete it and only have the one for loop with 18 iterations I get the same result which is the RTD and PT data for the first plateau only for all iterations. Not sure what I'm missing to get RTD and PT data for each plateau.


I did some simplifications to your VI:

(There still is room for more simplifications.)

 

Your FOR loop running 26 times still doesn't make any sense you you simple do the very same calculation again and again: what is YOUR reason for this loop?

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 4 of 11
(855 Views)

I will give this a try, and thank you! You are correct that I need the same calculations to be performed for each plateau (let's say 26 times for this example). I was under the impression the for loop is the tool for doing consecutive calculations across sections of samples (each progressive plateau).

0 Kudos
Message 5 of 11
(834 Views)

You failed to attach your datafile, so we cannot test. Please attach it!

 

  • Why do you index out the time column if you don't even use it?
  • Why delete the first row of the initial large 2D array if you could just delete the first element of the torque column?
  • You could use linear evaluation to do the scaling.
  • You could probably filter with a simple convolution (filter-reverse-filer-reverse is "convoluted" (sic) in a very different way). However, most likely filtering is not even needed, because you take the mean later anyway. How much noise is there?
  • The entire loop code is just pure Rube Goldberg.

 

How regular are the gaps and plateaus in terms of spacing?

0 Kudos
Message 6 of 11
(818 Views)

My original data file was too large so I've attached a cut down data file that only has 3 of the plateaus. I don't doubt there are many aspects that could be improved or refined, but my main issue is performing the two calculations (PT and RTD) for successive plateaus. The program generally does what I need it to, reads torque column --->scales torque-->and calculates PT and RTD but only for the first plateau as it is. I just don't know how to have it done for each plateau. Noise is reasonable. Spacing is quite consistent (5 sec between plateaus) and the 2.5 Nm threshold is being used as the "indicator" of a new plateau.

0 Kudos
Message 7 of 11
(806 Views)

Why would you attach an xlsx file (Microsoft binary file) if you try to read it as comma delimited csv file?

You need to simply keep track of the processing point and continue from there.

 

So let me clarify:

 

  • Your time axis is a linear ramp of 500 microseconds per point
  • For each "bump", you want the slope of the of the first 200ms (400 points!)
  • A rolling average is multiple points. I think you you want the average of the next 500ms (1000 points), right?

This all seems trivial to do, let me try later...

0 Kudos
Message 8 of 11
(769 Views)

Hopefully, my clarifications for each bullet are helpful.

 

  • Sampling rate was 2,000 so each time point is 0.0005 sec apart
  • Exactly. I am after that slope for each bump.
  • I use a rolling average to get smooth it a bit. I want the highest 500 ms (so 1,000 samples) rolling average of each bump. Applying one rolling average function shits the signal time time, so two are applied with the signal being reversed in between.

 

0 Kudos
Message 9 of 11
(757 Views)
Solution
Accepted by topic author ghester

See if this can give you some ideas. (Currently not doing the max of the rolling average, so implement that if needed.

 

 

altenbach_1-1720806519755.png

 

altenbach_2-1720806530794.png

 

Message 10 of 11
(751 Views)