LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Mean of collected samples over time

Hello,

 

I am currently running a modified Lock-In amplifier supplied from NI (http://sine.ni.com/devzone/cda/epd/p/id/4532) and I am trying to take a mean of the results. What i am trying to do is take 0.5 seconds of samples and then take a mean of those samples. Then i want to take a mean of the next 0.5 seconds of samples. I want to do this for ~1 minutes worth of samples (loop through 120 times) and at the same time write the mean and time to separate .csv files. Right now what is happening is the entire program is pausing for 0.5 seconds while i want the lock-in amplifier to be constantly running and storing 0.5 seconds worth of values.

 

Thank you.

0 Kudos
Message 1 of 8
(3,013 Views)

The problem is you are forcing your entire loop to wait with your "Time Delay" VI. Your loop cannot run again until everything in the loop as run, so everything is waiting for the "Time Delay" VI to finish.

 

What you are trying to do is best done in a Producer Consumer structure where you run your Lock-In amplifier code in one loop and pass data to another loop that processes the mean and writes the data to a file. You are experiencing the downsides of running two seperate processes in a single loop. One process must wait for the next process to complete before it can do its thing.

 

If you have not worked with a Producer Consumer architecture before, take a look at the templates included in Labview as well as some of their examples. I think it will make sense to you very quickly.

0 Kudos
Message 2 of 8
(2,997 Views)

I'm trying to get the producer consumer concept working but i'm struggling to send data for 0.5 seconds then mean it. What I think I can do is loop 120 times where i store data for 0.5 seconds and mean the values (use a sample length of 0 for point by point). Then on the next loop iteration I reinitialize the mean and do the 0.5 seconds of data again. I have tried with a very simple program but i do not know how to store data for 0.5 seconds.

0 Kudos
Message 3 of 8
(2,952 Views)

Consider how your VI works. The Producer loop generates and Enqueues one data point every 100 ms or ten samples per second. The Consumer loop runs 120 iterations with the time limited by waiting for data to appear in the queue. So (assuming that the stop button is not pressed) the program will run for 12 seconds. After that the consumer loop stops and the Beep sounds. The Producer loop continues to run. Eventually the queue will overflow and generate an error although the loop will continue to run until LV crashes or the user presses stop.  You should stay with the two while loop implementation. Also, stacked sequence structures (and sequence structures in general) should be avoided.  The Beep.vi can be enclosed in a single frame sequence with one of the mean arrays wired through it to force the execution after the mean calculations.

 

It is not completely clear but it seems you expect to get a set of samples from your lock-in every 0.5 second. Your lock-in VI has default values of 10000 samples per second and 1024 samples per channel (per read).  With those settings you cannot get data at exactly half-second intervals. Try setting the number of samples per channel to one half the sample rate = 5000 samples. Then every time you Read from the DAQ device you get exactly 0.5 seconds worth of samples. Use Array Index to get each channel or Autoindex in a for loop. Wire that to the standard (not Point by Point) Mean.vi. The output is then exactly the mean of 0.5 seconds of data for that channel.

 

Lynn

0 Kudos
Message 4 of 8
(2,927 Views)

I see what you're saying. However I believe that the Lock-In Amplifier (LIA) takes the number of samples (going with your suggestion N=5000) and uses those to convert to a single output value (I only want to deal with R and R2) which I want to find the mean of. Your suggestion would work well if I wanted the mean of the input samples before they go through the LIA but I want to mean the output.

 

I might be misunderstanding you but I modified my original program to go along with your suggestion so hopefully you can see the problem. I was looking into a master/slave implementation which I created a simple program to show my idea. I just need to somehow clear the array after the timer resets.

Download All
0 Kudos
Message 5 of 8
(2,901 Views)

I can't seem to edit my post but it looks my like Dual Lock-In was not saved when I changed it.

0 Kudos
Message 6 of 8
(2,873 Views)

johndoe,

 

What do you mean by that?

Mason M
Applications Engineer
National Instruments
0 Kudos
Message 7 of 8
(2,860 Views)

I've been working on my idea and I think this works for my application.

0 Kudos
Message 8 of 8
(2,849 Views)