How to use the read_float_binary.m function

Hello,

I am in deep deep trouble. And it would be really great if somebody come
up
with any sort of help.

I am trying to collect the raw data using USRP2. I used the
gr_file_sink(itemsize, “filename”) for this. The “filename” is a binary
file
and so it cant be seen/open. I googled in the internet to find a way of
converting the binary file to something else. I found that there is one
thing named read_float_binary.m and read_complex_binary.m to convert the
data into a matlab file. This function is written in C++. I realized
that I
have to use this function but dont know how to do it. Should I use this
function directly to the python program or in the gr_file_sink.cc
program.

It would be really helpful if somebody writes the exact command for
this.

This is really urgent and I will appreciate it very much if somebody
comes
forward.

Thank you

View this message in context:
http://old.nabble.com/How-to-use-the-read_float_binary.m-function-tp32729533p32729533.html
Sent from the GnuRadio mailing list archive at Nabble.com.

data into a matlab file. This function is written in C++. I realized that I
have to use this function but dont know how to do it. Should I use this
function directly to the python program or in the gr_file_sink.cc program.

It would be really helpful if somebody writes the exact command for this.

This is really urgent and I will appreciate it very much if somebody comes
forward.

Thank you
Those files (read_float_binary.m and read_complex_binary.m) are MATLAB
macros, intended to
be used directly by MatLab. If you don’t know how to use MatLab,
this is likely the wrong list
to get high-quality help in that direction. Just sayin’


Marcus L.
Principal Investigator
Shirleys Bay Radio Astronomy Consortium

On 10/27/2011 06:14 PM, hasanimam wrote:

will try to open it.
However, I was looking for some way to directly convert the file into .txt
or any other readable format using the python program.

see numpy.fromfile, use the type numpy.complex64

The data stored to file is just an array of std::complex or
std::complex

Hello Marcus,

I really appreciate your help.

Those files (read_float_binary.m and read_complex_binary.m) are MATLAB
macros, intended to be used directly by MatLab.

Did you mean that, the binary file which will be created by the
gr_file_sink, is needed Matlab to open?
Ok, then I will take the file to another PC where Matlab is installed
and
will try to open it.
However, I was looking for some way to directly convert the file into
.txt
or any other readable format using the python program.

Marcus D. Leech wrote:

and so it cant be seen/open. I googled in the internet to find a way of
This is really urgent and I will appreciate it very much if somebody

Discuss-gnuradio Info Page


View this message in context:
http://old.nabble.com/How-to-use-the-read_float_binary.m-function-tp32729533p32735431.html
Sent from the GnuRadio mailing list archive at Nabble.com.

However, I was looking for some way to directly convert the file into .txt
or any other readable format using the python program.
Ah, I got the impression you were looking for a quick way to read the
files into MatLab.

They’re native-binary floating-point data, either “float” or “complex
float”.

In Python there’s a plethora of ways of handling that, but numpy would
be the best bet, and I see that Josh
has already recommended numpy.fromfile.

For significant storage-size and performance reasons, the “file sink”
blocks in Gnu Radio store their data in the native
floating-point format. Although for low-speed data, one might
consider Josh’ new python-blocks stuff, which could
do conversions on-the-fly into a number of different formats,
including printable ones.


Marcus L.
Principal Investigator
Shirleys Bay Radio Astronomy Consortium

Well, I have been able to run the program somehow. The following code is
what
I used.

import numpy

numpy.fromfile(“observed_data”, dtype=float, count=-1, sep=‘’)

Now, the problem is that the file I am getting does not show anything. I
mean the characters in the file are still unreadable.

I want numpy to convert the binary file to a readable one.

Any idea?

hasanimam wrote:

However, it gives an error called "NameError: global name ‘numpy’ is not

On 10/27/2011 06:14 PM, hasanimam wrote:
and

up
thing named read_float_binary.m and read_complex_binary.m to convert
this.
to get high-quality help in that direction. Just sayin’
Discuss-gnuradio mailing list


Discuss-gnuradio mailing list
[email protected]
Discuss-gnuradio Info Page


View this message in context:
http://old.nabble.com/How-to-use-the-read_float_binary.m-function-tp32729533p32735603.html
Sent from the GnuRadio mailing list archive at Nabble.com.

Hello Josh,

Thank you. In fact I am a very newcomer to use gnuradio.
I tried to follow your advice.
I wrote the code in python like,
numpy.fromfile(observed_data, dtype=float, count=-1, sep=’’)

Here, observed_data is the file which is created using the gr_file_sink
command.
However, it gives an error called “NameError: global name ‘numpy’ is not
defined”.

Do you have any idea about it?

Thanks

On 27/10/11 10:09 PM, hasanimam wrote:

I want numpy to convert the binary file to a readable one.

Any idea?

numpy.fromfile returns an array of “floats” within Python. It doesn’t
convert your input file, merely
make it convenient to manipulate the contents as a Python array of
floats.

Once its in that format, you can use Python to format it for you:

thingy = numpy.fromfile(“observed_data”, dtype=float, count=-1, sep=‘’)

Thingy is now an array of floats. You might, for example:

file = open (“outputfile”, “w”)

for n in range(0,len(thingy)):
outstr = (“%f” % thingy[n]) + “\n”
file.write (outstr)

file.close()

But there are lots of other, likely more efficient ways to do that in
Python.


Principal Investigator
Shirleys Bay Radio Astronomy Consortium

On 10/27/2011 07:09 PM, hasanimam wrote:

