LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

calculations between two values from sequential loop iterations

Solved!
Go to solution

Hello all,

 

I have a code that is outputting our Power Spectral Density (PSD) from an FFT. A frequency is input and then stepped at a user input value. I would like to find the PSD difference between each frequency step. Attached is what I would like to happen. To avoid any confusion, I don't want to output a file that looks like that. I just want to display the "delta" column as an indicator on the front panel so I can monitor my change in PSD. I don't need the whole array, just the delta between the current iteration and the previous iteration. I've tried using a loop with shift registers, but I'm unsure of where to go from there. I figured that since shift registers pass data from loop to loop, that I could output the value before it went into the next iteration, but I'm having no luck. Any help is appreciated. Unfortunately, I am unable to post code due to company policy. I know this makes things much more difficult.

 

Thanks.

0 Kudos
Message 1 of 11
(4,124 Views)

Hi,

 

This is a method to use shift registers to analyse consecutive iterations.  You can replace with any analysis process.  Pull down on a regular shift register to store previous iterations of data ( it makes the second register box appear).

 

Analysis on conseq iterations.png

 

You might want to do more with the initial values.   If you want to do the analysis post process, then the solution is a loop reading the array and you can specify the indices and so no shift register needed.

-------
Mark Ramsdale
-------
0 Kudos
Message 2 of 11
(4,122 Views)

@Szklanam wrote:

Hello all,

 

 I figured that since shift registers pass data from loop to loop, that I could output the value before it went into the next iteration, but I'm having no luck. Any help is appreciated. Unfortunately, I am unable to post code due to company policy. I know this makes things much more difficult.

 

Thanks.


Shift Registers Don't pass data from loop to loop, they pass data from iteration to iteration for the loop. If you have two loops running parallel use 'Que's based (e.g. producer consumer) architecture. If the loops are running sequentially, then you can use the shift register on the first loop that executes to store all the data at the output tunnel of that loop. Use that data as an input to the next loop, and use auto indexing to perform operation on each point.

  It is very difficult to diagnose the problem without a vi. If this doesn't solve your problem post a anapshot of vi or something that is similar to what you are doing and may be we can help.



------------------------------------------------------------------------------------------------------
Kudos are (always) welcome for the good post. 🙂
0 Kudos
Message 3 of 11
(4,116 Views)

I feel dumb. I meant to say iteration to iteration seeing as I'm only dealing with one loop for this question anyway 😛 but thank you for the suggestions. I will try them and see how they work.

0 Kudos
Message 4 of 11
(4,109 Views)
Solution
Accepted by Szklanam

The suggestions didn't seem quite right, but I have found a way to do it. Attached is the way I did it.

0 Kudos
Message 5 of 11
(4,089 Views)

Why didn't you just put the shift registers on the FOR loop and remove the while loop?  That would be a lot simpler.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 11
(4,081 Views)
It is a massive for loop with a lot more code before and after the loop. I needed a way to keep everything in a small area. It's also within a sequencer. So long story short, for my code it works better this way unfortunately.
0 Kudos
Message 7 of 11
(4,069 Views)

A feedback node might make your life a little simpler.

https://www.ni.com/docs/en-US/bundle/labview/page/feedback-nodes-storing-data-between-loop-iteration...



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 11
(4,066 Views)

What you have posted looks like the program already has the data and you are feeding it to a one run loop that only holds the shift register to store the values.  If you already have the data you can use arrays.

 

If you are creating the data and then comparing to the previous iteration you can use the shift registers as I put above in a while loop or in a for loop.  The only reason I put dice outside the loop was to init the shift registers.

 

Feedback nodes work fine too, you can put them in a loop and attach the initial values to the loop edge.  

-------
Mark Ramsdale
-------
0 Kudos
Message 9 of 11
(4,046 Views)

@Szklanam wrote:

The suggestions didn't seem quite right, but I have found a way to do it. Attached is the way I did it.


Be careful, your solution may work the first time but you have an uninitialized shift register. This may cause you problems if theis loop gets executed multiple times. An uninitialized shift register will remember the value from the last time the loop was executed, not just the last iteration.

 

Also, you mentioned some scary things in your post regarding your code. It sounds like your code could use some cleaning up. Sequence structures, large amount of code before/after, etc are the types of comments made regarding poorly designed code. If you code requires more than a screen to display it is most likely in dire need of some cleanup.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
0 Kudos
Message 10 of 11
(4,037 Views)