LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read 1D waveform array from binary file

Hi all,

I have a 1D waveform (DBL) array stored as a binary file.  (It really is an array of four waveform elements from four channels but repeatedly appended).  My problem is trying to read the waveform array.

I can only get the first 4 elements out - the rest of the file seems to get lost. 

Please can someone help? Thanks.

Pauline

PS: I've attached my binary waveform file and the vi.
0 Kudos
Message 1 of 10
(5,116 Views)
I would recommend using the Write Waveforms to File.vi and then read them back using the Read Waveform from File.vi in a loop.
0 Kudos
Message 2 of 10
(5,089 Views)

Hi Pauline

When you write a waveform, or an array of waveforms, using Write Waveform to File.vi, the data is saved as a record. Each write creates a new record that can either be appended to the file or replace the existing data in the file. If you choose to append to the existing file, each write will create a new record. Read Waveform from File.vi can only read out one record at a time. You can combine the waveforms together in LabVIEW using Append Waveforms.vi so that you write all of the data in one record. This can be read out as a single waveform (or array of waveforms). Or you can read out all of the records one by one and combine the waveforms afterwards. The offset input in Read Waveform from File.vi specifies which record in the file that you want to read.

Hope this helps, please do not hesitate to reply to this thread if you encounter any more problems

Kind Regards

YatinM
NIUK
Applications Engineer

 

0 Kudos
Message 3 of 10
(5,058 Views)
Hi Yatin and Bill,

Thanks for your replies.  The reason I'm not using Write Waveform to File is because I'm writing out the waveform array at 250Hz and opening the file each time takes up too much time.  Appending it directly to a binary file is the quickest way I know.

I've figured out how to read the binary file and append the individual waveform records.  It required me to know the waveform structure (t0,dt, amplitude array).  As I'm using the waveform (DBL), I know the size of the amplitude array (# of elements * 8bytes).  The size of everything else in the waveform structure I worked out (by trial and error) to be 166bytes.  Could someone explain why this is?

Thanks,
Pauline
0 Kudos
Message 4 of 10
(5,050 Views)
hi, Pauline
 
could you attach your vi as an example? I am having the same problem as yours.
 
thanks
 
Rock
0 Kudos
Message 5 of 10
(4,969 Views)
Hi lyrock,

I gave up writing out my own waveform array to binary file - it's too difficult trying to read the binary file later because you need to know the size of each waveform yArray size and how many repetitions to append the array waveform.  This is almost impossible to track in my case.  Try using the TDMS file format - that worked like a charm and is extremely time-efficient.  Try it and let me know if you need more help.
0 Kudos
Message 6 of 10
(4,958 Views)
hi, Pauline
 
I read some note about the TDMS file format. But it is available only in V8.20, unfortunately, what I have is V7.1.
 
Anyway, thanks for your reply.
0 Kudos
Message 7 of 10
(4,948 Views)
Hi Rock,

Sorry about that.  If you want to post your code, I'm happy to take a look at it and offer some suggestions if I can.

Pauline
0 Kudos
Message 8 of 10
(4,942 Views)

hi, Pauline

I attached the LabVIEW file for data collection & binary data file. (only 1 Channel right now, but actually it will be multi-channel for my case)

What I want to do is to read the waveform from the saved binary data file, and do post-processing, like FFT, intergration... (I don't want to process data during collection) 

It sames simple to read the Y data. But I also got confused about how to get the waveform data out directly (Y, dt, t0), which will make the post-processing much easier.

Thanks

Rock

0 Kudos
Message 9 of 10
(4,927 Views)
Hi Rock,

Sorry for taking so long to reply - I've been busy.  You'll need to take note of the value of "number of samples per channel".  It would be simplest not to change this value during the acuqisition.  Your sample rate is constant since you cannot change this on-the-fly.  The size of each y-array is then "number of samples per channel" times 8 bytes (for a DBL).  I've worked out the header (t0 and dt) of the waveform type to be 166bytes but you should be able to find this header size if you know the size of your binary file, y-array size and the number of loops N your TestAcquisition program has gone through. 

Now, when it comes to using "Read from binary file", you'll need to tell it the "count" and wire a Waveform (DBL) constant to the "data type".  This "count" is [#channels x N (defined earlier)], or the total file size divided by (header+y-array size).  The output from this is a 1D waveform (array size should be 4channels x N; ch1,ch2,ch2,ch4,ch1,ch2,ch3,ch4...) which you'll need concatenate repeatedly using "Append Waveforms" to produce your final 1D waveform (of size 4).

I hope this is clear.  😃

pauline
0 Kudos
Message 10 of 10
(4,878 Views)