LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Need advise for processing DAQmx waveform array

Hello All,

I am using following code to continuously acquire data from 2 channels, then export to a text file for analysis with Execel or Origin. The data file should contain four columns:

t1   Y1    t2   Y2
........................
........................
.........................:

I know it is convenient to use Write Measurement File express VI, but since this express VI open and close file in each loop execution, I prefer to use low-level File I/O functions to save computer resources (I need to reserve resources for image acquisition and analyses).

The following attached VI just show the overall frame of the code, but is not executable now. I hope to get some suggestions from this forum to finish it.



Here, I have two main questions, thank you in advance if you can provide hints to any of them.

(1) How to get correct t0 and dt values for the waveform data

 I am using 25Hz pulse signal to externally trigger DAQmx  through PFI0.  I set 100Hz for the rate input of the DAQmx timing VI  since  LabVIEW help  says "If you use an external source for the Sample Clock, set this input to the maximum expected rate of that clock. " .

 When I use Write Measurement File express VI,  I found in the resulting text file, the dt is 0.01 instead of 0.04, i.e., the value of dt in the waveform data is not determined by external PFI0 signal, but by the rate input for the DAQmx timing VI.  Also, I found t0 does not always start from  zero.  However, from the display of data plot, I am sure the acquisition is at 25Hz.

Some people in this forum ever told me to use Get Waveform Component and Build waveform functions to manually rebuild the waveform data in order to get correct t0 and dt. I tried and no luck to succeed.  Anyone can give me more detailed hints?


(2) How to write data of 'NChan NSample' at one time in a loop

I have two channel DAQmx, and for each channel there are several data points.  I plan to use following method to export data:

Suppose in one loop DAQmx Read VI read 10 samples from each channel, so I assume I will get four arrays of 10 elements:
t_channel_1, Y_channel_1, t_channel_2, Y_channel_2.

Then I use a loop structure of N=10 to concatenate t1, tab,Y1,tab, t2,tab, Y2,return in 'element by element' mode, i.e., do 10 times of string concatenate and write to text file.

I don't know whether above method is effective. Anyone can advise a better one?


(3) Convert from timestamp to elapsed time in milisecond


In the final text file, the time column should be the values of elapsed time in milisecond since the start of acquisition. So, I think I need to get the timestamp of the first data point so that for later data points I can use Elapsed Time express VI  to extract elapsed time in milisecond. However, I don't know how to get the timestamp at the starting of acquisition. Please advise if you know it.

Sincerely,
Dejun

Message Edited by Dejun on 08-30-2007 10:34 AM

Download All
0 Kudos
Message 1 of 10
(3,596 Views)
Just an idea comes to my mind:

For the DAQmx Read VI, if I use NChan 1Sample instead of NChan NSample, the data analysis and export might be easier.

However, since the NChan NSample mode read all data points available in the buffer in each loop, it may be more effective and less computer resource consumption than the mode of NChan 1Sample?

Do you think it is wise to switch to NChan 1Sample?


Message Edited by Dejun on 08-30-2007 10:50 AM

0 Kudos
Message 2 of 10
(3,584 Views)
One thing I can see right away is that you have the DAQmx Start function before the DAQmx Read function.  I think you shoud move the Read to before the Start function, both outside the loop.  Inside the loop put a DAQmx Wait Until Done function.  This may or may not fix the dt problem.  The timestamp of the first aquisition should be t0 of the first waveform.  You could use a case structure.  Wire the loop iteration counter i into an =0 function.  Wire that output to the case structure.  In the True case (i=0), store t0 into an indicator.  In the False case, do nothing.
- tbob

Inventor of the WORM Global
0 Kudos
Message 3 of 10
(3,578 Views)

For continuous acquisition, I saw all NI examples put DAQmx Read VI within loop. Also, NI manual recommends putting read vi within loop for continuous acquisition.

Put DAQmx Start VI before loop, letting the DAQ board begin to acquire data and put to memory buffer. Then use DAQmx Read VI within loop to continuously retrieve data from buffer. This is why put start vi before loop, and put read vi within loop. This is what I imagin for how continuous acquisition  works. Also, looks like this is a template for all NI DAQmx continuous acquisition example.

Message Edited by Dejun on 08-30-2007 11:54 AM

0 Kudos
Message 4 of 10
(3,570 Views)
Sorry,, I was looking at the wrong example.  Yes, the read should be in the loop for continuous read.
- tbob

