03-21-2016 07:21 PM
Hi all,
I have encountered difficulty in implementing this: storing some values from certain loop iterations as reference, and use the reference to subtract all new values generated from later loop iterations.
For example:
My sensor generates an array (size: 768) per timed loop iteration.
I want to generate a background reference array from iteration #201 to iteration #220. Currently I am using stacked shift register (20 shift regsitered stacked) to store the array generated from my sensor. The final background reference array is averaged over 20 arrays from shift registees:
background reference array = (array 1+ array 2 +...array 20)/20
I want to subtract this background reference array from all subsequently collected array.
new array - (array 1+ array 2 +...array 20)/20
The new array can by any array from a later iteration of the timed loop (#221 or beyond).
In other words, I am having trouble generating a fixed reference array for normalizing the real time data I got. And the fixed reference array is collected from the same channel as the real time data.
How do I do this? (I tried the case structure plus stacked shift register, but it does not work...)
Thanks!
Solved! Go to Solution.
03-21-2016 08:13 PM
You definately do not need a stacked shift register. Just the normal one will suffice here. What I would do is use the iteration counter. If 0, store the read array in the shift register. If 1 to 18, add the value in the shift register and the read array and store the sum in the shift register. On 19 (the 20th iteration), you add and divide by 20. You now have your reference array stored in the shift register. So from then on, you can just subtract the array in the shift register from the read array.
03-21-2016 09:13 PM
Thanks Crossrulz!
Your answer makes sense to me. But I have a few more questions:
1. What is a "iteration counter"? And how do I implement it? Is it a increment function wired to a shift register? Or is it an indicator wired to the "i" symbol in the timed loop?
2. How to add values to elements already stored in the shift register? Or in general, how to do operations to elements already stored in the shift register without having to update it forever..?
03-22-2016 12:03 AM
What you want to do is unclear. Tell me if this is what you want to do:
Is this correct? If so, your algorithm can be expressed as a While Loop (each loop gets data into a Sample Array) inside of which there is a Case Statement to which the While Loop index ("i") is wired. If you increment "i" before wiring it to the Case selector, your Case inputs will range from 1 .. however many samples you take, which makes the "counting" easier.
Create the following Cases:
If this is your Algorithm, it is very simple to implement (as you can see). If you want to do something else, you'll have to tell us more precisely what you want to do, but maybe with the description I just provided, you might be able to figure out for yourself how to vary the algorithm. if you still are stuck, clarify what you've tried (it's very helpful if you attach your code, meaning a VI (not a picture, please, unless it is an "executable picture", as we'll want to try it and examine it ourselves). Among other things, ambiguities in word descriptions of algorithms are usually easier to understand by looking at the code.
Bob Schor
03-22-2016 05:07 AM
@bazingagirlsun wrote:1. What is a "iteration counter"? And how do I implement it? Is it a increment function wired to a shift register? Or is it an indicator wired to the "i" symbol in the timed loop?
2. How to add values to elements already stored in the shift register? Or in general, how to do operations to elements already stored in the shift register without having to update it forever..?
1. The "i" terminal in the loop
2. For the cases where you are not updating the shift register, just wire the value straight through the case structure.