From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Can't log data into multiple column *.csv format

Solved!
Go to solution

So I have been trying to output my logging data from DAQ system into a csv file.

For some reason, Labview put all data into 1 column instead of 3. Any idea where I went wrong?

Also, you can see from the VI that I'm trying to log the time stamp, but to be honest I'm not sure how to do so. Any suggestion?

0 Kudos
Message 1 of 12
(2,825 Views)

Hi Anh,

 

Any suggestion?

check.png

Saving timestamp with two other data items into a CSV file, consisting of 3 columns…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 12
(2,800 Views)

So I figured out where I was wrong (I transposed the array!). But now I also want to get the time data from the waveform.

With the setup below, after getting the dynamic data, I converted it into 2d array. By doing so, I get the analog value of my 2 signal. However, I did not get the time data. My sampling rate is 20k.

Is there any way to add the time into my csv file? I would like the time reference to the start of the sampling, not the global time.

Capture.JPG

0 Kudos
Message 3 of 12
(2,758 Views)

Hi Anh,

 

Is there any way to add the time into my csv file?

Yes, sure.

(Most often things get clearer and easier once you get rid of ExpressVIs…)

 

I would like the time reference to the start of the sampling, not the global time.

Add two more items to your "header": start time and samplerate…

Add one more column to your data: sample index divided by samplerate…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 4 of 12
(2,752 Views)

Thanks for the code, now we can see what you did and make some possibly-helpful suggestions.

  1. Have you thought about how you want to represent multiple samplings (the While loop) from multiple channels (the split Dynamic Data Wire) representing multiple samples (the Dreaded DAQ Assistant), namely an N by M by K (3-D) data arrangement in a 2-D (delimited spreadsheet) format?
  2. I notice (by examining your code) that you sort-of solve this issue by concatenating the sampling interval (dt) and the two channels of sampled data into a 1D array.  Personally, I think this will make it challenging to examine your data, as you will see (in a single row, or possibly in a single column) a time interval (possibly 0.001) and then 2*N samples (where N is the number of points you are sampling each time through the loop), with no clear way (except to figure out where halfway down the list of number is located) to compare Channel 1 data with Channel 2.  A more "natural" way to do this would be a 2D array, all of Channel 1 "on top of" (or "to the left of") all of Channel 2, but then what happens when you take more data in the While loop?
  3. Write Delimited Spreasheets, when called multiple times, appends to the end of the file.  This means that any new data will appear (spatially) "below" the existing data.  Your code includes the "Transpose the (2D) data" which turns your 1D "row vector" into a 1D "column vector".  Saving a row of 2N+1 (2 channels + dt) elements M times will result in a files having M * (2N+1) rows and 1 column.  This is probably not what you want, but definitely is what you programmed.
  4. Write a small Demo routine that uses random numbers or other "known quantities" and test your algorithms yourself to find your own mistakes.

Here is a Snippet generating 2 small (20-sample) Waveforms, concatenating them (or not -- do test the more-natural "Build Array without Concatenation") that can easily be written and tested.  Note the use of a Shift register to (correctly) call Write Delimited Spreadsheet, specifying the File Name only on the First Call.Data Logger TestData Logger Test

Bob Schor 

 

 

0 Kudos
Message 5 of 12
(2,744 Views)

Hm.

So how accurate is that if I just assume that with 20kSample/s, the relative time stamp of those data sampled in 1 second is map out evenly throughout that 1 second period?

With the time stamp coming from the Labview express VI, is that the same way to get the time, or is the time stamp something sent along with the analog reading from the DAQ device?

0 Kudos
Message 6 of 12
(2,742 Views)

Hi Anh,

 

So how accurate is that if I just assume that with 20kSample/s, the relative time stamp of those data sampled in 1 second is map out evenly throughout that 1 second period?

As long as you use the sample clock of your DAQ device (which you should for a samplerate of 20kS/s) it is accurate as the specsheet of that DAQ device promises. (Atleast it is much more accurate than any timing provided by WindowsOS.)

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 7 of 12
(2,739 Views)

Does that mean I can just add my own timing data, without getting the actual timing data of DAQ?

0 Kudos
Message 8 of 12
(2,735 Views)

Hi Anh,

 

for "short" measurements it is safe to assume an accurate sample rate. For "longer" measurements you might use an external (even more accurate) timing source (depending on your requirements!).

 

As said before: read the specs of your DAQ device to learn about its capabilities regarding sample clock accuracy…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 9 of 12
(2,725 Views)

That's a really nice reply, Bob!

For some reason, I didn't see yours until now. 

I see that you have found my mistake, which I ultimately found it through exactly what you suggested too.

So here's how I want to represent my data:

3 columns: Time, Voltage1, Voltage2

The time column is the relative time, which means it should be 0 at the first time interval. The unit of time should be us because I'm sampling at 20kHz.

And you are right about all data in 1 column, that's not what I want! But I have no idea how to, after converting the dynamic data to 2D array, to add time as another column to my spreadsheet. I find this is extremely difficult because I think the data I get from DAQ Assistant is 2 array of data in one time loop, while dt is a single data point. So I guess I'm not sure how to get another time column that supposedly comes with the data from the DAQ device. Any advice Bob?

Thanks again.

0 Kudos
Message 10 of 12
(2,710 Views)