Porting GnuRadio USRP examples to USRP2

Most example code in gnuradio-examples/ is written for the USRP. If you are new to this (as I am), it is somewhat tricky to update the USRP1 code into working with the USRP2.

This is a short list of what you can try out. It was deduced from a simple diff between usrp_wfm_rcv.py and usrp2_wfm_rcv.py in gnuradio git. My setup is a simple USRP2 with the TVRX frontend, running gnuradio from ubuntu maverick apt.

  • basics first: “from gnuradio import usrp2” instead of usrp.
  • you don’t need to pick a subdevice, nor the usrp_dbid stuff.
  • usrp.source_c() is now usrp2.source_32fc(). You don’t need to bother with the interface/MAC-addr arguments, it will autodetect.
  • decimation levels will be higher on the USRP2. The USRP1 features 64 MS/s (megasamples/sec), while the USRP2 can do 100 MS/s. Multiply the USRP1 decimation rate with (100/64) to get the USRP2 equivalent.
  • set gain on the usrp2 object instead of on the subdevice.
  • usrp.set_decim_rate(decim) is now usrp2.set_decim(decim).
  • usrp.tune(usrpobj, ..) is usrp2obj.set_center_freq(freq).

Some code examples to make it easier to understand:

<         self.u.set_decim_rate(usrp_decim)
>         self.u.set_decim(usrp_decim)

<         g = self.subdev.gain_range()
>         g = self.u.gain_range()

<         r = usrp.tune(self.u, 0, self.subdev, target_freq)
>         r = self.u.set_center_freq(target_freq)

<         self.subdev.set_gain(gain)
>         self.u.set_gain(gain)

The full diff (liberal use of –unified to get the complete files) can be seen in Gist 654211.

This entry was posted in stuff and tagged , , , . Bookmark the permalink.

2 Responses to Porting GnuRadio USRP examples to USRP2

  1. jincheng says:

    Hi, do you know how to setup USRP2 and TVRX? I have failed a lot of times. Could you give me some references about the setup? Thanks a lot. BTW, do you know how to port the usrp_spectrum_sense.py to usrp2?

    • Hi.

      It’s been a while since I played around with this now, so the details are all fuzzy.
      I suggest that you try the gnuradio-discuss email list.

      It is pretty lively these days and the people there are very knowledgeable and helpful.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s