| 1 | == Spectrum sensing with USRP2 and wiserd (OEDL and OML) == |
| 2 | |
| 3 | [[TOC(Tutorials/k0SDR*)]] |
| 4 | |
| 5 | === Description === |
| 6 | We'll use the nodes on sandbox 3 to transmit a predefined waveform and receive the spectrum data into an OML file. |
| 7 | |
| 8 | === Hardware / Software Resources utilized === |
| 9 | 1. Grid nodes with a USRP2 connect via Ethernet. |
| 10 | 2. ''ubuntu-14-04-64bit-sdr.ndz'': disk image loaded onto nodes. |
| 11 | 3. [http://wiser.orbit-lab.org/wiki/wiser/mSoftware/aWiserd Wiserd] - interface to configure and stream data to/from USRPs. |
| 12 | |
| 13 | === Transmit predefined tone === |
| 14 | To get started load ''ubuntu-14-04-64bit-sdr.ndz'' onto node1-1 and node1-2. Then turn both nodes on. |
| 15 | |
| 16 | |
| 17 | Set up node1-1 to configure transmit a predefined sine wave |
| 18 | {{{ |
| 19 | node1-1> wiserd |
| 20 | > --uhd_tx_freq 700e6 --uhd_tx_rate 5e6 --uhd_tx_gain 20 |
| 21 | > --tran_wavetype SINE --tran_wavefreq 1e6 --tran_amplitude 0.5 |
| 22 | > --addmodule waveform |
| 23 | }}} |
| 24 | |
| 25 | At this point the node1-1 should be transmitting a tone at 1MHz from the 700MHz center frequency. |
| 26 | From node1-2, use the UHD spectrum utility to verify the waveform |
| 27 | {{{ |
| 28 | node1-2> cd uhd/host/build/examples/ |
| 29 | node1-2> ./rx_ascii_art_dft --freq 700e6 --rate 5e6 --gain 20 --ref-lvl -40 |
| 30 | }}} |
| 31 | |
| 32 | === Record spectrum data to an OML file === |
| 33 | Now let's use wiserd to record this spectrum data into a local |
| 34 | {{{ |
| 35 | node1-2> wiserd |
| 36 | > --uhd_rx_freq 700e6 --uhd_rx_rate 5e6 --uhd_rx_gain 20 --recv_running_time 2000 |
| 37 | > --recv_numbins 256 --recv_avgwinlen 5 --recv_oml_servername file --recv_oml_output_type vector |
| 38 | > --addmodule fftmovingavgoml --timed |
| 39 | }}} |
| 40 | |
| 41 | Wiserd should record spectrum data to ''file'' for 2000ms and then stop recording. |
| 42 | |
| 43 | The recorded file can ve very large so a short snippet is shown below |
| 44 | {{{ |
| 45 | protocol: 5 |
| 46 | domain: spectrum |
| 47 | start-time: 1432751617 |
| 48 | sender-id: |
| 49 | app-name: spectrum |
| 50 | schema: 0 _experiment_metadata subject:string key:string value:string |
| 51 | schema: 1 _client_instrumentation measurements_injected:uint32 measurements_dropped:uint32 bytes_allocated:uint64 bytes_freed:uint64 bytes_in_use:uint64 bytes_max:uint64 |
| 52 | schema: 2 spectrum_data sampling:int32 cfreq_MHz:double gain_dB:int32 FFTLength:int32 FFTNum:string FFTBins:[double] |
| 53 | content: text |
| 54 | |
| 55 | 0.805870 2 1 5000000 700000000.000000 20 256 --- 256 0.00642503052949905 0.00640759989619255 0.00715913623571396 0.00693625304847956 0.00609686318784952 0.00611346587538719 0.00733797857537866 0.00742206443101168 0.00644569378346205 0.00748523231595755 0.00655230600386858 0.006748684681952 0.00692673865705729 0.00592925120145082 0.00748975854367018 0.00621710997074842 0.00608090776950121 0.0055550062097609 0.0057487809099257 0.00720828492194414 0.00618668925017118 0.00473179295659065 0.006808090955019 0.00687119970098138 0.005494792945683 0.00755641097202897 0.0063415477052331 0.00596773438155651 0.00671912264078856 0.00726061593741179 0.00553654972463846 0.00698605040088296 0.00529543263837695 0.00783630926162004 0.00672802329063416 0.00635359063744545 0.00666496902704239 0.00626690546050668 0.00589855946600437 0.00733701791614294 0.00885633658617735 0.00691640749573708 0.00642102723941207 0.00926791410893202 0.00719658425077796 0.00593259138986468 0.00634927907958627 0.00793861877173185 0.0070486469194293 0.008316645398736 0.00513946730643511 0.00822983402758837 0.00626416876912117 0.00688301119953394 0.00707513466477394 0.0092685641720891 0.00870540831238031 0.00925131514668465 0.0262136552482843 0.00431728875264525 0.00578053155913949 0.0068720756098628 0.00764161115512252 0.00618286710232496 0.00673849601298571 0.006247628480196 0.00722268223762512 0.00629418436437845 0.00773267960175872 0.0074175582267344 0.00646864250302315 0.00801937561482191 0.00764140486717224 0.00779543584212661 0.0079394802451133^@ 0.00697977934032679 0.00779644120484591 0.00789852533489466 0.00959375221282244 0.00706543261185288 0.00814522616565228 0.00915447436273098 0.00844117812812328 0.00785306375473738 0.00716404151171446 0.00879248790442944 0.0101312343031168 0.00902777351438999 0.00988549832254648 0.00871223211288452 0.00874703098088503 0.0101676043123007 0.0103123057633638 0.00945603661239147 0.0100027937442064 0.0096791498363018 0.00998857151716948 0.0117274457588792 0.0101575655862689 0.0124989086762071 0.01237382367253^@ 0.0133225293830037 0.0146061507984996 0.0208994746208191 0.0468954369425774 0.122245348989964 0.0262875147163868 0.0151699390262365 0.0129134533926845 0.0126580595970154 0.0127546470612288 0.0141236884519458 0.0128746386617422 0.0113462153822184 0.0139725683256984 0.0149048119783401 0.012725941836834 0.0142481597140431 0.014576974324882 0.0165196731686592 0.0166050866246223 0.0181233920156956 0.0182002373039722 0.0205240771174431 0.0182637479156256 0.0225130878388882 0.0199225898832083 0.022662311792373^@ 0.0272368285804987 0.0229660626500845 0.0206097178161144 0.0252554770559072 0.0277251955121756 0.027890432626009 0.03005550801754 0.0291061010211706 0.0328644625842571 0.0377240218222141 0.0371225923299789 0.0430551692843437 0.0448992624878883 0.0500019602477551 0.055297739803791 0.0620570369064808 0.0687699541449547 0.0800459012389183 0.096101202070713 0.119709715247154 0.151971653103828 0.222265601158142 0.395731300115585 1.8209445476532 0.701657652854919 0.293412864208221 0.186001688241959 0.135782465338707 0.107891581952572 0.0872630029916763 0.0756658166646957 0.0643373876810074 0.0577538087964058 0.053208451718092 0.0474477596580982 0.043580025434494 0.0416424460709095 0.0350464805960655 0.034961711615324 0.0329569280147552 0.0307744555175304 0.0304238144308329 0.0277519728988409 0.026080325245857^@ 0.0244618654251099 0.0233206581324339 0.023502279073 0.0213998667895794 0.0197461675852537 0.0213919542729855 0.0210770349949598 0.0178680755198002 0.0188288316130638 0.0168855395168066 0.0173622630536556 0.0162709001451731 0.0161915346980095 0.01674560084939 0.0157821383327246 0.0147516150027514 0.0129792336374521 0.01588449254632 0.0135742779821157 0.0144895184785128 0.0126562193036079 0.0140249133110046 0.0127318147569895 0.0125512164086103 0.0115098562091589 0.0102976094931364 0.0142459943890572 0.0123602850362659 0.0110908718779683 0.0117047075182199 0.0108433095738292 0.0113961454480886 0.00989516265690327 0.0109618585556746 0.00892620161175728 0.0101382881402969 0.00846627354621887 0.0101864114403725 0.00957665219902992 0.00926020089536905 0.00821538269519806 0.00760462647303939 0.010831995867192^@ 0.00874793529510498 0.00983591936528683 0.0086268512532115 0.00901609845459461 0.00873745605349541 0.00801646523177624 0.00832579005509615 0.00826011598110199 0.00759589159861207 0.00800738204270601 0.00827436801046133 0.00850967969745398 0.00803695525974035 0.00859370641410351 0.00757377874106169 0.00678808754310012 0.00810458604246378 0.00828907825052738 0.0073024220764637 0.00828505866229534 0.00829954538494349 0.00789687223732471 0.00625459849834442 0.00735813518986106 0.00677822157740593 0.00603437423706055 0.00656507024541497 0.00717219989746809 0.00768232485279441 0.00599283492192626 0.00739502254873514 0.00717072654515505 0.00757684791460633 0.00703901331871748 0.00658791046589613 0.00659507792443037 0.00577279180288315 0.00665358593687415 0.00633173156529665 0.00557167362421751 0.00851421989500523 |
| 56 | |
| 57 | 0.806104 2 2 5000000 700000000.000000 20 256 --- 256 0.00689565530046821 0.00628861784934998 0.00648185843601823 0.00669795507565141 0.00584999099373817 0.00637592282146215 0.00665496429428458 0.00677516451105475 0.00625768397003412 0.00584975723177195 0.0060897353105247 0.00563886109739542 0.00706819351762533 0.00657628104090691 0.00634182989597321 0.00633346568793058 0.0062954961322248 0.00681345677003264 0.00627884548157454 0.00565372034907341 0.00675516203045845 0.00734227616339922 0.00573072256520391 0.0063943974673748 0.00608528079465032 0.00676710763946176 0.00617225747555494 0.00553606916218996 0.00660644983872771 0.0063962722197175 0.00743097579106688 0.00628956127911806 0.00731373578310013 0.00724115874618292 0.00646150950342417 0.0066513828933239 0.00803750939667225 0.00523182982578874 0.00641514360904694 0.00818850565701723 0.00636473763734102 0.00712296459823847 0.00614004954695702 0.00618369597941637 0.00591028016060591 0.00637322664260864 0.00655190274119377 0.00639662798494101 0.00541317230090499 0.00741449510678649 0.00761738698929548 0.0070836590602994 0.00605544168502092 0.00635870546102524 0.00694706430658698 0.00656211003661156 0.00666100438684225 0.00627775583416224 0.0116550819948316 0.0100514981895685 0.00824615824967623 0.00756618101149797 0.0078535033389926 0.0101745296269655 0.00904152821749449 0.00695109087973833 0.00740401213988662 0.00704846531152725 0.0077576725743711 0.0071131675504148 0.00850622821599245 0.00610636034980416 0.00661058444529772 0.00847268849611282 0.007558090146631 0.00893115531653166 0.00833071861416101 0.00715811923146248 0.00823779869824648 0.0089316014200449 0.00595288490876555 0.00747732911258936 0.00831372570246458 0.00861002039164305 0.00799854192882776 0.00973799638450146 0.00850083213299513 0.00773866334930062 0.00879448000341654 0.00807567313313484 0.0105824302881956 0.00920506287366152 0.00788669660687447 0.00895833969116211 0.0112238116562366 0.0100678941234946 0.0103527856990695 0.0104455724358559 0.012177424505353 0.0112529918551445 0.0102290874347091 0.0135061638429761 0.0147446822375059 0.018596475943923 0.0414362847805023 0.114830479025841 0.025530856102705 0.0190154518932104 0.0155481668189168 0.0143186058849096 0.0138343144208193 0.014024967327714 0.0143188638612628 0.0134244654327631 0.0132367964833975 0.0148129807785153 0.0141275357455015 0.0152805019170046 0.0149390399456024 0.0163573995232582 0.0169974658638239 0.0169846024364233 0.0175251290202141 0.0187166798859835 0.0194499474018812 0.0228170566260815 0.0220983885228634 0.0203606244176626 0.0218033343553543 0.0210654400289059 0.0256397034972906 0.0221499484032393 0.0251883305609226 0.0291288048028946 0.0301742143929005 0.0299053974449635 0.031312745064497 0.0336895957589149 0.0370108000934124 0.0393577739596367 0.0433414280414581 0.0476785935461521 0.0539706349372864 0.0592275373637676 0.0678910464048386 0.0782939940690994 0.0912498533725739 0.113576114177704 0.150473922491074 0.212990492582321 0.384159237146378 1.74912762641907 0.685468077659607 0.285425901412964 0.179363623261452 0.131207302212715 0.104474768042564 0.0858906656503677 0.074637807905674 0.0646835714578629 0.0561635978519917 0.050263948738575 0.0462885685265064 0.0413284674286842 0.0397013314068317 0.0344642288982868 0.0322929508984089 0.0317045971751213 0.0295128636062145 0.0287306308746338 0.0286615248769522 0.023568470031023 0.0228897500783205 0.0226257108151913 0.0222484599798918 0.022429320961237 0.0206066872924566 0.0198463629931211 0.020149877294898 0.017288027331233 0.0161423590034246 0.0164039433002472 0.0163881666958332 0.0164083652198315 0.0157671608030796 0.0150078013539314 0.0146695794537663 0.0149738965556026 0.0142870601266623 0.0128184454515576 0.0130452159792185 0.0135776726529002 0.0117092151194811 0.0125469844788313 0.0118800457566977 0.0131193473935127 0.0124220326542854 0.0114703755825758 0.0109820328652859 0.011516802944243 0.0124680511653423 0.0113629531115294 0.0102917654439807 0.0101364348083735 0.00984693318605423 0.0115289557725191 0.0102153364568949 0.0101874768733978 0.00997439958155155 0.00883135385811329 0.0104001071304083 0.00914312619715929 0.00772677874192595 0.0100395102053881 0.00981313176453114 0.00869345106184483 0.00866962410509586 0.0086707565933466 0.00890628155320883 0.00784013234078884 0.00858987402170897 0.00826080795377493 0.00816309545189142 0.00844899006187916 0.00860675703734159 0.00816098414361477 0.00893862452358007 0.00668511306867003 0.00604773685336113 0.00760708004236221 0.00612658727914095 0.00698500219732523 0.00720309559255838 0.00738290185108781 0.00822578091174364 0.00712159927934408 0.00688611064106226 0.00610087253153324 0.00795015413314104 0.00696648936718702 0.00737108662724495 0.00663621257990599 0.00606435863301158 0.0070930584333837 0.00753137096762657 0.00686082383617759 0.00658690463751554 0.00619596661999822 0.00581462075933814 0.00712865078821778 0.00663717556744814 0.0064032943919301 0.00607451144605875 0.00634610885754228 0.00608755415305495 0.00666977930814028 |
| 58 | |
| 59 | }}} |
| 60 | |
| 61 | === Performing the experiment using OEDL === |
| 62 | |
| 63 | OEDL can be used to automatically perform the experiment. The OEDL code for the experiment is shown below. |
| 64 | |
| 65 | {{{ |
| 66 | defProperty('rx_freq', "800e6", "") |
| 67 | defProperty('rx_rate', "5e6", "") |
| 68 | defProperty('rx_gain', "20", "") |
| 69 | defProperty('recv_oml_output_type', "vector", "") |
| 70 | defProperty('recv_oml_servername', "file", "") |
| 71 | defProperty('tx_freq', "798e6", "") |
| 72 | defProperty('tx_rate', "5e6", "") |
| 73 | defProperty('tx_gain', "20", "") |
| 74 | defProperty('tx_module', "foo", "") # using a random name for an unexisting module |
| 75 | defProperty('rx_module', "foo", "") # so that no module is started, but it can be added later by setting this property |
| 76 | defProperty('del_rx_module', "foo", "") |
| 77 | |
| 78 | require './wiserd.rb' |
| 79 | |
| 80 | defGroup('sender', "node1-1") do |node| |
| 81 | node.addApplication("test:app:wiserd") do |app| |
| 82 | app.setProperty('--uhd_tx_freq', property.tx_freq) |
| 83 | app.setProperty('--uhd_tx_rate', property.tx_rate) |
| 84 | app.setProperty('--uhd_tx_gain', property.tx_gain) |
| 85 | app.setProperty('--addmodule', property.tx_module) |
| 86 | end |
| 87 | end |
| 88 | |
| 89 | defGroup('receiver', "node1-2") do |node| |
| 90 | node.addApplication("test:app:wiserd") do |app| |
| 91 | app.setProperty('--uhd_rx_freq', property.rx_freq) |
| 92 | app.setProperty('--uhd_rx_rate', property.rx_rate) |
| 93 | app.setProperty('--uhd_rx_gain', property.rx_gain) |
| 94 | app.setProperty('--recv_oml_output_type', property.recv_oml_output_type) |
| 95 | app.setProperty('--recv_oml_servername', property.recv_oml_servername) |
| 96 | app.setProperty('--addmodule', property.rx_module) |
| 97 | app.setProperty('--delmodule', property.del_rx_module) |
| 98 | end |
| 99 | end |
| 100 | |
| 101 | onEvent(:ALL_UP_AND_INSTALLED) do |event| |
| 102 | wait 10 |
| 103 | info "Starting the Receiver" |
| 104 | group("receiver").startApplications |
| 105 | info "Starting the Sender" |
| 106 | group("sender").startApplications |
| 107 | wait 8 |
| 108 | property.tx_module = "waveform" |
| 109 | property.rx_module = "fftmovingavgoml" |
| 110 | for i in 798..802 |
| 111 | property.tx_freq = "#{i}e6" |
| 112 | wait 1 |
| 113 | end |
| 114 | property.del_rx_module = "fftmovingavgoml" |
| 115 | group("sender").stopApplications |
| 116 | group("receiver").stopApplications |
| 117 | Experiment.done |
| 118 | end |
| 119 | }}} |
| 120 | |
| 121 | This experiment consists of a receiver centered at 800 MHz, with the bandwidth of 5 MHz, and the transmitter that runs for 5 seconds, transmitting a SINE waveform centered at frequencies of 798, 799, 800, 801 and 802 MHz for 1 second each. The code needs to be saved in a file named ''experiment.rb''. It's assumed that the [http://www.orbit-lab.org/attachment/wiki/Tutorials/k0SDR/Tutorial05/wiserd.rb Wiserd application definition] for OEDL is available in the file named ''wiserd.rb''. After imaging the nodes and making sure they are turned on, the experiment can be run using the command |
| 122 | |
| 123 | {{{ |
| 124 | omf exec experiment.rb |
| 125 | }}} |
| 126 | |
| 127 | When the experiment is finished, the receiver will save the results in a ''file'' located at the ''/'' directory. The file can then be transferred to a local machine for further processing. For example, the results can be plotted using a simple octave script shown below: |
| 128 | |
| 129 | {{{ |
| 130 | w = dlmread('file', ' ', 10, 1); |
| 131 | |
| 132 | i = 1; |
| 133 | while (i <= size(w,1)) |
| 134 | if (max(abs(w(i, :))) == 0) |
| 135 | w(i,:) = []; |
| 136 | end |
| 137 | i = i + 1; |
| 138 | end |
| 139 | imagesc(10*log(w/1000.0)) |
| 140 | }}} |
| 141 | |
| 142 | For the described experiment, octave will then produce the image shown below. |
| 143 | |
| 144 | [[Image(octave_plot.jpg)]] |