root/ResearchApps/PHY/WARPLAB/WARPLab_SISO_MIMO2x2/M_Code/warplab_siso_example_TxRxTwoWay_WorkshopExercise_Solution.m
| Revision 839, 25.2 kB (checked in by MelissaDuarte, 4 months ago) |
|---|
| Line | |
|---|---|
| 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | % Two-Way transmission and reception of data using Warplab (SISO configuration) |
| 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4 | % To run this code the boards must be programmed with the |
| 5 | % warplab_siso_v02.bit bitstream |
| 6 | |
| 7 | % Use Warplab for two-way communication between two nodes. First node A |
| 8 | % will transmit to node B and then node B will transmit to node A. |
| 9 | |
| 10 | % The specific steps implemented in this script are the following |
| 11 | |
| 12 | % 0. Initializaton and definition of parameters |
| 13 | % 1. Generate the vector of samples that node A will transmit to node B and |
| 14 | % the vector of samples that node B will transmit to node A, then download |
| 15 | % the samples to the Warp boards (Sample Frequency is 40MHz) |
| 16 | % 2. Prepare boards for transmission and reception from node A to node B |
| 17 | % and send trigger to start transmission and reception (trigger is the SYNC |
| 18 | % packet) |
| 19 | % 3. Disable the radios |
| 20 | % 4. Prepare boards for transmission and reception from node B to node A |
| 21 | % and send trigger to start transmission and reception (trigger is the SYNC |
| 22 | % packet) |
| 23 | % 5. Disable the radios |
| 24 | % 6. Read the received samples from the Warp boards |
| 25 | % 7. Reset the boards and close sockets |
| 26 | % 8. Plot the transmitted and received data |
| 27 | |
| 28 | % In this lab exercise you will write a matlab script that implements the |
| 29 | % nine steps above. Part of the code is provided, some part of the code you |
| 30 | % will write. Read the code below and fill in with your code wherever you |
| 31 | % are asked to do so. |
| 32 | |
| 33 | % NOTE: To avoid conflict with other groups using the boards, please test |
| 34 | % the code you write in this script in any of the following three ways: |
| 35 | % |
| 36 | % Option 1. Run this script from matlab's Command Window by entering the |
| 37 | % name of the script (enter warplab_example_TxRx_WorkshopExercise in |
| 38 | % matlab's Command Window). |
| 39 | % Option 2. In the menu bar go to Debug and select Run. If there |
| 40 | % are errors in the code, error messages will appear in the Command Window. |
| 41 | % Option 3. Press F5. If the are errors in the code, error messages will |
| 42 | % appear in the Command Window. |
| 43 | % |
| 44 | % DO NOT USE the Evaluate selection option and DO NOT run the script by |
| 45 | % sections. To test any change, always run the whole script by following |
| 46 | % any of the three options above. |
| 47 | |
| 48 | try, |
| 49 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 50 | % Code to avoid conflict between users, only needed for the workshop, go to |
| 51 | % step 0 below to start the initialization and definition of parameters |
| 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 53 | fid = fopen('c:\boards_lock.txt'); |
| 54 | |
| 55 | if(fid > -1) |
| 56 | fclose('all'); |
| 57 | errordlg('Boards already in use - Please try again!'); |
| 58 | return; |
| 59 | end |
| 60 | |
| 61 | !echo > c:\boards_lock.txt |
| 62 | |
| 63 | |
| 64 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 65 | % 0. Initializaton and definition of parameters |
| 66 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 67 | %Load some global definitions (packet types, etc.) |
| 68 | warplab_defines |
| 69 | |
| 70 | % Create Socket handles and intialize nodes |
| 71 | [socketHandles, packetNum] = warplab_initialize; |
| 72 | |
| 73 | %Separate the socket handles for easier access |
| 74 | % The first socket handle is always the magic SYNC |
| 75 | % The rest can be arranged in any combination of Tx and Rx |
| 76 | udp_Sync = socketHandles(1); |
| 77 | udp_nodeA = socketHandles(2); |
| 78 | udp_nodeB = socketHandles(3); |
| 79 | |
| 80 | % Define the warplab options (parameters) |
| 81 | CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14] |
| 82 | TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset] |
| 83 | TransMode = 0; %Transmission mode; in [0:1] |
| 84 | % 0: Single Transmission |
| 85 | % 1: Continuous Transmission. Tx board will continue |
| 86 | % transmitting the vector of samples until the user manually |
| 87 | % disables the transmitter. |
| 88 | CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14] |
| 89 | TxGainBB = 3; %Tx Baseband Gain in [0:3] |
| 90 | TxGainRF = 40; %Tx RF Gain in [0:63] |
| 91 | RxGainBB = 15; %Rx Baseband Gain in [0:31] |
| 92 | RxGainRF = 1; %Rx RF Gain in [1:3] |
| 93 | |
| 94 | % Define the options vector; the order of options is set by the FPGA's code |
| 95 | % (C code) |
| 96 | optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)]; |
| 97 | % Send options vector to the nodes |
| 98 | warplab_setOptions(socketHandles,optionsVector); |
| 99 | |
| 100 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 101 | % 1. Generate the vector of samples that node A will transmit to node B and |
| 102 | % the vector of samples that node B will transmit to node A, then download |
| 103 | % the samples to the Warp boards (Sample Frequency is 40MHz) |
| 104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 105 | % Create time vector. |
| 106 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; |
| 107 | |
| 108 | %-------------------------------------------------------------------------% |
| 109 | % USER CODE HERE |
| 110 | |
| 111 | % Create a signal to transmit from node A to node B. |
| 112 | % The signal must be a row vector. The Signal is a function of the time |
| 113 | % vector 't'. The signal can be real or complex, the only constraint is |
| 114 | % that the amplitude of the real part must be in [-1:1] and the amplitude |
| 115 | % of the imaginary part must be in [-1:1]. |
| 116 | |
| 117 | % Store the signal to transmit in a variable called |
| 118 | % TxDataAB (TxDataAB = your signal from node A to node B) |
| 119 | |
| 120 | % Create a signal to transmit from node A to node B |
| 121 | TxDataAB = exp(t*j*2*pi*1e6); %Signal must be a row vector. The signal can |
| 122 | % be real or complex, the only constraint is that the amplitude of the real |
| 123 | % part must be in [-1:1] and the amplitude of the imaginary part must be |
| 124 | % in [-1:1] |
| 125 | %-------------------------------------------------------------------------% |
| 126 | |
| 127 | %-------------------------------------------------------------------------% |
| 128 | % USER CODE HERE |
| 129 | |
| 130 | % Use the 'warplab_writeSMWO' function to download to node A the samples to |
| 131 | % be transmitted from node A to B ('TxDataAB' vector). The |
| 132 | % 'warplab_writeSMWO' function has been used in all the previous exercises. |
| 133 | |
| 134 | % Hints: |
| 135 | |
| 136 | % 1. The first argument of the 'warplab_writeSMWO' function identifies the |
| 137 | % node to which samples will be downloaded to. The handle for node A is |
| 138 | % 'udp_nodeA' so use 'udp_nodeA' as the first argument. |
| 139 | |
| 140 | % 2. The second argument of the 'warplab_writeSMWO' function is the |
| 141 | % vector of samples to be downloaded, which in this case is the 'TxDataAB' |
| 142 | % vector. |
| 143 | |
| 144 | % 3. The third argument of 'warplab_writeSMWO' is RADIO2_TXDATA, |
| 145 | % RADIO2_TXDATA is defined in 'warplab_defines'. RADIO2_TXDATA can be |
| 146 | % understood as an id that identifies the transmitter buffer. |
| 147 | |
| 148 | % 4. In sumary, the first argument of the 'warplab_writeSMWO' identifies |
| 149 | % the node and the third argument identifies which buffer in the node will |
| 150 | % the samples be downloaded to. The second argument is the vector of |
| 151 | % samples to download. |
| 152 | |
| 153 | % Download the samples to be transmitted |
| 154 | warplab_writeSMWO(udp_nodeA, TxDataAB, RADIO2_TXDATA); % Download samples to node A |
| 155 | %-------------------------------------------------------------------------% |
| 156 | |
| 157 | %-------------------------------------------------------------------------% |
| 158 | % USER CODE HERE |
| 159 | |
| 160 | % Create a signal to transmit from node B to node A. |
| 161 | % The signal must be a row vector. The Signal is a function of the time |
| 162 | % vector 't'. The signal can be real or complex, the only constraint is |
| 163 | % that the amplitude of the real part must be in [-1:1] and the amplitude |
| 164 | % of the imaginary part must be in [-1:1]. |
| 165 | |
| 166 | % Store the signal to transmit in a variable called |
| 167 | % TxDataBA (TxDataBA = your signal from node B to node A) |
| 168 | |
| 169 | % Create a signal to transmit from node B to node A |
| 170 | TxDataBA = linspace(0,1,TxLength).*exp(t*j*2*pi*5e6); |
| 171 | % Signal must be a row vector. The signal can be real or complex, |
| 172 | % the only constraint is that the amplitude of the real part must be in |
| 173 | % [-1:1] and the amplitude of the imaginary part must be in [-1:1] |
| 174 | %-------------------------------------------------------------------------% |
| 175 | |
| 176 | %-------------------------------------------------------------------------% |
| 177 | % USER CODE HERE |
| 178 | |
| 179 | % Use the 'warplab_writeSMWO' function to download to node B the samples to |
| 180 | % be transmitted from node B to A ('TxDataBA' vector). The |
| 181 | % 'warplab_writeSMWO' function has been used in all the previous exercises. |
| 182 | |
| 183 | % Hints: |
| 184 | |
| 185 | % 1. The first argument of the 'warplab_writeSMWO' function identifies the |
| 186 | % node to which samples will be downloaded to. The handle for node B is |
| 187 | % 'udp_nodeB' so use 'udp_nodeB' as the first argument. |
| 188 | |
| 189 | % 2. The second argument of the 'warplab_writeSMWO' function is the |
| 190 | % vector of samples to be downloaded, which in this case is the 'TxDataBA' |
| 191 | % vector. |
| 192 | |
| 193 | % 3. The third argument of 'warplab_writeSMWO' is RADIO2_TXDATA, |
| 194 | % RADIO2_TXDATA is defined in 'warplab_defines'. RADIO2_TXDATA can be |
| 195 | % understood as an id that identifies the transmitter buffer. |
| 196 | |
| 197 | % 4. In sumary, the first argument of the 'warplab_writeSMWO' identifies |
| 198 | % the node and the third argument identifies which buffer in the node will |
| 199 | % the samples be downloaded to. The second argument is the vector of |
| 200 | % samples to download. |
| 201 | |
| 202 | warplab_writeSMWO(udp_nodeB, TxDataBA, RADIO2_TXDATA); % Download samples to node B |
| 203 | %-------------------------------------------------------------------------% |
| 204 | |
| 205 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 206 | % 2. Prepare boards for transmission and reception from node A to node B |
| 207 | % and send trigger to start transmission and reception (trigger is the SYNC |
| 208 | % packet) |
| 209 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 210 | |
| 211 | %-------------------------------------------------------------------------% |
| 212 | % USER CODE HERE |
| 213 | |
| 214 | % Enable the transmitter radio path in node A by sending the RADIO2_TXEN |
| 215 | % command to node A using the 'warplab_sendCmd' function. This function has |
| 216 | % been used in all the previous exercises. |
| 217 | |
| 218 | % Hints: |
| 219 | |
| 220 | % 1. The first argument of the 'warplab_sendCmd' function identifies the |
| 221 | % node to which the command will be sent. The handle for node A is |
| 222 | % 'udp_nodeA' so use 'udp_nodeA' as the first argument. |
| 223 | |
| 224 | % 2. The second argument of the 'warplab_sendCmd' function identifies the |
| 225 | % instruction or command to be sent. In this case, the command to send is |
| 226 | % the RADIO2_TXEN command defined in 'warplab_defines'. |
| 227 | |
| 228 | % 3. The third argument of the 'warplab_sendCmd' command is a field that |
| 229 | % is not used at the moment, it may be used in future versions of WARPLab |
| 230 | % to keep track of packets. Use 'packetNum' as the third argument of the |
| 231 | % 'warplab_sendCmd' command. |
| 232 | |
| 233 | % Enable transmitter radio path in node A |
| 234 | warplab_sendCmd(udp_nodeA, RADIO2_TXEN, packetNum); |
| 235 | %-------------------------------------------------------------------------% |
| 236 | |
| 237 | %-------------------------------------------------------------------------% |
| 238 | % USER CODE HERE |
| 239 | |
| 240 | % Enable the receiver radio path in node B by sending the RADIO2_RXEN |
| 241 | % command to node B using the 'warplab_sendCmd' function. This function has |
| 242 | % been used in all the previous exercises. |
| 243 | |
| 244 | % Hints: |
| 245 | |
| 246 | % 1. The first argument of the 'warplab_sendCmd' function identifies the |
| 247 | % node to which the command will be sent. The handle for node B is |
| 248 | % 'udp_nodeB' so use 'udp_nodeB' as the first argument. |
| 249 | |
| 250 | % 2. The second argument of the 'warplab_sendCmd' function identifies the |
| 251 | % instruction or command to be sent. In this case, the command to send is |
| 252 | % the RADIO2_RXEN command defined in 'warplab_defines'. |
| 253 | |
| 254 | % 3. The third argument of the 'warplab_sendCmd' command is a field that |
| 255 | % is not used at the moment, it may be used in future versions of WARPLab |
| 256 | % to keep track of packets. Use 'packetNum' as the third argument of the |
| 257 | % 'warplab_sendCmd' command. |
| 258 | |
| 259 | % Enable receiver radio path in node B |
| 260 | warplab_sendCmd(udp_nodeB, RADIO2_RXEN, packetNum); |
| 261 | %-------------------------------------------------------------------------% |
| 262 | |
| 263 | %-------------------------------------------------------------------------% |
| 264 | % USER CODE HERE |
| 265 | |
| 266 | % Prime transmitter state machine in node A by sending the TX_START command |
| 267 | % to node A using the 'warplab_sendCmd' function. This function has |
| 268 | % been used in all the previous exercises and it is described in the Hints |
| 269 | % above. |
| 270 | |
| 271 | % Node A will start waiting for the SYNC packet as soon as it receives the |
| 272 | % TX_START command. Transmission from node A will be triggered when node A |
| 273 | % receives the SYNC packet. |
| 274 | |
| 275 | % Prime transmitter state machine in node A. Node A will be waiting for |
| 276 | % the SYNC packet. Transmission will be triggered when node A receives |
| 277 | % the SYNC packet. |
| 278 | warplab_sendCmd(udp_nodeA, TX_START, packetNum); |
| 279 | %-------------------------------------------------------------------------% |
| 280 | |
| 281 | %-------------------------------------------------------------------------% |
| 282 | % USER CODE HERE |
| 283 | |
| 284 | % Prime receiver state machine in node B by sending the RX_START command |
| 285 | % to node B using the 'warplab_sendCmd' function. This function has |
| 286 | % been used in all the previous exercises and it is described in the Hints |
| 287 | % above. |
| 288 | |
| 289 | % Node B will start waiting for the SYNC packet as soon as it receives the |
| 290 | % RX_START command. Capture on node B will be triggered when node B |
| 291 | % receives the SYNC packet. |
| 292 | |
| 293 | % Prime receiver state machine in node B. Node B will be waiting for |
| 294 | % the SYNC packet. Capture will be triggered when node B receives |
| 295 | % the SYNC packet. |
| 296 | warplab_sendCmd(udp_nodeB, RX_START, packetNum); |
| 297 | %-------------------------------------------------------------------------% |
| 298 | |
| 299 | % Send the SYNC packet |
| 300 | warplab_sendSync(udp_Sync) |
| 301 | |
| 302 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 303 | % 3. Disable the radios |
| 304 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 305 | |
| 306 | %-------------------------------------------------------------------------% |
| 307 | % USER CODE HERE |
| 308 | |
| 309 | % Disable the receiver radio path in node B by sending the RADIO2_RXDIS |
| 310 | % command to node B using the 'warplab_sendCmd' function. This function has |
| 311 | % been used in all the previous exercises and it is described in the Hints |
| 312 | % above. |
| 313 | |
| 314 | % Disable the receiver |
| 315 | warplab_sendCmd(udp_nodeB, RADIO2_RXDIS, packetNum); |
| 316 | %-------------------------------------------------------------------------% |
| 317 | |
| 318 | %-------------------------------------------------------------------------% |
| 319 | % USER CODE HERE |
| 320 | |
| 321 | % Disable the transmitter radio path in node A by sending the RADIO2_TXDIS |
| 322 | % command to node A using the 'warplab_sendCmd' function. This function has |
| 323 | % been used in all the previous exercises and it is described in the Hints |
| 324 | % above. |
| 325 | |
| 326 | % Disable the transmitter |
| 327 | warplab_sendCmd(udp_nodeA, RADIO2_TXDIS, packetNum); |
| 328 | %-------------------------------------------------------------------------% |
| 329 | |
| 330 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 331 | % 4. Prepare boards for transmission and reception from node B to node A |
| 332 | % and send trigger to start transmission and reception (trigger is the SYNC |
| 333 | % packet) |
| 334 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 335 | |
| 336 | %-------------------------------------------------------------------------% |
| 337 | % USER CODE HERE |
| 338 | |
| 339 | % Enable the transmitter radio path in node B by sending the RADIO2_TXEN |
| 340 | % command to node B using the 'warplab_sendCmd' function. This function has |
| 341 | % been used in all the previous exercises. |
| 342 | |
| 343 | % Enable transmitter radio path in node B |
| 344 | warplab_sendCmd(udp_nodeB, RADIO2_TXEN, packetNum); |
| 345 | %-------------------------------------------------------------------------% |
| 346 | |
| 347 | %-------------------------------------------------------------------------% |
| 348 | % USER CODE HERE |
| 349 | |
| 350 | % Enable the receiver radio path in node A by sending the RADIO2_RXEN |
| 351 | % command to node A using the 'warplab_sendCmd' function. This function has |
| 352 | % been used in all the previous exercises. |
| 353 | |
| 354 | % Enable receiver radio path in node A |
| 355 | warplab_sendCmd(udp_nodeA, RADIO2_RXEN, packetNum); |
| 356 | %-------------------------------------------------------------------------% |
| 357 | |
| 358 | %-------------------------------------------------------------------------% |
| 359 | % USER CODE HERE |
| 360 | |
| 361 | % Prime transmitter state machine in node B by sending the TX_START command |
| 362 | % to node B using the 'warplab_sendCmd' function. This function has |
| 363 | % been used in all the previous exercises and it is described in the Hints |
| 364 | % above. |
| 365 | |
| 366 | % Node B will start waiting for the SYNC packet as soon as it receives the |
| 367 | % TX_START command. Transmission from node B will be triggered when node B |
| 368 | % receives the SYNC packet. |
| 369 | |
| 370 | % Prime transmitter state machine in node B. Node B will be waiting for |
| 371 | % the SYNC packet. Transmission will be triggered when node B receives |
| 372 | % the SYNC packet. |
| 373 | warplab_sendCmd(udp_nodeB, TX_START, packetNum); |
| 374 | %-------------------------------------------------------------------------% |
| 375 | |
| 376 | %-------------------------------------------------------------------------% |
| 377 | % USER CODE HERE |
| 378 | |
| 379 | % Prime receiver state machine in node A by sending the RX_START command |
| 380 | % to node A using the 'warplab_sendCmd' function. This function has |
| 381 | % been used in all the previous exercises and it is described in the Hints |
| 382 | % above. |
| 383 | |
| 384 | % Node A will start waiting for the SYNC packet as soon as it receives the |
| 385 | % RX_START command. Capture on node A will be triggered when node A |
| 386 | % receives the SYNC packet. |
| 387 | |
| 388 | % Prime receiver state machine in node A. Node A will be waiting for |
| 389 | % the SYNC packet. Capture will be triggered when node A receives |
| 390 | % the SYNC packet. |
| 391 | warplab_sendCmd(udp_nodeA, RX_START, packetNum); |
| 392 | %-------------------------------------------------------------------------% |
| 393 | |
| 394 | % Send the SYNC packet |
| 395 | warplab_sendSync(udp_Sync) |
| 396 | |
| 397 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 398 | % 5. Disable the radios |
| 399 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 400 | |
| 401 | %-------------------------------------------------------------------------% |
| 402 | % USER CODE HERE |
| 403 | |
| 404 | % Disable the receiver radio path in node A by sending the RADIO2_RXDIS |
| 405 | % command to node A using the 'warplab_sendCmd' function. This function has |
| 406 | % been used in all the previous exercises and it is described in the Hints |
| 407 | % above. |
| 408 | |
| 409 | % Disable the receiver |
| 410 | warplab_sendCmd(udp_nodeA, RADIO2_RXDIS, packetNum); |
| 411 | %-------------------------------------------------------------------------% |
| 412 | |
| 413 | %-------------------------------------------------------------------------% |
| 414 | % USER CODE HERE |
| 415 | |
| 416 | % Disable the transmitter radio path in node B by sending the RADIO2_TXDIS |
| 417 | % command to node B using the 'warplab_sendCmd' function. This function has |
| 418 | % been used in all the previous exercises and it is described in the Hints |
| 419 | % above. |
| 420 | |
| 421 | % Disable the transmitter |
| 422 | warplab_sendCmd(udp_nodeB, RADIO2_TXDIS, packetNum); |
| 423 | %-------------------------------------------------------------------------% |
| 424 | |
| 425 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 426 | % 6. Read the received samples from the Warp boards |
| 427 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 428 | |
| 429 | %-------------------------------------------------------------------------% |
| 430 | % USER CODE HERE |
| 431 | |
| 432 | % Read the samples received at node B (samples sent from A to B) using the |
| 433 | % 'warplab_readSMRO' function. This function was used in the |
| 434 | % previous exercises. Store the samples in a variable named 'RawRxDataAB' |
| 435 | |
| 436 | % Hints: |
| 437 | |
| 438 | % 1. The first argument of the 'warplab_readSMRO' function identifies the |
| 439 | % node from which samples will be read. The handle for node B is |
| 440 | % 'udp_nodeB' so use 'udp_nodeB' as the first argument. |
| 441 | |
| 442 | % 2. The second argument of 'warplab_readSMRO' is RADIO2_RXDATA, |
| 443 | % RADIO2_RXDATA is defined in 'warplab_defines'. RADIO2_RXDATA can be |
| 444 | % understood as an id that identifies the receiver buffer. |
| 445 | |
| 446 | % 3. The third argument of the 'warplab_readSMRO' function is the number of |
| 447 | % samples to read. For this exercise, the third argument of the 'warplab_readSMRO' |
| 448 | % function is equal to 'TxLength+CaptOffset' |
| 449 | |
| 450 | % 4. In sumary, the first argument of the 'warplab_readSMWO' identifies |
| 451 | % the node and the second argument identifies which buffer in the node will |
| 452 | % be read. The third argument is the number of samples to read. |
| 453 | |
| 454 | % Read back the received samples sent from A to B |
| 455 | [RawRxDataAB] = warplab_readSMRO(udp_nodeB, RADIO2_RXDATA, TxLength+CaptOffset); |
| 456 | %-------------------------------------------------------------------------% |
| 457 | |
| 458 | % Process the received samples to obtain meaningful data |
| 459 | [RxDataAB,RxOTRAB] = warplab_processRawRxData(RawRxDataAB); |
| 460 | % Read stored RSSI data corresponding to A to B transmission |
| 461 | [RawRSSIDataAB] = warplab_readSMRO(udp_nodeB, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8); |
| 462 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 463 | [RxRSSIAB] = warplab_processRawRSSIData(RawRSSIDataAB); |
| 464 | |
| 465 | %-------------------------------------------------------------------------% |
| 466 | % USER CODE HERE |
| 467 | |
| 468 | % Read the samples received at node A (samples sent from B to A) using the |
| 469 | % 'warplab_readSMRO' function. This function was used in the two |
| 470 | % previous exercises. Store the samples in a variable named 'RawRxDataBA' |
| 471 | |
| 472 | % Hints: |
| 473 | |
| 474 | % 1. The first argument of the 'warplab_readSMRO' function identifies the |
| 475 | % node from which samples will be read. The handle for node A is |
| 476 | % 'udp_nodeA' so use 'udp_nodeA' as the first argument. |
| 477 | |
| 478 | % 2. The second argument of 'warplab_readSMRO' is RADIO2_RXDATA, |
| 479 | % RADIO2_RXDATA is defined in 'warplab_defines'. RADIO2_RXDATA can be |
| 480 | % understood as an id that identifies the receiver buffer. |
| 481 | |
| 482 | % 3. The third argument of the 'warplab_readSMRO' function is the number of |
| 483 | % samples to read. For this exercise, the third argument of the 'warplab_readSMRO' |
| 484 | % function is equal to 'TxLength+CaptOffset' |
| 485 | |
| 486 | % 4. In sumary, the first argument of the 'warplab_readSMWO' identifies |
| 487 | % the node and the second argument identifies which buffer in the node will |
| 488 | % be read. The third argument is the number of samples to read. |
| 489 | |
| 490 | % Read back the received samples sent from B to A |
| 491 | [RawRxDataBA] = warplab_readSMRO(udp_nodeA, RADIO2_RXDATA, TxLength+CaptOffset); |
| 492 | %-------------------------------------------------------------------------% |
| 493 | |
| 494 | % Process the received samples to obtain meaningful data |
| 495 | [RxDataBA,RxOTRBA] = warplab_processRawRxData(RawRxDataBA); |
| 496 | % Read stored RSSI data corresponding to B to A transmission |
| 497 | [RawRSSIDataBA] = warplab_readSMRO(udp_nodeA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8); |
| 498 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 499 | [RxRSSIBA] = warplab_processRawRSSIData(RawRSSIDataBA); |
| 500 | |
| 501 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 502 | % 7. Reset the boards and close sockets |
| 503 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 504 | |
| 505 | %-------------------------------------------------------------------------% |
| 506 | % USER CODE HERE |
| 507 | |
| 508 | % Reset node A by sending the RX_DONEREADING command to node A using the |
| 509 | % 'warplab_sendCmd' function. When the node receives the RX_DONEREADING |
| 510 | % command it knows that the samples in the receiver buffer have been read |
| 511 | % and sets the node ready for a new capture. |
| 512 | |
| 513 | % Reset node A |
| 514 | warplab_sendCmd(udp_nodeA, RX_DONEREADING, packetNum); |
| 515 | %-------------------------------------------------------------------------% |
| 516 | |
| 517 | %-------------------------------------------------------------------------% |
| 518 | % USER CODE HERE |
| 519 | |
| 520 | % Reset node B by sending the RX_DONEREADING command to node B using the |
| 521 | % 'warplab_sendCmd' function. When the node receives the RX_DONEREADING |
| 522 | % command it knows that the samples in the receiver buffer have been read |
| 523 | % and sets the node ready for a new capture. |
| 524 | |
| 525 | % Reset node B |
| 526 | warplab_sendCmd(udp_nodeB, RX_DONEREADING, packetNum); |
| 527 | %-------------------------------------------------------------------------% |
| 528 | |
| 529 | % Close sockets |
| 530 | pnet('closeall'); |
| 531 | |
| 532 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 533 | % 5. Plot the transmitted and received data |
| 534 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 535 | % Plot data from A to B transmissio |
| 536 | figure; |
| 537 | subplot(2,2,1); |
| 538 | plot(real(TxDataAB)); |
| 539 | title('Tx I A to B'); |
| 540 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 541 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 542 | subplot(2,2,2); |
| 543 | plot(imag(TxDataAB)); |
| 544 | title('Tx Q A to B'); |
| 545 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 546 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 547 | subplot(2,2,3); |
| 548 | plot(real(RxDataAB)); |
| 549 | title('Rx I A to B'); |
| 550 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 551 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 552 | subplot(2,2,4); |
| 553 | plot(imag(RxDataAB)); |
| 554 | title('Rx Q A to B'); |
| 555 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 556 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 557 | |
| 558 | % Plot data from B to A transmission |
| 559 | figure; |
| 560 | subplot(2,2,1); |
| 561 | plot(real(TxDataBA)); |
| 562 | title('Tx I B to A'); |
| 563 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 564 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 565 | subplot(2,2,2); |
| 566 | plot(imag(TxDataBA)); |
| 567 | title('Tx Q B to A'); |
| 568 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 569 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 570 | subplot(2,2,3); |
| 571 | plot(real(RxDataBA)); |
| 572 | title('Rx I B to A'); |
| 573 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 574 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 575 | subplot(2,2,4); |
| 576 | plot(imag(RxDataBA)); |
| 577 | title('Rx Q B to A'); |
| 578 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 579 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 580 | |
| 581 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 582 | % Code to avoid conflict between users, only needed for the workshop |
| 583 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 584 | pnet('closeall'); |
| 585 | !del c:\boards_lock.txt |
| 586 | catch, |
| 587 | % Close sockets |
| 588 | pnet('closeall'); |
| 589 | !del c:\boards_lock.txt |
| 590 | lasterr |
| 591 | end |
Note: See TracBrowser
for help on using the browser.