Linux下GNU Radio平台的搭建以及该如何使用NI USRP设备

[复制链接]
1471|14
手机看帖
扫描二维码
随时随地手机跟帖
gaochy1126|  楼主 | 2019-8-31 22:36 | 显示全部楼层 |阅读模式
1. 概念性描述

[color=rgb(51, 51, 51) !important]USRP设备需要固件(firmware image)和FPGA镜像(FPGA image)且版本一致才能正常工作,此二者与上位机使用何种环境:Windows还是Linux无关 [1],即:同一套固件和镜像不需要更换可在Windows LabVIEW及Linux GNU Radio下使用。

[color=rgb(51, 51, 51) !important] 19330343N_0.jpg

[color=rgb(51, 51, 51) !important]
图1 两套环境对比


[color=rgb(51, 51, 51) !important]在Windows系统下操作时,可通过NI-USRP ConfiguraTIon UTIlity 软件进行固件与FPGA镜像的写入/更新,如图2 。这样,USRP设备就能通过NI-USRP驱动与上位机通信。

[color=rgb(51, 51, 51) !important] 1933011A5_0.jpg

[color=rgb(51, 51, 51) !important]
图2 NI-USRP ConfiguraTIon UTIlity – N2xx/NI-29xx Image Updater


[color=rgb(51, 51, 51) !important]而在Linux GNU Radio下,UHD驱动代替了NI-USRP驱动的工作 [2]。可以通过运行 uhd_images_downloader 从网上下载镜像到本地,uhd_image_loader 更新镜像,之后会详细描述。

2. 环境搭建

[color=rgb(51, 51, 51) !important]2.1 安装Ubuntu系统
我们常用的电脑都是Windows系统的,有两种方法在电脑上运行Linux。第一种方法是安装双系统,第二种方法是安装虚拟机并在虚拟机中安装Linux,由于方法二不需要额外分区、更改BIOS等操作、在操作不当时也不会导致Windows的崩溃,因此选用方法二。

[color=rgb(51, 51, 51) !important]这里使用了常见的虚拟机软件 VMware Workstation。在以下链接中可以下载Ubuntu 16.04:https://www.ubuntu.com/download/desktop Ubuntu是一个Linux常用的发行版。下载到的文件是Ubuntu系统的镜像.iso文件,在VMware中选择File – New Virtual Machine 按照提示一步步点击下一步即可,在配置虚拟机硬件时,CPU数及CPU核心数与实际CPU一致即可,内存可设的稍大一些,我设置了8G内存(共16G物理内存),硬盘设置40G(装完Ubuntu系统、安装完GNU Radio的所有依赖软件后实际使用了8.1G)。

[color=rgb(51, 51, 51) !important]启动虚拟机,按照第一次启动向导简单配置Ubuntu,进入桌面后点击左上角的图标,搜索terminal即命令行工具,如图3 。

[color=rgb(51, 51, 51) !important] 1932449351_0.jpg

[color=rgb(51, 51, 51) !important]
图3 找到Ubuntu的命令行工具


[color=rgb(51, 51, 51) !important]打开命令行工具,输入
sudo passwd回车

[color=rgb(51, 51, 51) !important]设置管理员(Supper User)密码即root密码,在用户设置密码之前,Ubuntu每次开机会产生一个随机的root密码。注意,输密码时不会显示“****”,而是什么字符也不显示,这一点和我们一般的认知很不一样!

[color=rgb(51, 51, 51) !important]系统提示再次输入密码,第二次输入密码并确认、两次一致后密码设置成功。接下来输入
sudo apt-get update回车

[color=rgb(51, 51, 51) !important]更新源,会提示输入管理员密码,输入刚才设置的管理员密码后点回车。之后输入(或复制粘贴,请勿使用Ctrl C + V的快捷键,而是鼠标右键在命令行窗口中单击 – 选择paste)
sudo apt-get -y install git swig cmake doxygen build-essential libboost-all-dev libtool libusb-1.0-0 libusb-1.0-0-dev libudev-dev libncurses5-dev libfftw3-bin libfftw3-dev libfftw3-doc libcppunit-1.13-0v5 libcppunit-dev libcppunit-doc ncurses-bin cpufrequtils python-numpy python-numpy-doc python-numpy-dbg python-scipy python-docutils qt4-bin-dbg qt4-default qt4-doc libqt4-dev libqt4-dev-bin python-qt4 python-qt4-dbg python-qt4-dev python-qt4-doc python-qt4-doc libqwt6abi1 libfftw3-bin libfftw3-dev libfftw3-doc ncurses-bin libncurses5 libncurses5-dev libncurses5-dbg libfontconfig1-dev libxrender-dev libpulse-dev swig g++ automake autoconf libtool python-dev libfftw3-dev libcppunit-dev libboost-all-dev libusb-dev libusb-1.0-0-dev fort77 libsdl1.2-dev python-wxgtk3.0 git-core libqt4-dev python-numpy ccache python-opengl libgsl-dev python-cheetah python-mako python-lxml doxygen qt4-default qt4-dev-tools libusb-1.0-0-dev libqwt5-qt4-dev libqwtplot3d-qt4-dev pyqt4-dev-tools python-qwt5-qt4 cmake git-core wget libxi-dev gtk2-engines-pixbuf r-base-dev python-tk liborc-0.4-0 liborc-0.4-dev libasound2-dev python-gtk2 libzmq-dev libzmq1 python-requests python-sphinx libcomedi-dev python-zmq回车