Inventor of the WORM Global
0 Kudos
Message 5 of 10
(3,562 Views)


@Dejun wrote:

(1) How to get correct t0 and dt values for the waveform data

 I am using 25Hz pulse signal to externally trigger DAQmx  through PFI0.  I set 100Hz for the rate input of the DAQmx timing VI  since  LabVIEW help  says "If you use an external source for the Sample Clock, set this input to the maximum expected rate of that clock. " .


You say you are using an external 25Hz pulse signal.  But your time source is sample clock, and its set for 25Hz.  1/25Hz is .04 sec.  Which is what you are getting as dt.  I don't see your problem.  I don't see where you say you are setting a 100Hz rate.

Message Edited by Ravens Fan on 08-30-2007 11:26 PM

0 Kudos
Message 6 of 10
(3,549 Views)

Ravens Fan:

Read his post again:

"I am using 25Hz pulse signal to externally trigger DAQmx  through PFI0.  I set 100Hz for the rate input of the DAQmx timing VI  since  LabVIEW help  says "If you use an external source for the Sample Clock, set this input to the maximum expected rate of that clock. " .

 When I use Write Measurement File express VI,  I found in the resulting text file, the dt is 0.01 instead of 0.04, i.e., the value of dt in the waveform data is not determined by external PFI0 signal, but by the rate input for the DAQmx timing VI.  Also, I found t0 does not always start from  zero.  However, from the display of data plot, I am sure the acquisition is at 25Hz."

 

He says in the 1st paragraph that he sets theDAQmx timing to 100Hz because that is his maximum expected clock rate.  In the 2nd paragraph he says that in his measurement file dt is 0.01 instead of 0.04.  This indicates that the dt value is determined by the DAQmx timing rate, not the PFI0 clock rate.  I am thinking that he should set the DAQmx timing to match the PFI0 timing, 25Hz.

Maybe this would work.

- tbob

Inventor of the WORM Global
0 Kudos
Message 7 of 10
(3,534 Views)


@tbob wrote:

Ravens Fan:

Read his post again:

"I am using 25Hz pulse signal to externally trigger DAQmx  through PFI0.  I set 100Hz for the rate input of the DAQmx timing VI  since  LabVIEW help  says "If you use an external source for the Sample Clock, set this input to the maximum expected rate of that clock. " .

 When I use Write Measurement File express VI,  I found in the resulting text file, the dt is 0.01 instead of 0.04, i.e., the value of dt in the waveform data is not determined by external PFI0 signal, but by the rate input for the DAQmx timing VI.  Also, I found t0 does not always start from  zero.  However, from the display of data plot, I am sure the acquisition is at 25Hz."

 

He says in the 1st paragraph that he sets theDAQmx timing to 100Hz because that is his maximum expected clock rate.  In the 2nd paragraph he says that in his measurement file dt is 0.01 instead of 0.04.  This indicates that the dt value is determined by the DAQmx timing rate, not the PFI0 clock rate.  I am thinking that he should set the DAQmx timing to match the PFI0 timing, 25Hz.

Maybe this would work.



You're right, I did misread what he said. But, I still have questions about what he said.  " I set 100Hz for the rate input of the DAQmx timing VI  ".  The code shows a rate input of 25 to the timing VI.  And nowhere else do I see a setting of 100Hz.  I ran his code (used a simulated device) and put an indicator on the to dt's in the clusters.  The came up as .04 which is what i would expect.  It is hard to comment what is going on in the file since there is nothing being send to the write text file VI.

Message Edited by Ravens Fan on 08-31-2007 12:18 PM

0 Kudos
Message 8 of 10
(3,533 Views)
You should not have a 10 ms Wait Until Next Multiple.vi in your loop.  The DAQmx Read.vi blocks until it reads the number of samples specified by "number of samples per channel".  There are some good examples in the example finder that show acquiring data and logging using TDMS files (LabVIEW 8.x).

I hope this helps!
0 Kudos
Message 9 of 10
(3,515 Views)
Sorry, I attached wrong code, causing misunderstanding of my questions.

The rate input of the DAQmx timing VI is 100HZ, and the timing source input is PFI0.




Message Edited by Dejun on 08-31-2007 03:51 PM

Download All
0 Kudos
Message 10 of 10
(3,502 Views)