MATLAB連接USRP實現數據採集

本文主要針對USRP 2955設備進行數據接收。2955由X310進行封裝,可以實現數據的收發。

1、USRP連接電腦需要修改IP地址。USRP中的IP地址默認爲192.168.10.2。因此電腦端需要修改IP地址爲192.168.10.1 ,子網掩碼爲255.255.255.0。

2、MATLAB2018中的UHD版本爲3.9.7,MATLAB2019中的UHD版本爲3.13。USRP官網目前的最新版本爲3.14。要保證MATLAB能夠連接上USRP需要兩個的版本一致,因此使用MATLAB2019和USRP的3.13。其中MATLAB2019中需要下載Communications Toolbox Support Package for USRP Radio功能包。

3、官網下載uhd_3.13.1.0-release_Win32_VS2014。將路徑添加到環境變量中,該軟件需要pip和python2.7的支持。因此需要先安裝python,python2.7.8以上的版本才自帶pip。因此需要安裝python2.7.8。

4、安裝完成後斷開網絡修改IP,連接USRP,首先執行uhd_find_devices確定是否發現設備,若通過網線連接,網口燈不亮,則利用VIVADO燒寫bit文件。

5、uhd_usrp_probe 命令,使用探針工具若檢測到如下問題(固件有問題需要更新):


Error: RuntimeError: Expected FPGA compatibility number 35, but got 33:
The FPGA image on your device is not compatible with this host code build.
Download the appropriate FPGA images for this version of UHD.
As an Administrator, please run:
"C:\Program Files\UHD\lib\uhd\utils\uhd_images_downloader.py"
Then burn a new image to the on-board flash storage of your
USRP X3xx device using the image loader utility. Use this command:
"C:\Program Files\UHD\bin\uhd_image_loader" --args="type=x300,addr=192.168.10.2"


6、連接外網,CMD中執行"C:\Program Files\UHD\lib\uhd\utils\uhd_images_downloader.py"會自動下載固件 

7、下載完成後執行"C:\Program Files\UHD\bin\uhd_image_loader" --args="type=x300,addr=192.168.10.2進行鏡像文件的燒寫

8、完成後,打開MATLAB,執行findsdru命令,若status顯示not compatible則需要燒寫MATLAB的鏡像,使用getSDRuDriverVersion()  查看驅動版本

9、執行druload('Device','X310')燒入image重啓後執行findsdru,statu顯示success

10、參考代碼:

%首先查找設備findsdru
%參數說明1:https://ww2.mathworks.cn/help/supportpkg/usrpradio/ug/comm.sdrureceiver-system-object.html#bun592c-29
%參數說明2: https://ww2.mathworks.cn/help/dsp/ref/dsp.signalsink-system-object.html?s_tid=doc_ta
%% SDRuReceiver
% 1.ChannelMapping 通道映射:1,2or[1 2] channels 1 and 2 of the radio with IP address 192.168.10.3.
% 2.CenterFrequency:2.45e9
% 3.LocalOscillatorOffset:0 本地振盪器(LO)偏移頻率
% 4.Gain:default:8 硬件接收器數據路徑的總體增益
% 5.ClockSource:'Internal' (default) | 'External' 時鐘源
% 6.DecimationFactor 512 (default) | integer 數據接收器的抽取係數
% 7.TransportDataType int16 
% 8.OutputDataType 'Same as transport data type' (default) | 'double'   接收信號的數據類型
% 9.SamplesPerFrame 362 每幀數據的樣本
% 10.EnableBurstMode false not run in real time
% 11.NumFramesInBurst 100
% 12.MasterClockRate default:200e6 120e6 186.32e6 200e6
% 13.PPSSource :Internal 
%% dsp.SignalSink
% 1.BufferLength:default:inf Maximum number of input frames to log
% 2.Decimation:default;1 抽取因子
% 3.FrameHandlingMode:Output dimensionality for frame-based inputs
% default:2-D array
% 4.Buffer:logged data

clear;close all;
rx_SDRu = comm.SDRuReceiver('Platform','X310','IPAddress','192.168.10.2','CenterFrequency',700e6,'OutputDataType','double','LocalOscillatorOffset',650e6 );
% info(rx_SDRu)  

%%進行一次數據的採集,第一次是buffer置0,第二次纔是是未知數據,第三次纔是正式數據
%默認buffer大小爲362

% [Y1,datalen]=step(rx_SDRu);
% subplot(221);plot(real(Y1));title('空數據');
% pause(3);
% [Y2,datalen]=step(rx_SDRu);
% subplot(222);plot(real(Y2));title('未知數據');
% [Y3,datalen]=step(rx_SDRu);
% subplot(223);plot(real(Y3));title('正式數據1');
% [Y4,datalen]=step(rx_SDRu);
% subplot(224);plot(real(Y4));title('正式數據2');

%%利用SignalSink採集數據
rx_log = dsp.SignalSink('Decimation',1);
data1 = rx_SDRu();
rx_log(complex(data1));%第一輪採集的是實數0,後面爲複數,因此強制轉換,或者後面的數據存放新的變量裏面
subplot(121);
log=rx_log.Buffer;
plot(real(log));title('空數據');
pause(3);
data2 = rx_SDRu();
rx_log(complex(data2));%第二輪採集的是未知
subplot(122);
log=rx_log.Buffer;
plot(real(log(362:end)));title('未知數據');

%正式數據
for counter = 1:20
  data = rx_SDRu();
  rx_log(data);
end
log=rx_log.Buffer;
figure;
plot(real(log(722:end)));title('正式數據');
release(rx_SDRu)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章