[color=rgb(51, 51, 51) !important]大约会下载1个多G的依赖库和软件。等待其下载完成后,下载编译安装UHD驱动。


使用特权

评论回复

相关帖子

gaochy1126|  楼主 | 2019-8-31 22:36 | 显示全部楼层

[color=rgb(51, 51, 51) !important]2.2 安装UHD驱动
UHD驱动是以源码形式提供的。在命令行中输入
git clone https://github.com/EttusResearch/uhd回车

[color=rgb(51, 51, 51) !important]会将uhd源码拷贝到HOME路径下,转到该路径并新建build目录
cd uhd回车
cd host回车
mkdir build回车
cd build回车

[color=rgb(51, 51, 51) !important]输入
cmake ../回车

[color=rgb(51, 51, 51) !important]产生Makefile,输入
make回车



[color=rgb(51, 51, 51) !important]编译源码,大约需要10-30min时间,可以通过开启多线程编译可大大缩短编译时间,用make -j4 代替make即可,就会启用4个线程同时编译,但也不是越多越好,一般和计算机CPU线程数或虚拟机CPU线程数一致即可。如编译中途死机(虚拟机可能会出现、由于内存不足),重新来过时会接着之前的编译进度继续。之后安装编译成功的库,输入
make test回车
sudo make install回车

[color=rgb(51, 51, 51) !important]更新共享库和环境变量
sudo ldconfig回车

[color=rgb(51, 51, 51) !important]export LD_LIBRARY_PATH=/usr/local/lib回车

[color=rgb(51, 51, 51) !important]此时UHD驱动已经安装完毕,可通过输入
uhd_find_devices回车

[color=rgb(51, 51, 51) !important]查看驱动的版本,若在同一子网中已有USRP设备,可看到USRP设备的信息,如图4

[color=rgb(51, 51, 51) !important] 193214P33_0.jpg

[color=rgb(51, 51, 51) !important]
图4 验证UHD安装情况


使用特权

评论回复
gaochy1126|  楼主 | 2019-8-31 22:36 | 显示全部楼层

[color=rgb(51, 51, 51) !important]一个小技巧:在输入上条命令时输入uhd_fin之后按Tab键看看会发生什么……自动填充!对于输一些比较长的命令时可以通过自动填充功能降低拼写错误,省时省力。

[color=rgb(51, 51, 51) !important]在找到设备的情况下,可运行以下程序查看CDMA移动电话的上行频谱
uhd_fft -a addr=10.144.97.123 -f 835M -s 10M回车

[color=rgb(51, 51, 51) !important] 1932014G7_0.jpg

[color=rgb(51, 51, 51) !important]
图5 UHD FFT测试程序


[color=rgb(51, 51, 51) !important]注意,若USRP中的镜像和UHD版本不匹配的话,无法直接运行上述测试程序,可以通过更新firmware image 和 FPGA image使之匹配。更新方法见第3节。

[color=rgb(51, 51, 51) !important]2.3 安装GNU Radio
安装GNU Radio与安装UHD驱动的步骤类似。
首先回到home路径
cd $HOME回车
之后下载GNU Radio源码
git clone --recursive https://github.com/gnuradio/gnuradio回车

[color=rgb(51, 51, 51) !important]下载完成后新建build目录
cd gnuradio回车
mkdir build回车
cd build回车

[color=rgb(51, 51, 51) !important]生成Makefile并编译安装
cmake ../ 回车
make回车
make test回车
sudo make install回车
sudo ldconfig回车

[color=rgb(51, 51, 51) !important]完成后,可以测试安装是否正确,输入
gnuradio-companion回车
GNU Radio 开发环境应当可以正确打开。至此,环境搭建完成[3] 。


使用特权

评论回复
gaochy1126|  楼主 | 2019-8-31 22:37 | 显示全部楼层
3. 运行一个GNU Radio程序

[color=rgb(51, 51, 51) !important]3.1 修改USRP IP地址并连接
这里使用的是USRP-2922,USRP设备使用固定IP,默认IP是192.168.10.2 。首先将USRP设备通过网线直连至PC,设置PC的ip为192.168.10.1,子网掩码255.255.255.0,在Windows下可通过NI-USRP Configuration Utility软件修改USRP设备的IP。在本次验证中,使用了超过1台的USRP,需要通过交换机和上位机通信,在处于同一个子网的PC上查看PC的IP地址:windows徽标键+R -> 输入cmd回车 -> 输入ipconfig回车,找到自己的本地网卡的IPv4地址,如10.144.97.17,将两台USRP的IP设置到同一个子网下,如10.144.97.123和10.144.97.124 。

