3

I have a binary file that contains several complex numbers of type complex64? (i.e. four bytes of type float for the real part and another four bytes for the imaginary part). The real and imaginary parts are multiplexed so that the real part is stored first and followed by the imaginary part.

5
  • Can you show a sample of what you have? Commented Jun 26, 2016 at 23:29
  • complex64 is a complex number represented by two 32-bit floats (real and imaginary components). Is it what you have in your file? Commented Jun 26, 2016 at 23:58
  • @Moses, I don't know if there is a way to upload here, but the complex values in the file have been written from a program called GNURadio, and the docs say that a binary file of complex numbers stores the real and imag parts as 32-bits floats (first element is the real and the second is the imag) I tried to read the file using the following command but I could not get the numbers that I was expecting: numpy.fromfile('file_name', dtype=complex) @Jacques, yes this is what I have. I was expecting [0, 2+j, -3.14-7.99j] but I get something like: [0 +7.81e-3j, -1.29e+5 +0j, 7.8e-3 -1.29e+5j] Commented Jun 27, 2016 at 6:09
  • The doc is here:nutaq.com/blog/gnu-radio-file-source-and-sink. Why don't you do numpy.fromfile('file_name', dtype=numpy.complex64)? Commented Jun 27, 2016 at 9:12
  • gnuradio.org/redmine/projects/gnuradio/wiki/… seems to indicate the same use as my comment above Commented Jun 27, 2016 at 11:24

1 Answer 1

2

I was able to reproduce the error you encounter by creating an array of complex64 from [0, 2+j, -3.14-7.99j], saving it to a file and reading it as Python built-in complex type.

The issue is that the built-in complex type has the size of a C double which, depending on your plateform, may differ from 32-bits (256 bits on my machine).

You must use numpy.fromfile('file_name', dtype=numpy.complex64) to read your file correctly, i.e. make sure the complex numbers are read as two 32-bits floating point numbers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.