# Log raw data from the usrp\_spectrum\_sense.py

**URL:** <https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862>\
**Category:** GNU Radio\
**Created:** [December 1, 2014, 3:59pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862 "2014-12-01T15:59:03Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [December 1, 2014, 3:59pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/1 "2014-12-01T15:59:03Z")

</div>

I’m using the usrp\_spectrum\_sense.py to get the raw data for the wide  
band  
spectrum for FFT in the FPGA . The thing confused me is what the raw  
data  
is. Is that the complex signal before fft ?  
As m.raw\_data is a string that contains the binary floats, when i try  
to  
log it in a txt file, it outputs Garbled text, and it seems only take  
few  
millisecond, and how to control the time to do the spectrum sensing btw.  
here is the code for exporting the m.raw\_data

```
    text_file = open("Output.txt", "w")
    text_file.write("binary floats: %s" % m.raw_data)
    text_file.close()

```

Thanks a lot

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503.html](http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 1, 2014, 4:37pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/2 "2014-12-01T16:37:16Z")

</div>

Hi Leo,

usrp\_spectrum\_sense actually has nothing to do with the FPGA – in fact,  
it just gets complex samples from a USRP, and displays them in frequency  
domain; so hopefully that answers your question 🙂

Regarding writing the raw binary data to a file: These are binary  
samples, and not text, and thus you won’t see anything useful in a text  
file.

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 1, 2014, 5:23pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/3 "2014-12-01T17:23:59Z")

</div>

When u say complex samples, i thought it should in time domain, and  
after the  
the fft block, it transfer to frequency domain. I just want use USRP to  
collect the a wide band signal around and save the data to the txt file,  
so  
i use the usr\_spectrum\_sense.

and how to make the binary samples visualized and could be processed?  
or the s2v is the thing I may consider?

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51506.html](http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51506.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 4, 2014, 2:29pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/4 "2014-12-04T14:29:58Z")

</div>

when u said:save the signal from a USRP to a file, that’s a two  
block flow graph in the GNU Radio companion: Just connect the USRP  
Source to a File Sink, parameterize both to your likings, and you’re  
done.

the two block flow graph can only use for narrow band, my idea is to  
sensing  
the wide band signal, such as Wi-Fi, and get the complex sample.

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51534.html](http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51534.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 1, 2014, 5:30pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/5 "2014-12-01T17:30:39Z")

</div>

> When u say complex samples, i thought it should in time domain,

yes, these are time domain samples.

> I just want use USRP to  
> collect the a wide band signal around and save the data to the txt file,

Usually, there’s no good reason to save millions of samples in text  
format – it’s not really useful, just big.  
If you, for some reason, need that, you can either write your own sink  
that does that, or use python, octave, matlab, C, C++, or whatever you  
like to load the binaries and print out strings representing complex  
numbers textually.

> so i use the usr\_spectrum\_sense.  
> usrp\_spectrum\_sense is really a visualization demo.  
> If you just want to save the signal from a USRP to a file, that’s a two  
> block flow graph in the GNU Radio companion: Just connect the USRP  
> Source to a File Sink, parameterize both to your likings, and you’re  
> done.

If that sounds strange to you, I can really recommend going through the  
guided tutorials 1, 2 and 3, and most of your questions will be answered  
🙂  
[http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided\_Tutorials](http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorials)

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 4, 2014, 5:48pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/6 "2014-12-04T17:48:50Z")

</div>

Hello Leo,

with the USRP source you can get as much bandwidth at once as your  
sampling rate allows, and it will give you the complex samples. The USRP  
source will give you all the instantaneous bandwidth the USRP delivers  
to your PC. You won’t see more at once when using usrp\_spectrum\_sense,  
as it internally uses the very same USRP source.

I don’t know which USRP model you are currently using, but all but the  
USRP1/b100/e1x0 will do enough bandwidth to allow you to monitor a WiFi  
channel at once, as long as your PC is fast enough.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 4, 2014, 6:15pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/7 "2014-12-04T18:15:53Z")

</div>

Hi sir,  
I’m using USRP2 now, as the sample rate is limited to 25MHz for 16bit  
sample, I thought it can only sweep 25MHz at one time, but when u said  
USRP  
source can get as much bandwidth at once, it confused me.  
The Wi-Fi frequency is from 2.38GHz to 2.42GHz,which 25MHz is not enough  
for  
such large bandwidth. Or is there any misunderstanding of these concept?

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51539.html](http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51539.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 4, 2014, 9:18pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/8 "2014-12-04T21:18:21Z")

