Dear All. We use the attached "write_complex_binary.m" funtion in matlab to write complex numbers into a binary file. The format used is the IEEE floating point with big-endian byte ordering. And use the attached "read_complex_binary.m" function to read back the complex numbers from the saved binary file. However, I just dont seem to be able to read the generated binary file in labview. I tried using the "Read from binary file" block with big-endian byte ordering with no success. I am sure its my lack of knowledge of how the labview block works is the reason. I also can't seem to find any helpful resources to that matter. I was hoping someone could kindly help with this or give me some directions to work with.
Thank you loads in advance. Please find attached the two matlab functions zipped. Kind regards.
Solved! Go to Solution.
Be a Scientist -- do an Experiment.
I presume you know Matlab and can generate a little complex data and use the Matlab function to write it to a file. You can also look at the Matlab function that you posted -- you'll see that Matlab takes the array of complex apart into 2-D array of [real, imaginary], which are written as 32-bit floats, which LabVIEW calls "Sgl".
So now you know you need to read an array of Sgls, and figure out how to put it together again into an array of Complex.
When I did this experiment, I made the Real part of the (Matlab) Complex data [1, 2, 3, 4], and the Imaginary [5, 6, 7, 8]. If you are curious, you can write these data out in Matlab with your Complex Write function, then read them back as a simple Array of Dbl to see how they are ordered (there are two possibilities -- [1, 2, 3, 4, 5, 6, 7, 8], if written "All Reals, All Imaginaries", or [1, 5, 2, 6, 3, 7, 4, 8], if "Real, Imaginary pairs"].
Now you know (from the Matlab function) that the data are an array of Sgl (to LabVIEW). I presume you know how to write the three-function routine that will open the file, read the entire file into an Array of Sgl, and close the file. Do this experiment and see if you see meaningful numbers. The "catch" is the byte-ordering of the data -- does Matlab use the same byte ordering as LabVIEW? [Hint -- if you see numbers from 1 to 8 in either of the above orders, you have the byte-ordering correct, and if not, try another byte ordering for the LabVIEW Read Binary function].
OK, now you have your Sgl Array of 8 numbers, and want to convert it to an array of 4 Complex, [1+5i, 2+6i, 3+7i, 4+i8]. Once you have figured out how to do this, your problem is solved.
To help yourself when you actually go to use this code, write it as a sub-VI whose input is the Path to the file you want to read and whose output is the Array of CSG contained in the file. My LabVIEW routine had 8 LabVIEW functions -- three for File I/O, and 5 for converting the 1D Array of Sgl into a 1D Array of CSG. No loops were needed. Give it a try -- you can test it against the Matlab Data File you used for your Experiment (see above) and if you get the expected answer, you've written correct code.
Thank you Bob. I have been doing exactly what you have been saying since yesterday. Except the "CATCH". I did not fiddle with the byte ordering. Now interestingly the byte ordering is all upside down. Kind regards.
Yep, Matlab (in their Wisdom) does not use the "expected" Byte ordering ... Moral of the Story -- Use LabVIEW.
Bob (former Matlab Guru) Schor