LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to do batch measurement every n seconds?

Hi,

Here are what I want to do:
1. Measure data from multiple channels;
2. For every m data points, calculate mean etc.;
3. Save the mean and the corresponding time;
4. Wait n seconds, measure another m data points.

The attached is my vi file. My question is:
If the waiting time is set as 0, the time interval between every saving is 8 seconds. Now the waiting time is set as 10 seconds. Is the time interval between saving is 10 seconds or 18 seconds (measurement time + waiting time)? I checked the data file, and the time interval is 10 seconds. I am confused. How can I set the waiting time between every batch measurement?

Also, is there any suggestion on saving data? Because I want to save the date and time when the mean is calculated, I converted the mean values to strings, and also writed them to a text file. Is it a good way to deal with a large amount of data? I will use this file to continuously measure for about 1 or 2 days.

Thanks,
Bei
0 Kudos
Message 1 of 9
(4,550 Views)
I would lose the flat sequence structure first of all and let the data flow determine execution. You should also convert your while loop to a timed loop. Your user provided wait time then feeds the dT of the timed loop. I would also suggest you try using TDM as your data storage format (assuming you're using LV 8.x). It's compact since it's in binary and is good for long measurement cycles, gives you easy timestamp capability and can be read back easily with LabVIEW or even read directly into Excel with the free plug-in.

Your data flow inside the loop (without the sequence) should be:

1) Get your measurements
2) Do the mean calculation
3) Write measurements to file (this would include the timestamping)
4) Repeat until loop termination criteria is met

Let the timed while loop take care of your "wait n seconds" requirement.

You can find a lot of good information on TDM on the NI website.

Message Edited by Bill@NGC on 07-24-2007 10:24 PM

Message 2 of 9
(4,546 Views)
The DAQmx Read you have inside a for loop is very strange. If you want to use hardware timing and change the number of samples, wire the samples per measurement control to the number of samples per channel input of DAQmx Read. The whole for loop and array manipulation goes away. You would also have reliable and consistent sample rates instead of doing it in sofiware like you are doing now.
Message 3 of 9
(4,526 Views)
Hi Bill,

Thanks for the suggestions. I deleted the flat sequence structure, and changed the while loop to the timed loop. I am working on the TDM.

By the way, is TDM better than Write to Text File from the viewpoint of precision? It seems I cannot control the precision or format of the data for Write to Text File.

Thanks,
Bei
0 Kudos
Message 4 of 9
(4,507 Views)

You have as much control over the precision as you want. You are not specifying any precision with your format to string.

p.s If you don't eliminate that for loop with the 1 sample like I mentioned, you are essentially using software timed acquistion.

Message 5 of 9
(4,502 Views)
Here's a picture.
Message 6 of 9
(4,497 Views)
Hi, Dennis,

Thanks for the example. I also changed the block diagram for sampling. Please see the attached file. Is it better now?

Thanks,
Bei
0 Kudos
Message 7 of 9
(4,494 Views)
You can simplify it even more and eliminate the 'channels' control. The number of channels is defined by the physical channels control that you have. If the user uses a number in the channels control that is different than the number of channels in the physical channels list, you could end up with some strange results. The DAQmx Read returns a 2D array that has x number of channels as columns and the number of samples is the number of rows. You can transpose this and just wire this to a for loop where you calculate the mean and standard deviation. The output of this will create a 2D array that you wire directly to a Write to Spreadsheet File function. You can also choose to return the data from the DAQmx Read as a 1D array of Waveform data type. The number of elements in this array will equal the number of channels. The waveform data type also includes a time stamp. So instead of calling the Get Date/Time, you just extract if from the waveform. The picture below should get you started.
Message 8 of 9
(4,489 Views)
Hi, Dennis,

Thanks again for the examples.

About the output of the DAQmx Read, I found that it is a 2D array (column: no. of samples, row: no. of channels). So I don't need to do transpose before calculating the mean, etc.

Bei
0 Kudos
Message 9 of 9
(4,481 Views)