LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Writing Binary Files for Offline Sorter (16 Bit)

I am currently having issues using the Write to Binary Function to create files to be used with Offline Sorter. From my understanding, Labview is currently writing these numbers in base 256, meaning that a 16 bit number consists of two "digits" from 0 to 255. The problem is that when this is loaded into Offline Sorter, the program doesn't recognize the two digits as being part of the same number and reads them separately. I am able to use Matlab to convert the data into a format that works, but this takes several hours to complete with the file sizes I am working with. Moving to writing an 8-bit number is also not an option due to the loss of resolution. Is there a way to get Labview to write this binary value as a single binary "digit" between 0 and 65535 instead of breaking it up?

0 Kudos
Message 1 of 18
(3,672 Views)

A flat binary file has no delimiters, so your first statement is certainly incorrect. You can write any kind of binary file with any kind of byte order directly in LabVIEW, you are just doing it wrong.

 

Can you show us how you are writing the file and what your matlab program does to straighten out your LabVIEW errors. There should be a 30 second fix for that. 😄

 

Also please attach one of your LabVIEW generated files as well as its matlab corrected version. Thanks!

 

What is your LabVIEW version?

0 Kudos
Message 2 of 18
(3,665 Views)

I don't have access to the files right now, but the gist of the current configuration can be seen in the screen shot below. The files we will be ending up trying to write are a 2D array instead of a double.

 

The current Matlab fix is just writing to text instead, reading that into Matlab, and using Matlab to rewrite it as a binary file. With a binary file the fix would be reading it in and creating a new array by summing 256*(first value of pair) + second value of pair.

0 Kudos
Message 3 of 18
(3,655 Views)

You have something completely mixed up and we are not gettting the entire story. A binary file written like that does not have information on size and number of dimensions.

 

Can you show us the matlab code that writes the file? As said, an actual correct output file would be even better.

 

Is this under windows?

0 Kudos
Message 4 of 18
(3,641 Views)

I also don't know what an "offline sorter" is. Is there a manual that describes the expected file structure?

0 Kudos
Message 5 of 18
(3,636 Views)

Sorry for the delay in reply.

 

To write the file in Matlab, I am just using Fwrite, which creates a file that can be appropriately loaded by Offline Sorter.

 

Offline Sorter is a program used to sort neural recording spikes. It simply looks for 16 bit binary files, but when I use the following sequence of commands

 

fid = fopen ('filename');

a= fread(fid);

 

it comes out as described in my original post (pairs of 8 bit numbers).

 

I am unable to attach the binary files as this forum does not support uploading .bin files, which is the extension compatible with OLS that I am using to write to.

0 Kudos
Message 6 of 18
(3,605 Views)
Place a good (matlab generated) and bad (LabVIEW generated) in A zip file and attach it. Make sure to tell us what's what. 😉
0 Kudos
Message 7 of 18
(3,601 Views)

Here you go. Set the program to run the loop 20 times and just added a 2nd file writing to text in the previous program (same lay out with Write to Text instead of Write to Binary), used b=textread('name') to read it into Matlab then fopen('newname','wb') and fwrite(fid,b) to write it. The good file has no second dimension. I can try it again with larger numbers to see what happens once the value to write to text exceeds 255, but I don't think it changes.

 

Edit: Tried it again with larger numbers, caps at 255 with no overflow. Unless you can see something I specifically messed up, the issue is probably somewhere with how Matlab and OLS handle binary, not Labview. I'll have to figure it out with those programs. Thanks for your help.

0 Kudos
Message 8 of 18
(3,589 Views)

The bad file has x00 interlaced. You are probably writing with the wrong representation. You would get the good result if you would convert to U8 in the above shown code. Try it!

0 Kudos
Message 9 of 18
(3,584 Views)

Here's the content of your two files in hex display. See what I mean?

 

 

0 Kudos
Message 10 of 18
(3,576 Views)