[1455] | 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 2 | % Transmitting and Receiving Data using WARPLab (2x2 MIMO configuration) |
---|
| 3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 4 | % The specific steps implemented in this script are the following |
---|
| 5 | |
---|
| 6 | % 0. Initializaton and definition of parameters |
---|
| 7 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
| 8 | % WARP board (Sample Frequency is 40MHz) |
---|
| 9 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
| 10 | % start transmission and reception (trigger is the SYNC packet) |
---|
| 11 | % 3. Read the received samples from the Warp board |
---|
| 12 | % 4. Reset and disable the boards |
---|
| 13 | % 5. Plot the transmitted and received data and close sockets |
---|
| 14 | |
---|
| 15 | % In this lab exercise you will write a matlab script that implements the |
---|
| 16 | % six steps above. Part of the code is provided, some part of the code you |
---|
| 17 | % will write. Read the code below and fill in with your code wherever you |
---|
| 18 | % are asked to do so. |
---|
| 19 | |
---|
| 20 | % NOTE: To avoid conflict with other groups using the boards, please test |
---|
| 21 | % the code you write in this script in any of the following three ways: |
---|
| 22 | % |
---|
| 23 | % Option 1. Run this script from MATLAB's Command Window by entering the |
---|
| 24 | % name of the script (enter warplab_mimo_2x2_example_TxRx_WorkshopExercise |
---|
| 25 | % in matlab's Command Window). |
---|
| 26 | % Option 2. In the menu bar go to Debug and select Run. If there |
---|
| 27 | % are errors in the code, error messages will appear in the Command Window. |
---|
| 28 | % Option 3. Press F5. If the are errors in the code, error messages will |
---|
| 29 | % appear in the Command Window. |
---|
| 30 | % |
---|
| 31 | % DO NOT USE the Evaluate selection option and DO NOT run the script by |
---|
| 32 | % sections. To test any change, always run the whole script by following |
---|
| 33 | % any of the three options above. |
---|
| 34 | |
---|
| 35 | try, |
---|
| 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 37 | % Code to avoid conflict between users, only needed for the workshop, go to |
---|
| 38 | % step 0 below to start the initialization and definition of parameters |
---|
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 40 | % fid = fopen('c:\boards_lock.txt'); |
---|
| 41 | % |
---|
| 42 | % if(fid > -1) |
---|
| 43 | % fclose('all'); |
---|
| 44 | % errordlg('Boards already in use - Please try again!'); |
---|
| 45 | % return; |
---|
| 46 | % end |
---|
| 47 | % |
---|
| 48 | % !echo > c:\boards_lock.txt |
---|
| 49 | |
---|
| 50 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 51 | % 0. Initializaton and definition of parameters |
---|
| 52 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 53 | %Load some global definitions (packet types, etc.) |
---|
| 54 | warplab_defines |
---|
| 55 | |
---|
| 56 | % Create Socket handles and intialize nodes |
---|
| 57 | [socketHandles, packetNum] = warplab_initialize; |
---|
| 58 | |
---|
| 59 | % Separate the socket handles for easier access |
---|
| 60 | % The first socket handle is always the magic SYNC |
---|
| 61 | % The rest of the handles are the handles to the WARP nodes |
---|
| 62 | udp_Sync = socketHandles(1); |
---|
| 63 | udp_node1 = socketHandles(2); |
---|
| 64 | udp_node2 = socketHandles(3); |
---|
| 65 | |
---|
| 66 | % Define WARPLab parameters. |
---|
| 67 | %-------------------------------------------------------------------------% |
---|
| 68 | % USER CODE HERE |
---|
| 69 | |
---|
| 70 | % Create the following variables and assign them valid values: |
---|
| 71 | |
---|
| 72 | % TxDelay: Number of noise samples per Rx capture. In [0:2^14] |
---|
| 73 | % TxLength: Length of transmission. In [0:2^14-1-TxDelay] |
---|
| 74 | % TxMode: Transmission mode. In [0:1] |
---|
| 75 | % 0: Single Transmission |
---|
| 76 | % 1: Continuous Transmission. Tx board will continue |
---|
| 77 | % transmitting the vector of samples until the user manually |
---|
| 78 | % disables the transmitter. |
---|
| 79 | % For this exercise set TxMode = 0; |
---|
| 80 | % CarrierChannel: Channel in the 2.4 GHz band. In [1:14] |
---|
| 81 | % Node1_Radio2_TxGain_BB: Tx Baseband Gain. In [0:3] |
---|
| 82 | % Node1_Radio2_TxGain_RF: Tx RF Gain. In [0:63] |
---|
| 83 | % Node1_Radio3_TxGain_BB: Tx Baseband Gain. In [0:3] |
---|
| 84 | % Node1_Radio3_TxGain_RF: Tx RF Gain. In [0:63] |
---|
| 85 | % Node2_Radio2_RxGain_BB: Rx Baseband Gain. In [0:31] |
---|
| 86 | % Node2_Radio2_RxGain_RF: Rx RF Gain. In [1:3] |
---|
| 87 | % Node2_Radio3_RxGain_BB: Rx Baseband Gain. In [0:31] |
---|
| 88 | % Node2_Radio3_RxGain_RF: Rx RF Gain. In [1:3] |
---|
| 89 | % % Note: For this experiment node 1 will be set as the transmitter and node |
---|
| 90 | % 2 will be set as the receiver (this is done later in the code), hence, |
---|
| 91 | % there is no need to define receive gains for node1 and there is no |
---|
| 92 | % need to define transmitter gains for node2. |
---|
| 93 | |
---|
| 94 | %-------------------------------------------------------------------------% |
---|
| 95 | |
---|
| 96 | % Download the WARPLab parameters to the WARP nodes. |
---|
| 97 | % The nodes store the TxDelay, TxLength, and TxMode parameters in |
---|
| 98 | % registers defined in the WARPLab sysgen model. The nodes set radio |
---|
| 99 | % related parameters CarrierChannel, TxGains, and RxGains, using the |
---|
| 100 | % radio controller functions. |
---|
| 101 | |
---|
| 102 | % The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter; |
---|
| 103 | % the receiver doesn't require knowledge of these parameters (the receiver |
---|
| 104 | % will always capture 2^14 samples). For this exercise node 1 will be set as |
---|
| 105 | % the transmitter (this is done later in the code). Since TxDelay, TxLength and |
---|
| 106 | % TxMode are only required at the transmitter we download the TxDelay, TxLength and |
---|
| 107 | % TxMode parameters only to the transmitter node (node 1). |
---|
| 108 | warplab_writeRegister(udp_node1,TX_DELAY,TxDelay); |
---|
| 109 | warplab_writeRegister(udp_node1,TX_LENGTH,TxLength); |
---|
| 110 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
| 111 | % The CarrierChannel parameter must be downloaded to all nodes |
---|
| 112 | warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel); |
---|
| 113 | warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel); |
---|
| 114 | |
---|
| 115 | %-------------------------------------------------------------------------% |
---|
| 116 | % USER CODE HERE |
---|
| 117 | |
---|
| 118 | % Download 'Node1_Radio2_TxGain_RF', 'Node1_Radio2_TxGain_BB', |
---|
| 119 | % 'Node1_Radio3_TxGain_RF', and 'Node1_Radio3_TxGain_BB' parameters |
---|
| 120 | % to node 1 using the 'warplab_setRadioParameter' function. |
---|
| 121 | |
---|
| 122 | % Hints: |
---|
| 123 | |
---|
| 124 | % 1. The first argument of the 'warplab_setRadioParameter' function |
---|
| 125 | % identifies the node to which the parameter will be downloaded to. |
---|
| 126 | % The id or handle to node 1 is 'udp_node1'. |
---|
| 127 | |
---|
| 128 | % 2. The second argument of the 'warplab_setRadioParameter' function |
---|
| 129 | % identifies the parameter that will be downloaded. The |
---|
| 130 | % 'Node1_Radio2_TxGain_RF' and 'Node1_Radio2_TxGain_BB' parameters are |
---|
| 131 | % downloaded in one call of the 'warplab_setRadioParameter' and the id to |
---|
| 132 | % download these parameters is 'RADIO2_TXGAINS'. The |
---|
| 133 | % 'Node1_Radio3_TxGain_RF' and 'Node1_Radio3_TxGain_BB' parameters are |
---|
| 134 | % downloaded in one call of the 'warplab_setRadioParameter' and the id to |
---|
| 135 | % download these parameters is 'RADIO3_TXGAINS'. |
---|
| 136 | |
---|
| 137 | % 3. The third argument of the 'warplab_setRadioParameter' function is the |
---|
| 138 | % value the parameter must be set to. The 'Node1_Radio2_TxGain_RF' and |
---|
| 139 | % 'Node1_Radio2_TxGain_BB' parameters are downloaded in one call of the |
---|
| 140 | % 'warplab_setRadioParameter', these two values must be combined for |
---|
| 141 | % download in the following way: |
---|
| 142 | % (Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16) |
---|
| 143 | % The 'Node1_Radio3_TxGain_RF' and |
---|
| 144 | % 'Node1_Radio3_TxGain_BB' parameters are downloaded in one call of the |
---|
| 145 | % 'warplab_setRadioParameter', these two values must be combined for |
---|
| 146 | % download in the following way: |
---|
| 147 | % (Node1_Radio3_TxGain_RF + Node1_Radio3_TxGain_BB*2^16) |
---|
| 148 | |
---|
| 149 | % 4. The 'warplab_setRadioParameter' function has been used in previous |
---|
| 150 | % exercises. |
---|
| 151 | |
---|
| 152 | % 5. Call the 'warplab_setRadioParameter' function twice. One time to |
---|
| 153 | % download the 'Node1_Radio2_TxGain_RF' and 'Node1_Radio2_TxGain_BB' |
---|
| 154 | % parameters and one time to download the 'Node1_Radio3_TxGain_RF' and |
---|
| 155 | % 'Node1_Radio3_TxGain_BB' parameters. |
---|
| 156 | |
---|
| 157 | %-------------------------------------------------------------------------% |
---|
| 158 | |
---|
| 159 | %-------------------------------------------------------------------------% |
---|
| 160 | % USER CODE HERE |
---|
| 161 | |
---|
| 162 | % Download 'Node2_Radio2_RxGain_BB', 'Node2_Radio2_RxGain_RF', |
---|
| 163 | % 'Node2_Radio3_RxGain_BB', and 'Node2_Radio3_RxGain_RF' parameters |
---|
| 164 | % to node 2 using the 'warplab_setRadioParameter' function. |
---|
| 165 | |
---|
| 166 | % Hints: |
---|
| 167 | |
---|
| 168 | % 1. The first argument of the 'warplab_setRadioParameter' function |
---|
| 169 | % identifies the node to which the parameter will be downloaded to. |
---|
| 170 | % The id or handle to node 2 is 'udp_node2'. |
---|
| 171 | |
---|
| 172 | % 2. The second argument of the 'warplab_setRadioParameter' function |
---|
| 173 | % identifies the parameter that will be downloaded. The |
---|
| 174 | % 'Node2_Radio2_RxGain_BB' and 'Node2_Radio2_RxGain_RF' parameters are |
---|
| 175 | % downloaded in one call of the 'warplab_setRadioParameter' and the id to |
---|
| 176 | % download these parameters is 'RADIO2_RXGAINS'. The |
---|
| 177 | % 'Node2_Radio3_RxGain_BB' and 'Node2_Radio3_RxGain_RF' parameters are |
---|
| 178 | % downloaded in one call of the 'warplab_setRadioParameter' and the id to |
---|
| 179 | % download these parameters is 'RADIO3_RXGAINS' |
---|
| 180 | |
---|
| 181 | % 3. The third argument of the 'warplab_setRadioParameter' function is the |
---|
| 182 | % value the parameter must be set to. The 'Node2_Radio2_RxGain_BB' and |
---|
| 183 | % 'Node2_Radio2_RxGain_RF' parameters are downloaded in one call of the |
---|
| 184 | % 'warplab_setRadioParameter', these two values must be combined for |
---|
| 185 | % download in the following way: |
---|
| 186 | % (Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16) |
---|
| 187 | % The 'Node2_Radio3_RxGain_BB' and |
---|
| 188 | % 'Node2_Radio3_RxGain_RF' parameters are downloaded in one call of the |
---|
| 189 | % 'warplab_setRadioParameter', these two values must be combined for |
---|
| 190 | % download in the following way: |
---|
| 191 | % (Node2_Radio3_RxGain_BB + Node2_Radio3_RxGain_RF*2^16) |
---|
| 192 | |
---|
| 193 | % 4. The 'warplab_setRadioParameter' function has been used in previous |
---|
| 194 | % exercises. |
---|
| 195 | |
---|
| 196 | % 5. Call the 'warplab_setRadioParameter' function twice. One time to |
---|
| 197 | % download the 'Node2_Radio2_RxGain_BB' and 'Node2_Radio2_RxGain_RF' |
---|
| 198 | % parameters and one time to download the 'Node2_Radio3_RxGain_BB' and |
---|
| 199 | % 'Node2_Radio3_RxGain_RF' parameters. |
---|
| 200 | |
---|
| 201 | %-------------------------------------------------------------------------% |
---|
| 202 | |
---|
| 203 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 204 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
| 205 | % WARP board (Sample Frequency is 40MHz) |
---|
| 206 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 207 | % Prepare some data to be transmitted |
---|
| 208 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector |
---|
| 209 | |
---|
| 210 | % Create a signal to transmit from radio 2, the signal can be real or complex. |
---|
| 211 | % The signal must meet the following requirements: |
---|
| 212 | % - Signal to transmit must be a row vector. |
---|
| 213 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
| 214 | % of the imaginary part must be in [-1:1]. |
---|
| 215 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
| 216 | % is limited to 19 MHz) |
---|
| 217 | % - Lowest frequency component is limited to 30 kHz |
---|
| 218 | Node1_Radio2_TxData = exp(t*j*2*pi*1e6); |
---|
| 219 | |
---|
| 220 | %-------------------------------------------------------------------------% |
---|
| 221 | % USER CODE HERE |
---|
| 222 | % Download the 'Node1_Radio2_TxData' vector to WARP node 1 radio 2 Tx |
---|
| 223 | % buffer using the 'warplab_writeSMWO' function. The 'Node1_Radio2_TxData' |
---|
| 224 | % vector is the vector of samples to be transmitted from node 1 radio 2. The |
---|
| 225 | % 'warplab_writeSMWO' function has been used in previous exercises. |
---|
| 226 | % The id for radio 2 Tx buffer is 'RADIO2_TXDATA'. |
---|
| 227 | |
---|
| 228 | %-------------------------------------------------------------------------% |
---|
| 229 | |
---|
| 230 | % Create a signal to transmit from radio 3, the signal can be real or complex. |
---|
| 231 | % The signal must meet the following requirements: |
---|
| 232 | % - Signal to transmit must be a row vector. |
---|
| 233 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
| 234 | % of the imaginary part must be in [-1:1]. |
---|
| 235 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
| 236 | % is limited to 19 MHz) |
---|
| 237 | % - Lowest frequency component is limited to 30 kHz |
---|
| 238 | Node1_Radio3_TxData = exp(t*j*2*pi*5e6); |
---|
| 239 | |
---|
| 240 | %-------------------------------------------------------------------------% |
---|
| 241 | % USER CODE HERE |
---|
| 242 | % Download the 'Node1_Radio3_TxData' vector to WARP node 1 radio 3 Tx |
---|
| 243 | % buffer using the 'warplab_writeSMWO' function. The 'Node1_Radio3_TxData' |
---|
| 244 | % vector is the vector of samples to be transmitted from node 1 radio 3. The |
---|
| 245 | % 'warplab_writeSMWO' function has been used in previous exercises. |
---|
| 246 | % The id for radio 3 Tx buffer is 'RADIO3_TXDATA'. |
---|
| 247 | |
---|
| 248 | %-------------------------------------------------------------------------% |
---|
| 249 | |
---|
| 250 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 251 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
| 252 | % start transmission and reception (trigger is the SYNC packet) |
---|
| 253 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 254 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
| 255 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
| 256 | % packet. |
---|
| 257 | |
---|
| 258 | %-------------------------------------------------------------------------% |
---|
| 259 | % USER CODE HERE |
---|
| 260 | % Enable transmitter radio path in radios 2 and 3 in node 1 (enable radio 2 |
---|
| 261 | % and radio 3 in node 1 as transmitters) by sending the RADIO2_TXEN and |
---|
| 262 | % RADIO3_TXEN commands to node 1 using |
---|
| 263 | % the 'warplab_sendCmd' function. The 'warplab_sendCmd' function has been |
---|
| 264 | % used in previous exercises. |
---|
| 265 | % To send the RADIO2_TXEN and RADIO3_TXEN commands in one call of the |
---|
| 266 | % 'warplab_sendCmd' function the second argument of the 'warplab_sendCmd' |
---|
| 267 | % function can be a vector of the commands: [RADIO2_TXEN, RADIO3_TXEN] |
---|
| 268 | |
---|
| 269 | %-------------------------------------------------------------------------% |
---|
| 270 | |
---|
| 271 | %-------------------------------------------------------------------------% |
---|
| 272 | % USER CODE HERE |
---|
| 273 | % Enable transmission of node1's radio 2 and radio 3 Tx buffer (enable |
---|
| 274 | % transmission of samples stored in radio 2 Tx Buffer and in radio 3 Tx |
---|
| 275 | % Buffer in node 1) by sending the RADIO2TXBUFF_TXEN and |
---|
| 276 | % RADIO3TXBUFF_TXEN commands to node 1 using |
---|
| 277 | % the 'warplab_sendCmd' function. The 'warplab_sendCmd' function has been |
---|
| 278 | % used in previous exercises. To send the |
---|
| 279 | % RADIO2TXBUFF_TXEN and RADIO3TXBUFF_TXEN commands in one call of the |
---|
| 280 | % 'warplab_sendCmd' function the second argument of the 'warplab_sendCmd' |
---|
| 281 | % function can be a vector of |
---|
| 282 | % the commands: [RADIO2TXBUFF_TXEN, RADIO3TXBUFF_TXEN] |
---|
| 283 | |
---|
| 284 | %-------------------------------------------------------------------------% |
---|
| 285 | |
---|
| 286 | %-------------------------------------------------------------------------% |
---|
| 287 | % USER CODE HERE |
---|
| 288 | % Enable receiver radio path in radios 2 and 3 in node 2 (enable radios 2 |
---|
| 289 | % and 3 in node 2 as receivers) by sending the 'RADIO2_RXEN' and |
---|
| 290 | % 'RADIO3_RXEN' ommands to node 2 using 'warplab_sendCmd' function. |
---|
| 291 | % The 'warplab_sendCmd' function has been |
---|
| 292 | % used in previous exercises. To send the |
---|
| 293 | % RADIO2_RXEN and RADIO3_RXEN commands in one call of the |
---|
| 294 | % 'warplab_sendCmd' function the second argument of the 'warplab_sendCmd' |
---|
| 295 | % function can be a vector of |
---|
| 296 | % the commands: [RADIO2_RXEN, RADIO3_RXEN] |
---|
| 297 | |
---|
| 298 | %-------------------------------------------------------------------------% |
---|
| 299 | |
---|
| 300 | %-------------------------------------------------------------------------% |
---|
| 301 | % USER CODE HERE |
---|
| 302 | % Enable capture in node2's radio 2 and radio 3 Rx Buffer (enable radio 2 |
---|
| 303 | % Rx buffer and radio 3 Rx buffer in node 2 for storage of samples) by |
---|
| 304 | % sending the 'RADIO2RXBUFF_RXEN' and 'RADIO3RXBUFF_RXEN' commands to node 2 |
---|
| 305 | % using 'warplab_sendCmd' function. |
---|
| 306 | % The 'warplab_sendCmd' function has been |
---|
| 307 | % used in previous exercises. To send the |
---|
| 308 | % RADIO2RXBUFF_RXEN and RADIO3RXBUFF_RXEN commands in one call of the |
---|
| 309 | % 'warplab_sendCmd' function the second argument of the 'warplab_sendCmd' |
---|
| 310 | % function can be a vector of |
---|
| 311 | % the commands: [RADIO2RXBUFF_RXEN, RADIO3RXBUFF_RXEN] |
---|
| 312 | |
---|
| 313 | %-------------------------------------------------------------------------% |
---|
| 314 | |
---|
| 315 | %-------------------------------------------------------------------------% |
---|
| 316 | % USER CODE HERE |
---|
| 317 | |
---|
| 318 | % Prime transmitter state machine in node 1 by sending the TX_START command |
---|
| 319 | % to node 1 using the 'warplab_sendCmd' function. |
---|
| 320 | |
---|
| 321 | % Node 1 will start waiting for the SYNC packet as soon as it receives the |
---|
| 322 | % TX_START command. Transmission from node 1 will be triggered when node 1 |
---|
| 323 | % receives the SYNC packet. |
---|
| 324 | |
---|
| 325 | %-------------------------------------------------------------------------% |
---|
| 326 | |
---|
| 327 | %-------------------------------------------------------------------------% |
---|
| 328 | % USER CODE HERE |
---|
| 329 | |
---|
| 330 | % Prime receiver state machine in node 2 by sending the RX_START command |
---|
| 331 | % to node 2 using the 'warplab_sendCmd' function. |
---|
| 332 | |
---|
| 333 | % Node 2 will start waiting for the SYNC packet as soon as it receives the |
---|
| 334 | % RX_START command. Capture on node 2 will be triggered when node 2 |
---|
| 335 | % receives the SYNC packet. |
---|
| 336 | |
---|
| 337 | %-------------------------------------------------------------------------% |
---|
| 338 | |
---|
| 339 | % Send the SYNC packet |
---|
| 340 | warplab_sendSync(udp_Sync); |
---|
| 341 | |
---|
| 342 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 343 | % 3. Read the received samples from the Warp board |
---|
| 344 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 345 | %-------------------------------------------------------------------------% |
---|
| 346 | % USER CODE HERE |
---|
| 347 | |
---|
| 348 | % Read the received samples from the WARP node 2 radio 2 Rx buffer using the |
---|
| 349 | % 'warplab_readSMRO' function. Store the samples in a variable named |
---|
| 350 | % 'Node2_Radio2_RawRxData'. |
---|
| 351 | |
---|
| 352 | % The id for radio 2 Rx buffer is 'RADIO2_RXDATA'. |
---|
| 353 | |
---|
| 354 | % For this exercise the third argument of the 'warplab_readSMRO' |
---|
| 355 | % function must be equal to 'TxLength+TxDelay', since TxLength is the |
---|
| 356 | % number of samples that were transmitted and the first TxDelay samples |
---|
| 357 | % that were captured correspond to noise samples captured before the data |
---|
| 358 | % was transmitted. |
---|
| 359 | |
---|
| 360 | %-------------------------------------------------------------------------% |
---|
| 361 | |
---|
| 362 | %-------------------------------------------------------------------------% |
---|
| 363 | % USER CODE HERE |
---|
| 364 | |
---|
| 365 | % Read the received samples from the WARP node 2 radio 3 Rx buffer using the |
---|
| 366 | % 'warplab_readSMRO' function. Store the samples in a variable named |
---|
| 367 | % 'Node2_Radio3_RawRxData'. |
---|
| 368 | |
---|
| 369 | % The id for radio 3 Rx buffer is 'RADIO3_RXDATA'. |
---|
| 370 | |
---|
| 371 | % For this exercise the third argument of the 'warplab_readSMRO' |
---|
| 372 | % function must be equal to 'TxLength+TxDelay', since TxLength is the |
---|
| 373 | % number of samples that were transmitted and the first TxDelay samples |
---|
| 374 | % that were captured correspond to noise samples captured before the data |
---|
| 375 | % was transmitted. |
---|
| 376 | |
---|
| 377 | %-------------------------------------------------------------------------% |
---|
| 378 | |
---|
| 379 | % Process the received samples to obtain meaningful data |
---|
| 380 | [Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData); |
---|
| 381 | [Node2_Radio3_RxData,Node2_Radio3_RxOTR] = warplab_processRawRxData(Node2_Radio3_RawRxData); |
---|
| 382 | % Read stored RSSI data from radio 2 |
---|
| 383 | [Node2_Radio2_RawRSSIData] = warplab_readSMRO(udp_node2, RADIO2_RSSIDATA, ceil((TxLength+TxDelay)/8)); |
---|
| 384 | % Read stored RSSI data from radio 3 |
---|
| 385 | [Node2_Radio3_RawRSSIData] = warplab_readSMRO(udp_node2, RADIO3_RSSIDATA, ceil((TxLength+TxDelay)/8)); |
---|
| 386 | % Procecss Raw RSSI data to obtain meningful RSSI values |
---|
| 387 | [Node2_Radio2_RSSIData] = warplab_processRawRSSIData(Node2_Radio2_RawRSSIData); |
---|
| 388 | [Node2_Radio3_RSSIData] = warplab_processRawRSSIData(Node2_Radio3_RawRSSIData); |
---|
| 389 | % Note: If the four lines of code above (warplab_processRawRSSIData lines and |
---|
| 390 | % warplab_readSMRO(udp_node2, RADIO2_RSSIDATA, (TxLength+TxDelay)/8) line |
---|
| 391 | % and warplab_readSMRO(udp_node2, RADIO3_RSSIDATA, (TxLength+TxDelay)/8) line) |
---|
| 392 | % are deleted, then the code will work when the boards are programmed |
---|
| 393 | % with the warplab_mimo_4x4_v04.bit bitstream) |
---|
| 394 | |
---|
| 395 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 396 | % 4. Reset and disable the boards |
---|
| 397 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 398 | % Set radios 2 and 3 Tx buffer in node 1 back to Tx disabled mode |
---|
| 399 | warplab_sendCmd(udp_node1, [RADIO2TXBUFF_TXDIS RADIO3TXBUFF_TXDIS], packetNum); |
---|
| 400 | |
---|
| 401 | % Disable the transmitter radios |
---|
| 402 | warplab_sendCmd(udp_node1, [RADIO2_TXDIS, RADIO3_TXDIS], packetNum); |
---|
| 403 | |
---|
| 404 | % Set radios 2 and 3 Rx buffer in node 2 back to Rx disabled mode |
---|
| 405 | warplab_sendCmd(udp_node2, [RADIO2RXBUFF_RXDIS, RADIO3RXBUFF_RXDIS], packetNum); |
---|
| 406 | |
---|
| 407 | % Disable the receiver radios |
---|
| 408 | warplab_sendCmd(udp_node2, [RADIO2_RXDIS,RADIO3_RXDIS], packetNum); |
---|
| 409 | |
---|
| 410 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 411 | % 5. Plot the transmitted and received data and close sockets |
---|
| 412 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 413 | figure; |
---|
| 414 | subplot(4,2,1); |
---|
| 415 | plot(real(Node1_Radio2_TxData)); |
---|
| 416 | title('Tx Node 1 Radio 2 I'); |
---|
| 417 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 418 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 419 | subplot(4,2,2); |
---|
| 420 | plot(imag(Node1_Radio2_TxData)); |
---|
| 421 | title('Tx Node 1 Radio 2 Q'); |
---|
| 422 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 423 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 424 | subplot(4,2,3); |
---|
| 425 | plot(real(Node1_Radio3_TxData)); |
---|
| 426 | title('Tx Node 1 Radio 3 I'); |
---|
| 427 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 428 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 429 | subplot(4,2,4); |
---|
| 430 | plot(imag(Node1_Radio3_TxData)); |
---|
| 431 | title('Tx Node 1 Radio 3 Q'); |
---|
| 432 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 433 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 434 | subplot(4,2,5); |
---|
| 435 | plot(real(Node2_Radio2_RxData)); |
---|
| 436 | title('Rx Node 2 Radio 2 I'); |
---|
| 437 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 438 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 439 | subplot(4,2,6); |
---|
| 440 | plot(imag(Node2_Radio2_RxData)); |
---|
| 441 | title('Rx Node 2 Radio 2 Q'); |
---|
| 442 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 443 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 444 | subplot(4,2,7); |
---|
| 445 | plot(real(Node2_Radio3_RxData)); |
---|
| 446 | title('Rx Node 2 Radio 3 I'); |
---|
| 447 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 448 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 449 | subplot(4,2,8); |
---|
| 450 | plot(imag(Node2_Radio3_RxData)); |
---|
| 451 | title('Rx Node 2 Radio 3 Q'); |
---|
| 452 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 453 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 454 | |
---|
| 455 | % Close sockets |
---|
| 456 | pnet('closeall'); |
---|
| 457 | |
---|
| 458 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 459 | % Code to avoid conflict between users, only needed for the workshop |
---|
| 460 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 461 | % !del c:\boards_lock.txt |
---|
| 462 | catch, |
---|
| 463 | % Reset nodes |
---|
| 464 | warplab_reset2x2Node(udp_node1); |
---|
| 465 | warplab_reset2x2Node(udp_node2); |
---|
| 466 | % Close sockets |
---|
| 467 | pnet('closeall'); |
---|
| 468 | % !del c:\boards_lock.txt |
---|
| 469 | lasterr |
---|
| 470 | end |
---|