Well, I have been able to run the program somehow. The following code is what
I used.

import numpy

numpy.fromfile(“observed_data”, dtype=float, count=-1, sep=’’)

See my previous email about the data type. I do not think you want to
parse the data as a float64/double. Right?

On 27/10/11 11:00 PM, hasanimam wrote:

file.close()

The output file does not contain anything. I have really no idea why these
things are happening.
I thought that using numpy.formfile, I will be able to read the converted
binary file…however…its not happening.

Am a little bit sad…

Is your input file non-zero length?

and since you’re using complex64, assuming you’ve read your file into
‘a’:

f = open(“outputfile”, “w”)
for n in range(0,len(a)):
x = str(a[n].real) + " " + str(a[n].imag)+ “\n”
f.write (x)

f.close()

Will produce a readable-text file for output.


Principal Investigator
Shirleys Bay Radio Astronomy Consortium

Still no ray of hope.

I am pasting the complete code here.


    collect_raw_data = gr.file_sink(self.fft_size, "observed_data")

    numpy.fromfile("observed_data", dtype=numpy.complex64, count=-1,

sep=‘’)
thingy = numpy.fromfile(“observed_data”, dtype=int, count=-1,
sep=‘’)

    file = open ("outputfile", "w")

    for n in range(0, len(thingy)):
        x = str(thingy[n].real) + " " + str(thingy[n].imag)+ "\n"
        file.write(x)

    file.close()

   self.connect(self.u, s2v, c2mag, collect_raw_data)

What do you think what should be the output of the above alogrithm.
I am getting two output files for this algorithm.
One is “observed_data” which contains some unreadable characters. I
think
this is a binary file. I have to convert this binary file to understand
the
raw data.
The other one is “output” which contains nothing. I guess this file
should
contain the converted data of “observed_data” file.

Still looking for some sort of help.

Thanks.

Marcus D. Leech wrote:

for n in range(0,len(a)):


Discuss-gnuradio mailing list
[email protected]
Discuss-gnuradio Info Page


View this message in context:
http://old.nabble.com/How-to-use-the-read_float_binary.m-function-tp32729533p32735809.html
Sent from the GnuRadio mailing list archive at Nabble.com.

To Josh and Marcus,

Well I tried all aspects.
Here is what I did,

a = numpy.fromfile(“observed_data”, dtype=numpy.complex64, count=-1,
sep=‘’)
file = open (“outputfile”, “w”)
for n in range(0,len(a)):
outstr = (“%f” % a[n]) + “\n”
file.write (outstr)

file.close()

The output file does not contain anything. I have really no idea why
these
things are happening.
I thought that using numpy.formfile, I will be able to read the
converted
binary file…however…its not happening.

Am a little bit sad…

Josh B.-2 wrote:

Hello,
and so it cant be seen/open. I googled in the internet to find a way
function directly to the python program or in the gr_file_sink.cc
Those files (read_float_binary.m and read_complex_binary.m) are
http://www.sbrac.org

University of Electro-Communication, Japan


Discuss-gnuradio mailing list
[email protected]
Discuss-gnuradio Info Page


View this message in context:
http://old.nabble.com/How-to-use-the-read_float_binary.m-function-tp32729533p32735733.html
Sent from the GnuRadio mailing list archive at Nabble.com.

On Thu, 2011-10-27 at 19:00 -0600, hasanimam wrote:

Hello,

I am in deep deep trouble. And it would be really great if somebody come up
with any sort of help.

Well, here is the code I cobbled together to do this. It is nothing
fancy.

  • Wayde

#!/usr/bin/env python

import sys, struct

if len(sys.argv) != 2: # Need to have one input data file
# Print out splash banner in case the filename
# isn’t entered correctly

  print
  print '   [gr_raw2num.py, Version 20100308 by J. Wayde Allen]'
  print
  print '   NAME:  gr_raw2num.py  '
  print
  print '   USAGE:  gr_raw2num.py filename'
  print
  print '   DESCRIPTION:'
  print
  print '   Converts raw complex float data to complex'

else:

myfile = sys.argv[1]
f = open(myfile, ‘rb’)
eof = False

while not eof:
try:
chunk = f.read(8)
a,b = struct.unpack(‘ff’,chunk)
value = complex(a,b)
print a, b
except:
eof = True

    thingy = numpy.fromfile("observed_data", dtype=int, count=-1,
   self.connect(self.u, s2v, c2mag, collect_raw_data)

Still looking for some sort of help.

Thanks.

The crucial item we were all missing was that you were trying to do this
inside a Gnu Radio flowgraph.

Let the flow-graph run, then use an independant Python program after
the fact
to convert your
data file.

From your code, it’s clear that you’re confused about how all this
works, and probably software-design
and programming in general. I suspect that you’re a student, and that
you have an overdue assignment
and you don’t even know where to start. From the code-segment you
provided, I’m guessing that your
programming and software design background is extremely limited.
While people on this list are
generally pretty generous with their time and knowledge, the
assumption is that our good will
won’t be abused. Using the people on this list as a means to complete
your academic assignments for
you is definitely an abuse of that good will.


Principal Investigator
Shirleys Bay Radio Astronomy Consortium

On Fri, Oct 28, 2011 at 08:06:40AM -0600, wallen wrote:

Well, here is the code I cobbled together to do this. It is nothing
fancy.

Though it can’t be adapted as easily to more sophisticated processing as
your python code, I often use this one-liner to do the same thing:

$ od -fvw8 filename