[color=rgb(51, 51, 51) !important]在Linux下可通过以下方法修改设备IP [4] ,cd 到/usr/local/lib/uhd/utils目录下,运行
sudo ./usrp2_recovery.py --ifc=eth0 --new-ip=10.144.97.123回车

[color=rgb(51, 51, 51) !important]以上方法需要防火墙允许UDP广播。需要注意的是,在虚拟机中运行Linux的话,需要将虚拟机的网卡配置为直连或者与主机共用IP。

[color=rgb(51, 51, 51) !important] 19310cS8_0.jpg

[color=rgb(51, 51, 51) !important]
图6 虚拟机网卡配置


[color=rgb(51, 51, 51) !important]设置IP后,可以ping一下USRP,命令行输入:
ping 10.144.97.123回车

[color=rgb(51, 51, 51) !important]此时应当看到ping通的信息,按Ctrl + Z可以退出ping的状态。

[color=rgb(51, 51, 51) !important]3.2 更新firmware image和FPGA image
如开篇所述,这两个镜像在Windows和Linux下是通用的,只要版本和驱动版本一致即可。NI-USRP 15.5提供的镜像和UHD 3.11.0提供的镜像是一致的。如果你的USRP在Windows下更新过镜像,可以跳过这一步。

[color=rgb(51, 51, 51) !important]在Ubuntu命令行中输入:
sudo uhd_images_downloader回车

[color=rgb(51, 51, 51) !important]这样可以自动地将网络上合适的镜像下载到本地计算机中。

[color=rgb(51, 51, 51) !important]再输入
uhd_image_loader --args="type=usrp2,addr=,reset"回车
将镜像下载到USRP设备中并重启设备,这里的镜像是自动选择版本的。


使用特权

评论回复
gaochy1126|  楼主 | 2019-8-31 22:37 | 显示全部楼层

[color=rgb(51, 51, 51) !important]3.3在GNU Radio中编程
首先,在命令行中输入
gnuradio-companion回车
运行GNU Radio开发环境,该环境也是使用图形化模块编程的,详细使用教程可以在网络上搜索。这里可以编写一个程序,在两台USRP-2922之间传文件。使用随机自带的天线,工作在915M ISM频段上。也可通过衰减器将两个USRP的TX/RX接口直连。注意:使用USRP发射无线电信号需遵守当地相关法律法规。

[color=rgb(51, 51, 51) !important] 1931022148_0.jpg

[color=rgb(51, 51, 51) !important]
图7 一个GRC程序

[color=rgb(51, 51, 51) !important] 1930135612_0.jpg

[color=rgb(51, 51, 51) !important]
图8 程序运行界面

[color=rgb(51, 51, 51) !important] 19300293N_0.jpg

[color=rgb(51, 51, 51) !important]
图9 程序运行结果


使用特权

评论回复
gaochy1126|  楼主 | 2019-8-31 22:37 | 显示全部楼层
相关链接:
[1] GNU radio and LabVIEW simultaneously on USRP 2920
?board.id=500&message.id=1188
[2] Can NI-USRP be worked on GNU Radio?
[3] Building and Installing the USRP Open-Source Toolchain (UHD and GNU Radio) on Linux
[4] USRP Hardware Driver and USRP Manual

使用特权

评论回复
gaochy1126|  楼主 | 2019-12-31 21:40 | 显示全部楼层
在Ubuntu上安装GNU radio                                 

使用特权

评论回复
gaochy1126|  楼主 | 2019-12-31 21:40 | 显示全部楼层
用gnu radio 的grc搭建信号解调                     

使用特权

评论回复
gaochy1126|  楼主 | 2019-12-31 21:40 | 显示全部楼层
基于 GNU Radio 的 Python 程序,能够将 USRP 接收到的信号以图形界面显示它的FFT频谱。

使用特权

评论回复
gaochy1126|  楼主 | 2019-12-31 21:41 | 显示全部楼层
gnuradio里面有一个实例,usrp_spectrum_sense.py 可以参照一下  

使用特权

评论回复
gaochy1126|  楼主 | 2020-1-31 19:40 | 显示全部楼层
各linux发行版更新源中的GNURadio版本相对较老,可能会有相关的依赖问题。

使用特权

评论回复
gaochy1126|  楼主 | 2020-1-31 19:41 | 显示全部楼层
配置ubuntu12.04下gnuradio+openBTS         

使用特权

评论回复
gaochy1126|  楼主 | 2020-1-31 19:41 | 显示全部楼层
ubuntu可能更适合初学者学,因为它有强大的社区支持  

使用特权

评论回复
gaochy1126|  楼主 | 2020-1-31 19:41 | 显示全部楼层
gnuradio给我们提供了近百种常用的功能模块block,但是在我们自己的系统设计中,需要不同的模块完成特定的功能,这样就需要我们自己来编写 C++源代码,生成新的block以供系统调用。

使用特权

评论回复
gaochy1126|  楼主 | 2020-1-31 19:41 | 显示全部楼层
gnuradio usrp 开发的中文论坛网上有很多,资料不错的。      

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:这个社会混好的两种人:一是有权有势,二是没脸没皮的。

1025

主题

11271

帖子

24

粉丝