# Change of complex binary file format for Matlab

**URL:** <https://www.ruby-forum.com/t/change-of-complex-binary-file-format-for-matlab/201705>\
**Category:** GNU Radio\
**Created:** [January 13, 2011, 6:01am UTC](https://www.ruby-forum.com/t/change-of-complex-binary-file-format-for-matlab/201705 "2011-01-13T06:01:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 13, 2011, 6:01am UTC](https://www.ruby-forum.com/t/change-of-complex-binary-file-format-for-matlab/201705/1 "2011-01-13T06:01:44Z")

</div>

Hello,  
I am trying to use “rx\_samples\_to\_file.cpp” in UHD to save samples  
received.  
UHD seems save samples in complex integer format in c++.  
However, it is not possible to read that format from Matlab.  
I have checked the Matlab utilities in Gnuradio, but they were not  
useful.  
Is that any simpler way to change the formats of the saving file so that  
Matlab can easily read?

Another question is that why the saved samples are integer format? not  
float?  
Thanks for reading.

* * *

```
std::vector<std::complex<short> >

```

buff(dev-\>get\_max\_recv\_samps\_per\_packet());  
std::ofstream outfile(file.c\_str(), std::ofstream::binary);

```
while(num_acc_samps < total_num_samps){
    size_t num_rx_samps = dev->recv(
        &buff.front(), buff.size(), md,
        uhd::io_type_t::COMPLEX_INT16,
        uhd::device::RECV_MODE_ONE_PACKET
    );

    outfile.write((const char*)&buff[0], num_rx_samps *

```

sizeof(std::complex));

– \*  
\*

---

<div class="post-metadata">

**Author:** ![Sangho\_Oh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@Sangho\_Oh](https://www.ruby-forum.com/u/Sangho_Oh)\
**Post date:** [January 13, 2011, 6:31am UTC](https://www.ruby-forum.com/t/change-of-complex-binary-file-format-for-matlab/201705/2 "2011-01-13T06:31:48Z")

</div>

> I am trying to use “rx\_samples\_to\_file.cpp” in UHD to save samples received.  
> UHD seems save samples in complex integer format in c++.

yes, COMPLEX\_INT16

> However, it is not possible to read that format from Matlab.

I’m not a huge matlab fan, but I am sure that it can read integers from  
a file. [LMGTFY](http://tinyurl.com/6kyxdk4)

> I have checked the Matlab utilities in Gnuradio, but they were not useful.

Its looks like you are not very familiar with matlab, so I suggest (out  
of my person preference) that you take this time to learn python+scipy  
[http://www.scipy.org/](http://www.scipy.org/) For one, its free. And I have always found myself  
more productive with python, and I have found the plotting widgets and  
mathematics that come with scipy give me everything I need.

> Is that any simpler way to change the formats of the saving file so that  
> Matlab can easily read?

You can change the example easily to write binary floats. And with a  
tiny bit more effort and a for loop you can write a text formatted file  
as well.

> Another question is that why the saved samples are integer format? not  
> float?

To save disk space and IO overhead for large captures or high data  
rates. You will appreciate this if you change the example to output a  
text format.

Good luck,  
-Josh

---

<div class="post-metadata">

**Author:** ![Sangho\_Oh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@Sangho\_Oh](https://www.ruby-forum.com/u/Sangho_Oh)\
**Post date:** [January 13, 2011, 6:53am UTC](https://www.ruby-forum.com/t/change-of-complex-binary-file-format-for-matlab/201705/3 "2011-01-13T06:53:06Z")

</div>

Hi

I am not that coded up on UHD, but I would think that they have the same  
type of file writing system as is used in the GNU Radio code. In the GNU  
Radio code they use a binary file writing system. I have attached a  
matlab M  
file that reads these types of files, the file can be found in GNU Radio  
file address ~/gnuradiio/gnuradio-core/src/utils. There are a large  
number  
of matlab M files there so just have a look for the type of stuff you  
want  
to do.

Hope it help

Regards  
Alan Jones

---

<div class="post-metadata">

**Author:** ![Sangho\_Oh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/9fc348/32.png) [@Sangho\_Oh](https://www.ruby-forum.com/u/Sangho_Oh)\
**Post date:** [January 13, 2011, 8:24am UTC](https://www.ruby-forum.com/t/change-of-complex-binary-file-format-for-matlab/201705/4 "2011-01-13T08:24:00Z")

</div>

Thanks a lot.  
I found the problem. I should have used ‘int16’ instead of ‘int’ nor  
‘float’.  
I think I have better spectrum shape for 20Mhz signal using UHD compared  
to  
gnuradio  
usrp2\_rx\_cfile.py.

But I found high frequency portion is somewhat suppressed than the  
original  
samples transmitted.

One question is that whether it is possible to demodulate 20Mhz signal  
using  
Gnuradio. I think many are trying to demodulate 802.11 packets, but  
still  
cannot found any one succeeded.

The maximum sampling that Gnuradio can provide rate is 25Mhz with  
decimation 4. But I am curious about whether it is possible to  
demodulate  
the 20Mhz signal without 2x or 4x oversampling.
