LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Storing some values but not all

Solved!
Go to solution

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!

 

 

 

0 Kudos
Message 1 of 5
(3,449 Views)

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.


GCentral
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 2 of 5
(3,421 Views)

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..?

 

0 Kudos
Message 3 of 5
(3,396 Views)
Solution
Accepted by topic author bazingagirlsun

What you want to do is unclear.  Tell me if this is what you want to do:

  • Each iteration, get 768 points into a "Sample Array".
  • Throw away Sample Arrays 1 to 200.
  • Compute the average of Sample Arrays 201 to 220.  Call this Average Sample Array.
  • For all the "future" Sample Arrays (which you want), save Sample Array - Average Sample Array.

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:

  • .. 200 (which means any number <= 200).  This is the "Do Nothing" case where you throw the data away.
  • 201 .. 219.  This is the "Accumulate sums of Sample Arrays in a Shift Register (initialize the Register to an empty array).
  • 220.  Add the final Sample, divide by 20, and save (in the same Shift Register) as Average Sample Array.
  • 221 ..  Take your Sample Array, subtract Average Sample Array (from Shift Register), and do whatever you want to do with your referenced Sample. 

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

Message 4 of 5
(3,372 Views)
Solution
Accepted by topic author bazingagirlsun

@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.


GCentral
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
Message 5 of 5
(3,353 Views)