07-02-2013 06:41 AM
I have an array of samping frequency values (determined by an external signal) and I would like to extract one value at a time from this array to use as the sampling frequency for another signal.
The shift register almost does what I want. The problem is that I don't always want to start at element 0, but rather at the first positive sampling frequency value, which has a slightly different index each time. Once this value is reached, I want the index to increment by 1 each loop iteration (which it already does).
I have attached a VI for reference. Any suggestions?
Solved! Go to Solution.
07-02-2013 06:55 AM
Please post the code in 2011 version
07-02-2013 06:56 AM
You can acquire before you intialize shift register & index the required value by comparision for first iteration
07-02-2013 07:19 AM
Here is the 2011 version
07-02-2013 07:23 AM
I need the DAQ to remain inside the while loop because the data is going to still be coming in while the sampling values are being extracted. Is there a way to do this that keeps the DAQ in the while loop?
07-02-2013 08:01 AM
Laura121,
I can think of two ways to do that. One is to place a copy of the DAQ Assistant outside the loop. Take one reading to get the initialization value for the shift register then proceed as you are now doing for subsequent measurements.
The other way is do the initialization in a case structure. When i = 0 (first iteration), initialize the shift register. For i > 0, use existing code. This method would only require one DAQ Assistant.
It is not clear that your code or either of the approaches I described actually does what you said you want to do in the original post: "...extract one value at a time from this array..." Each time through the loop you take another set of readings, discard all the old data, and take one sample from the array at the index determined by the shift register. This is not what I would consider extracting one value at a time from the array. If you really want to go through the entire array, you need to do the sampling frequency extraction many times for each DAQ Read.
You also should have some error handling to consider the case where no element in the Array of Sampling Frequencies is positive or the case where you have reached the end of the array.
Lynn
07-02-2013 08:09 AM
I posted a simplified version of my VI. In my actual version, there is an array that stores values from the previous loop iteration (this array grows in size each iteration).
When you talk about initializing in a case structure, does this case structure go outside the while loop? I am having troulbe understanding how to do the case structure when the true/false is dependent on calculations within the while loop.
07-02-2013 08:42 AM
The case structure is inside the while loop. This is somewhat like the structure used for state machines. Look at the attached VI. I did not test it.
You generally should avoid buiding an array inside a loop as it will eventually cause memory allocation problems (= program crash!). It is better to allocate an array as large or larger than the maximum you expect to use outside the loop and use Replace Array Subset inside the loop.
Lynn
07-02-2013 09:22 AM
Just use index array and the index will be i+ start value (easy). Once you determine your starting point (first positive freqeuncy as you said) wire this value inside the loop and add it to i.
07-03-2013 11:11 AM
Thank you very much! That did the trick.