08-07-2009 02:37 PM
Hello,
I am measuring signal from DAQ assistant and I am taking average of all the data I get over one cycle,for that I am using a while loop and a shift register and after the while loop completes running i divided the output of the shift register by i of the while loop +1.
But I am getting the following error :"Error in add:Waveform has different dt".
Can anyone please help me how I can I get rid of this error?
Thanks
Solved! Go to Solution.
08-07-2009 04:21 PM - edited 08-07-2009 04:22 PM
You have to initialize the shift register with a waveform that has a dt that is the same as the waveforms you are getting with the DAQ Assistant. For example:
That said, I am HIGHLY SUSPICIOUS of your use of local variables. To the point where they don't make sense. The way you've used "Current Cycle Number" implies that it's being changed someplace else. This smells of a race condition to me.
08-07-2009 05:13 PM
Thanks for your reply.Yes my current cycle number variable is changing in another parallel loop in the same VI when the axis completes one cycle of motion.So far I only knew that using global or shared variable has the risk of race condition.Can you make the point more clear?
Also I dont know the dt for my signal from DAQ asssiatant.I tried to use Get Waveform Attribute VI from the waveform palette but it does not accept dynamic data type.How can I know the dt of my signal?
Aru
08-07-2009 05:35 PM
Oh that was a stupid question,inverse of the sampling rate of my DAQ assistant express VI is the dt.
08-07-2009 07:03 PM
08-07-2009 07:20 PM
You need to do someting similar to this.
Here is a picture of the old example using a FOR loop. Modify as needed.
08-07-2009 07:26 PM
poorinLabVIEW wrote:Yes my current cycle number variable is changing in another parallel loop in the same VI when the axis completes one cycle of motion.So far I only knew that using global or shared variable has the risk of race condition.Can you make the point more clear?
This is a prototypical race condition and makes no sense whatsoever. It is highly likely that the two local variable instances are read within nanoseconds (one right before the loop starts and one right after to loop has started. There is a very high possibility that they return the same value and thus the loop will stop after one iteration, messing with any attempts at averaging.
Why don't you attach some actual code instead of images?
08-07-2009 10:38 PM
Thanks,it worked but I am not sure if my code does what I want it to do.I want to get the mean of all the data collected in one cycle (as long as current cycle numberbefore iteration =current cycle number )and have it plotted against the cycle number.My buffer size for data acquisition is 100 and sampling rate is 1KHz. I am simply dividing the sum of all data by the total number of iteration which I am not sure if the same as total number of samples in one cycle.
You used an uninitialized shift register which I didnt understand why.
I am using stop if true for while loop stop terminal so it will only stop when the value of current cycle number is no longer equal to the current value of current cycle number.I would really appreciate any c omments regrading the possibility of contamination with race condition after taking a look at my code.
08-08-2009 02:10 AM
Don't overcomplicate things. Keep the "add" node and get rid of the math express VI.
You want to add waveforms, so at the first iteration (i=0), you simply place the current waveform into the shift register. Since we ignore the value from the shift register, it does not matter if we initialize or not. Only starting with the second iteration (i=1..) we add the new waveforms to whatever is in the shift register.
(Your method with the initialized shift register will not work, because even though the dt is correct, the initial data in the shift register has no values (zero elements), so you cannot add. Additions are element by element, so the shorter array wins.)
poorinLabVIEW wrote:My buffer size for data acquisition is 100 and sampling rate is 1KHz. I am simply dividing the sum of all data by the total number of iteration which I am not sure if the same as total number of samples in one cycle.
Sorry, I don't have any DAQ tools installed, so I cannot really inspect your code. Still, Your sentence above makes little sense to me.
08-08-2009 09:08 AM
altenbach wrote:(Your method with the initialized shift register will not work, because even though the dt is correct, the initial data in the shift register has no values (zero elements), so you cannot add. Additions are element by element, so the shorter array wins.)
You're right. I neglected to consider the array portion of the waveform, and was only looking at the error's cause, which was the mismatch in dt.