前一阵申请的usrp x310和twinrx子板总算到位了,这下有条件也有义务好好研究下软件无线电了,毕竟花了几万块钱啊。要是没搞出点东西,真是没法交代。准备写几篇博客作为学习研究的总结,第一篇先从硬件和软件的安装配置说起。主要参考资料有:
x310有两块子版插槽,左边是slot A,右边是slot B。twinrx的硬件安装非常简单,将方向对准,插槽插好,然后拧上四角的螺丝就行了,具体步骤可以参考[4]。twinrx子板安装到slot A以后,效果是这样的。
前面板来个特写,目前只有两个SMA天线接口。
后面板特写。后面板有两个万兆SFP+接口。其中SFP+0也能降级作为千兆以太网使用。当SFP+0用作千兆以太网时,不支持10M和100M以太网,所以要求对端也为千兆,而且一定要使用六类网线。
另外,x310出厂默认的fpga image版本是HG,这个版本的image把SFP+0作为千兆以太网,SFP+1作为万兆。若想把两个SFP+端口都作为万兆使用,需要用usrp_image_loader更新XG版本的镜像。
twinrx是目前推出的最新的子板,不支持老版本的uhd和gnuradio,最低版本要求参考[3]。
3.1 windows下安装
在windows下安装usrp的开发环境很简单,在files.ettus.com的相应目录中,下载最新的uhd二进制安装包运行即可。uhd包含了开发需要的头文件,库文件和运行时,还包含了一些实用工具。
如果不打算自己写代码的话,uhd提供的几个命令行程序已经足够研究一阵了。如果要自己写代码,还需要安装boost库和visual studio。boost库也有现成的安装包,下载后一路下一步就完事了。我是在win7 x64下面装的vs2013,这个坑就比较多了,需要说明一下。
3.2 ubuntu下安装
在ubuntu下安装uhd也非常简单,参考http://files.ettus.com/manual/page_install.html#install_linux,三条命令就搞定,安装的版本也是最新的。
准备工作都完成了,现在就把它用起。把转接头插到SFP+0端口,然后用网线将x310和计算机直连。还需要设置一下计算机的IP地址。当SFP+0工作在千兆速度时,该网口的默认IP是192.168.10.2(万兆时为192.168.30.2)。所以需要将计算机的IP设置在同一网段,例如192.168.10.7,子网掩码设置为255.255.255.0。然后把一个价值10元的收音机拉杆天线在前面板的SMA接口上。打开电源开关,x310的风扇声音还是略大。
直接在cmd或终端里运行uhd_find_devices程序。可以看到找到了我们的设备。
~$ uhd_find_devices
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.001.001-release
--------------------------------------------------
-- UHD Device 0
--------------------------------------------------
Device Address:
type: x300
addr: 192.168.10.2
fpga: HG
name:
serial: *******
product: X310
再运行一下usrp_uhd_probe,可以看到更详细的信息。从程序输出中可以看到,只在slot A安装了子板twinrx,该子板有两个接收通道frontend 0和frontend 1,这块子板没有发送通道(这也是我比较后悔的一件事,应该买一块ubx的)。
~$ uhd_usrp_probe
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.001.001-release
-- X300 initialization sequence...
-- Determining maximum frame size... 1472 bytes.
-- Setup basic communication...
-- Loading values from EEPROM...
-- Setup RF frontend clocking...
-- Radio 1x clock:200
-- Detecting internal GPSDO.... No GPSDO found
-- [DMA FIFO] Running BIST for FIFO 0... pass (Throughput: 1186.7MB/s)
-- [DMA FIFO] Running BIST for FIFO 1... pass (Throughput: 1181.5MB/s)
-- [RFNoC Radio] Performing register loopback test... pass
-- [RFNoC Radio] Performing register loopback test... pass
-- [RFNoC Radio] Performing register loopback test... pass
-- [RFNoC Radio] Performing register loopback test... pass
-- Performing timer loopback test... pass
-- Performing timer loopback test... pass
_____________________________________________________
/
| Device: X-Series Device
| _____________________________________________________
| /
| | Mboard: X310
| | revision: 10
| | revision_compat: 7
| | product: 30818
| | mac-addr0: 00:80:2f:27:5d:7f
| | mac-addr1: 00:80:2f:27:5d:80
| | gateway: 192.168.10.1
| | ip-addr0: 192.168.10.2
| | subnet0: 255.255.255.0
| | ip-addr1: 192.168.20.2
| | subnet1: 255.255.255.0
| | ip-addr2: 192.168.30.2
| | subnet2: 255.255.255.0
| | ip-addr3: 192.168.40.2
| | subnet3: 255.255.255.0
| | serial: *******
| | FW Version: 5.0
| | FPGA Version: 33.0
| | RFNoC capable: Yes
| |
| | Time sources: internal, external, gpsdo
| | Clock sources: internal, external, gpsdo
| | Sensors: ref_locked
| | _____________________________________________________
| | /
| | | RX Dboard: A
| | | ID: TwinRX v1.1 (0x0093)
| | | Serial: *******
| | | _____________________________________________________
| | | /
| | | | RX Frontend: 0
| | | | Name: TwinRX RX0
| | | | Antennas: RX1, RX2
| | | | Sensors: lo_locked
| | | | Freq range: 10.000 to 6000.000 MHz
| | | | Gain range all: 0.0 to 95.0 step 1.0 dB
| | | | Bandwidth range: 80000000.0 to 80000000.0 step 0.0 Hz
| | | | Connection Type: II
| | | | Uses LO offset: No
| | | _____________________________________________________
| | | /
| | | | RX Frontend: 1
| | | | Name: TwinRX RX1
| | | | Antennas: RX1, RX2
| | | | Sensors: lo_locked
| | | | Freq range: 10.000 to 6000.000 MHz
| | | | Gain range all: 0.0 to 95.0 step 1.0 dB
| | | | Bandwidth range: 80000000.0 to 80000000.0 step 0.0 Hz
| | | | Connection Type: QQ
| | | | Uses LO offset: No
| | | _____________________________________________________
| | | /
| | | | RX Codec: A
| | | | Name: ads62p48
| | | | Gain range digital: 0.0 to 6.0 step 0.5 dB
| | _____________________________________________________
| | /
| | | RX Dboard: B
| | | _____________________________________________________
| | | /
| | | | RX Frontend: 0
| | | | Name: Unknown (0xffff) - 0
| | | | Antennas:
| | | | Sensors:
| | | | Freq range: 0.000 to 0.000 MHz
| | | | Gain Elements: None
| | | | Bandwidth range: 0.0 to 0.0 step 0.0 Hz
| | | | Connection Type: IQ
| | | | Uses LO offset: No
| | | _____________________________________________________
| | | /
| | | | RX Codec: B
| | | | Name: ads62p48
| | | | Gain range digital: 0.0 to 6.0 step 0.5 dB
| | _____________________________________________________
| | /
| | | TX Dboard: A
| | | ID: Unknown (0x0092)
| | | Serial: *******
| | | _____________________________________________________
| | | /
| | | | TX Frontend: 0
| | | | Name: Unknown (0x0092) - 0
| | | | Antennas:
| | | | Sensors:
| | | | Freq range: 0.000 to 0.000 MHz
| | | | Gain Elements: None
| | | | Bandwidth range: 0.0 to 0.0 step 0.0 Hz
| | | | Connection Type: IQ
| | | | Uses LO offset: No
| | | _____________________________________________________
| | | /
| | | | TX Codec: A
| | | | Name: ad9146
| | | | Gain Elements: None
| | _____________________________________________________
| | /
| | | TX Dboard: B
| | | _____________________________________________________
| | | /
| | | | TX Frontend: 0
| | | | Name: Unknown (0xffff) - 0
| | | | Antennas:
| | | | Sensors:
| | | | Freq range: 0.000 to 0.000 MHz
| | | | Gain Elements: None
| | | | Bandwidth range: 0.0 to 0.0 step 0.0 Hz
| | | | Connection Type: IQ
| | | | Uses LO offset: No
| | | _____________________________________________________
| | | /
| | | | TX Codec: B
| | | | Name: ad9146
| | | | Gain Elements: None
| | _____________________________________________________
| | /
| | | RFNoC blocks on this device:
| | |
| | | * DmaFIFO_0
| | | * Radio_0
| | | * Radio_1
| | | * DDC_0
| | | * DDC_1
| | | * DUC_0
| | | * DUC_1
usrp x310的最主要的功能是将射频前端采集到的样本传输到计算机(接收通道)和将计算机上的数据传输到前端发送出去(发送通道)。uhd也提供了的一些工具完成这些任务。对于twinrx,我们可以用rx_samples_to_file程序将样本存储到文件中用于事后的离线分析。
/usr/lib/uhd/examples$ ./rx_samples_to_file --help
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.001.001-release
UHD Warning:
Unable to set the thread priority. Performance may be negatively affected.
Please see the general application notes in the manual for instructions.
EnvironmentError: OSError: error in pthread_setschedparam
UHD RX samples to file Allowed options:
--help help message
--args arg multi uhd device address args
--file arg (=usrp_samples.dat) name of the file to write binary samples to
--type arg (=short) sample type: double, float, or short
--nsamps arg (=0) total number of samples to receive
--duration arg (=0) total number of seconds to receive
--time arg (DEPRECATED) will go away soon! Use --duration
instead
--spb arg (=10000) samples per buffer
--rate arg (=1000000) rate of incoming samples
--freq arg (=0) RF center frequency in Hz
--gain arg gain for the RF chain
--ant arg antenna selection
--subdev arg subdevice specification
--bw arg analog frontend filter bandwidth in Hz
--ref arg (=internal) reference source (internal, external, mimo)
--wirefmt arg (=sc16) wire format (sc8 or sc16)
--setup arg (=1) seconds of setup time
--progress periodically display short-term bandwidth
--stats show average bandwidth on exit
--sizemap track packet size and display breakdown on
exit
--null run without writing to file
--continue don't abort on a bad packet
--skip-lo skip checking LO lock status
--int-n tune USRP with integer-N tuning
This application streams data from a single channel of a USRP device to a file.
-subdev选项用来指定子通道,这个参数的设置应当与实际子版的情况相一致。rx_samples_to_file这个程序只支持一个通道,又因为我们将子版安装在了solt A,所以只能指定参数为A:0(意味着将使用子板的第一个通道)或者A:1(使用第二个通道)。
-ant选项用来指定天线。大部分子版都包括两个通道(sbx,wbx,ubx都是一个接收一个发送,twinrx是两个发送),通过子版内置的天线开关,子版上的两个通道可以在两个天线接口间自由的切换。不同的子版-ant参数的具体值也不一样。对于twinrx,如果-ant参数指定为RX1,意味着使用slot A左侧的天线接口(面板上的标签写着TX/RX的那个),如果指定为RX2,则使用右侧的那个接口(标着RX2)。
中心频率-freq设置为90MHz,增益-gain指定为60dB(最大不要超过70dB),采样率-rate设置为1MHz,-duration选项指定了采样时长,以秒为单位。由于这个采样率是对正交信号来说的,所以采集到的信号带宽也为1MHz。
/usr/lib/uhd/examples$ sudo ./rx_samples_to_file --duration 60 --rate 1e6 --freq 90e6 --gain 60 --ant RX2 --subdev "A:0"
linux; GNU C++ version 5.4.0 20160609; Boost_105800; UHD_003.010.001.001-release
Creating the usrp device with: ...
-- X300 initialization sequence...
-- Determining maximum frame size... 1472 bytes.
-- Setup basic communication...
-- Loading values from EEPROM...
-- Setup RF frontend clocking...
-- Radio 1x clock:200
-- [DMA FIFO] Running BIST for FIFO 0... pass (Throughput: 1189.1MB/s)
-- [DMA FIFO] Running BIST for FIFO 1... pass (Throughput: 1178.2MB/s)
-- [RFNoC Radio] Performing register loopback test... pass
-- [RFNoC Radio] Performing register loopback test... pass
-- [RFNoC Radio] Performing register loopback test... pass
-- [RFNoC Radio] Performing register loopback test... pass
-- Performing timer loopback test... pass
-- Performing timer loopback test... pass
UHD Warning:
[X300 Radio] Requesting invalid sampling rate from device: 100 MHz. Actual rate is: 200 MHz.
Using Device: Single USRP:
Device: X-Series Device
Mboard 0: X310
RX Channel: 0
RX DSP: 0
RX Dboard: A
RX Subdev: TwinRX RX0
TX Channel: 0
TX DSP: 0
TX Dboard: A
TX Subdev: Unknown (0x0092) - 0
TX Channel: 1
TX DSP: 0
TX Dboard: B
TX Subdev: Unknown (0xffff) - 0
Setting RX Rate: 1.000000 Msps...
Actual RX Rate: 1.000000 Msps...
Setting RX Freq: 90.000000 MHz...
Actual RX Freq: 90.000000 MHz...
Setting RX Gain: 60.000000 dB...
Actual RX Gain: 60.000000 dB...
Waiting for "lo_locked": ++++++++++ locked.
Press Ctrl + C to stop streaming...
Done!
程序运行完成后,会在当前目录生成一个大小为240MB,名为usrp_samples.dat的数据文件,保存采集到的信号样本。现在计算一下该文件的大小,采集时长为60秒,采样精度为16位(实际上是14位精度,但以16位存储),采样率为1MHz,另外正交信号具有实部和虚部所以还要乘2,也就是60*16*1000000*2/8=240000000字节=240MB,与实际是完全一致的。
x310输出和输入的都是正交信号,为了对x310采集的数据进行分析和处理,必须正确的理解正交信号,下面一章将其概念进行介绍。