</div>

Hi sir,  
I have ran the uhd\_msg\_tune.grc,but its quiet hard to understand the  
python  
code for me.

I just set the sample rate to 40M, and centre frequency to 2.4G, it  
comes  
out power against the frequency of the signal and the graph seems more  
static than dynamic.

I wonder how it achieved without fft, and how to export the raw complex  
data  
instead of power?

cuz I want to install the gnuradio into a embedded system instead of PC,  
I’m  
working on the data collection, after get the raw data, I will pass it  
to  
the FPGA for the fft, and the output will be further processed for  
signal  
classification.

Thanks a lot  
Yang

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51545.html](http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51545.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 4, 2014, 7:10pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/9 "2014-12-04T19:10:01Z")

</div>

Hi Leo,

thanks for following up on this!  
I’ll just comment in your reply; I hope that is OK for you.

On 12/04/2014 06:05 PM, Leo Yang wrote:

> Hi sir,  
> I’m using USRP2 now, as the sample rate is limited to 25MHz for 16bit  
> sample, I thought it can only sweep 25MHz at one time, but when u said USRP  
> source can get as much bandwidth at once, it confused me.  
> Yes, the instantaneous maximum bandwidth with 16bit over Gigabit  
> Ethernet is 25MHz. But: That is not “sweeping”, it’s just sampling that  
> much bandwidth at once.  
> The Wi-Fi frequency is from 2.38GHz to 2.42GHz,which 25MHz is not enough for  
> such large bandwidth. Or is there any misunderstanding of these concept?  
> I don’t think you’re misunderstanding 🙂  
> A standard 802.11g channel is only rougly 20MHz wide, the 802.11n  
> transmissions might be twice as wide, so I guess this was my  
> misunderstanding.

I’m understanding now that you want to have a sweeping spectrum  
analyzer; usrp\_spectrum\_sense implements that, but in a manner that does  
not use timed commands, which is kind of undesirable for a  
However, in the gr-uhd/example/grc folder, you will find an example,  
called uhd\_msg\_tune.grc, which behaves a bit similar to  
usrp\_spectrum\_sense, and you could connect a metadata file sink parallel  
to the QT gui sink.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 5, 2014, 11:18am UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/10 "2014-12-05T11:18:07Z")

</div>

Hi Yang,

the Power of the FFT is only calculated inside the graphical sink, the  
connection between the USRP source and the graphical sink represents a  
complex sample stream.

I’m still not quite understanding what you really want the USRP to do,  
would you mind explaining that again?

Best regards,  
Marcus

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 5, 2014, 12:57pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/11 "2014-12-05T12:57:42Z")

</div>

thank u sir,

now, i just want to export the complex stream that goes into the sink,  
is  
that possible? whats the format of the that complex stream?  
cuz, in the my group design, USRP is in charge of signal collection, the  
rest signal processing(FFT) work will pass to a FPGA.

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51562.html](http://gnuradio.4.n7.nabble.com/Log-raw-data-from-the-usrp-spectrum-sense-py-tp51503p51562.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![Leo\_Yang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/439d5e/32.png) [@Leo\_Yang](https://www.ruby-forum.com/u/Leo_Yang)\
**Post date:** [December 5, 2014, 1:43pm UTC](https://www.ruby-forum.com/t/log-raw-data-from-the-usrp-spectrum-sense-py/234862/12 "2014-12-05T13:43:05Z")

</div>

Hello Yang,  
On 12/05/2014 12:47 PM, Leo Yang wrote:

> thank u sir,
> 
> now, i just want to export the complex stream that goes into the sink, is  
> that possible?  
> That is exactly what the file sink does, see the proposed solution I’ve  
> discussed in this thread.  
> whats the format of the that complex stream?  
> just pairs of 32bit floats, one after the other. [1]

Honestly, we’re starting to repeat ourselves; I think I don’t really  
understand the issues you encounter, could you explain whether the  
usrp\_source-\>file\_sink fits your needs or what is insufficient?

Greetings,  
Marcus

[1][http://gnuradio.org/redmine/projects/gnuradio/wiki/FAQ#What-is-the-file-format-of-a-file\_sink-How-can-I-read-files-produced-by-a-file-sink](http://gnuradio.org/redmine/projects/gnuradio/wiki/FAQ#What-is-the-file-format-of-a-file_sink-How-can-I-read-files-produced-by-a-file-sink)
