How to edit the file generated by file sink of GNU Radio?

时光怂恿深爱的人放手 提交于 2019-12-23 03:42:20

问题


I find that the file generated by file sink block is binary format, which can not edit by gedit under linux or something else, So how can i edit the file?

I send a dat file contains "hello world" and I want to recieve a file contains "hello world"


回答1:


This is asked very often. So here's a link to the FAQ and the excerpt:

All files are in pure binary format. Just bits. That’s it. A floating point data stream is saved as 32 bits in the file, one after the other. A complex signal has 32 bits for the real part and 32 bits for the imaginary part. Reading back a complex number means reading in 32 bits, saving that to the real part of a complex data structure, and then reading in the next 32 bits as the imaginary part of the data structure. And just keep reading the data.

Take a look at the Octave and Python files in gr-utils for reading in data using Octave and Python’s Scipy module.

The exception to the format is when using the metadata file format. These files are produced by the File Meta Sink: http://gnuradio.org/doc/doxygen/classgr_1_1blocks_1_1file__meta__sink.html block and read by the File Meta Source block. See the manual page on the metadata file format for more information about how to deal with these files.

A one-line Python command to read the entire file into a numpy array is:

f = scipy.fromfile(open("filename"), dtype=scipy.uint8)

Replace the dtype with scipy.int16, scipy.int32, scipy.float32, scipy.complex64 or whatever type you were using.

So your question "How do I edit this?" boils down to understanding that this is raw data. You can of course just modify this on a byte level (e.g. using a hexeditor), but usually, you'd have (or write) some program that loads the data into an in-program represenation (e.g. an array of complex numbers) and look at that.

The way you're asking this suggests you're not really aware of what you're looking at (because you don't even mention how you transmit that string). Maybe your data has bit errors due to symbol errors due to noise? Quite possibly, there's no synchronization done, so your received bits did not end up on the same byte order as you meant them to be sent etc.

I think this might be a very good place to point you to the GNU Radio Guided Tutorials.



来源:https://stackoverflow.com/questions/36055644/how-to-edit-the-file-generated-by-file-sink-of-gnu-radio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!