[1455] | 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 2 | % Using WARPLab (SISO configuration) to Estimate the Amplitude and Phase of |
---|
| 3 | % a Narrowband Flat Fading Wireless Channel |
---|
| 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 5 | % The specific steps implemented in this script are the following: |
---|
| 6 | |
---|
| 7 | % 0. Transmit a narrowband signal using WARPLab |
---|
| 8 | % 1. Remove from the received vector the samples that do not correspond to |
---|
| 9 | % transmitted data. |
---|
| 10 | % 2. Compute the amplitude and the phase of the transmitted and received |
---|
| 11 | % samples |
---|
| 12 | % 3. Compute the channel amplitude and channel phase per sample and close |
---|
| 13 | % sockets |
---|
| 14 | |
---|
| 15 | % Note: The amplitude and phase computed in this exercise correspond to the |
---|
| 16 | % amplitude and phase of the channel together with the amplitude and phase |
---|
| 17 | % of the hardware. In other words, the effect of the radios (like gains and |
---|
| 18 | % carrier frequency offset)is also part of the channel. |
---|
| 19 | |
---|
| 20 | % NOTE 2 : To avoid conflict with other groups using the boards, please |
---|
| 21 | % test the code you write in this script in any of the following three |
---|
| 22 | % ways: |
---|
| 23 | % |
---|
| 24 | % Option 1. Run this script from matlab's Command Window by entering the |
---|
| 25 | % name of the script (enter warplab_siso_example_ChannelEstim_WorkshopExercise |
---|
| 26 | % in matlab's Command Window). |
---|
| 27 | % Option 2. In the menu bar go to Debug and select Run. If there |
---|
| 28 | % are errors in the code, error messages will appear in the Command Window. |
---|
| 29 | % Option 3. Press F5. If the are errors in the code, error messages will |
---|
| 30 | % appear in the Command Window. |
---|
| 31 | % |
---|
| 32 | % DO NOT USE the Evaluate selection option and DO NOT run the script by |
---|
| 33 | % sections. To test any change, always run the whole script by following |
---|
| 34 | % any of the three options above. |
---|
| 35 | |
---|
| 36 | try, |
---|
| 37 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 38 | % Code to avoid conflict between users, only needed for the workshop, go to |
---|
| 39 | % step 0 below to transmit a narrowband signal using WARPLab |
---|
| 40 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 41 | % fid = fopen('c:\boards_lock.txt'); |
---|
| 42 | % |
---|
| 43 | % if(fid > -1) |
---|
| 44 | % fclose('all'); |
---|
| 45 | % errordlg('Boards already in use - Please try again!'); |
---|
| 46 | % return; |
---|
| 47 | % end |
---|
| 48 | % |
---|
| 49 | % !echo > c:\boards_lock.txt |
---|
| 50 | |
---|
| 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 52 | % 0. Transmit a narrowband signal using WARPLab |
---|
| 53 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 54 | % Follow the steps for transmission and reception of data using WARPLab. |
---|
| 55 | % These are the steps implemented in the previous lab exercise, the |
---|
| 56 | % following sections (0.0 to 0.5) guide you through the steps. |
---|
| 57 | |
---|
| 58 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 59 | % 0.0. Initializaton and definition of parameters |
---|
| 60 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 61 | %Load some global definitions (packet types, etc.) |
---|
| 62 | warplab_defines |
---|
| 63 | |
---|
| 64 | % Create Socket handles and intialize nodes |
---|
| 65 | [socketHandles, packetNum] = warplab_initialize; |
---|
| 66 | |
---|
| 67 | % Separate the socket handles for easier access |
---|
| 68 | % The first socket handle is always the magic SYNC |
---|
| 69 | % The rest of the handles are the handles to the WARP nodes |
---|
| 70 | udp_Sync = socketHandles(1); |
---|
| 71 | udp_node1 = socketHandles(2); |
---|
| 72 | udp_node2 = socketHandles(3); |
---|
| 73 | |
---|
| 74 | % Define WARPLab parameters. |
---|
| 75 | %-------------------------------------------------------------------------% |
---|
| 76 | % USER CODE HERE |
---|
| 77 | |
---|
| 78 | % Create the following variables and assign them valid values: |
---|
| 79 | |
---|
| 80 | % TxDelay: Number of noise samples per Rx capture. In [0:2^14] |
---|
| 81 | % TxLength: Length of transmission. In [0:2^14-1-TxDelay] |
---|
| 82 | % CarrierChannel: Channel in the 2.4 GHz band. In [1:14] |
---|
| 83 | % Node1_Radio2_TxGain_BB: Tx Baseband Gain. In [0:3] |
---|
| 84 | % Node1_Radio2_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 | |
---|
| 88 | % Note: For this experiment node 1 will be set as the transmitter and node |
---|
| 89 | % 2 will be set as the receiver (this is done later in the code), hence, |
---|
| 90 | % there is no need to define receive gains for node 1 and there is no |
---|
| 91 | % need to define transmitter gains for node 2. |
---|
| 92 | |
---|
| 93 | %-------------------------------------------------------------------------% |
---|
| 94 | |
---|
| 95 | TxMode = 0; %Transmission mode. In [0:1] |
---|
| 96 | % 0: Single Transmission |
---|
| 97 | % 1: Continuous Transmission. Tx board will continue |
---|
| 98 | % transmitting the vector of samples until the user manually |
---|
| 99 | % disables the transmitter. |
---|
| 100 | |
---|
| 101 | % Download the WARPLab parameters to the WARP nodes. |
---|
| 102 | % The nodes store the TxDelay, TxLength, and TxMode parameters in |
---|
| 103 | % registers defined in the WARPLab sysgen model. The nodes set radio |
---|
| 104 | % related parameters CarrierChannel, TxGains, and RxGains, using the |
---|
| 105 | % radio controller functions. |
---|
| 106 | |
---|
| 107 | % The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter; |
---|
| 108 | % the receiver doesn't require knowledge of these parameters (the receiver |
---|
| 109 | % will always capture 2^14 samples). For this exercise node 1 will be set as |
---|
| 110 | % the transmitter (this is done later in the code). Since TxDelay, TxLength and |
---|
| 111 | % TxMode are only required at the transmitter we download the TxDelay, TxLength and |
---|
| 112 | % TxMode parameters only to the transmitter node (node 1). |
---|
| 113 | warplab_writeRegister(udp_node1,TX_DELAY,TxDelay); |
---|
| 114 | warplab_writeRegister(udp_node1,TX_LENGTH,TxLength); |
---|
| 115 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
| 116 | % The CarrierChannel parameter must be downloaded to all nodes |
---|
| 117 | warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel); |
---|
| 118 | warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel); |
---|
| 119 | % Node 1 will be set as the transmitter so download Tx gains to node 1. |
---|
| 120 | warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16)); |
---|
| 121 | % Node 2 will be set as the receiver so download Rx gains to node 2. |
---|
| 122 | warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16)); |
---|
| 123 | |
---|
| 124 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 125 | % 0.1. Generate a vector of samples to transmit and send the samples to the |
---|
| 126 | % WARP board (Sample Frequency is 40MHz) |
---|
| 127 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 128 | % Prepare some data to be transmitted |
---|
| 129 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector. |
---|
| 130 | |
---|
| 131 | % The signal must meet the following requirements: |
---|
| 132 | % - Signal to transmit must be a row vector. |
---|
| 133 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
| 134 | % of the imaginary part must be in [-1:1]. |
---|
| 135 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
| 136 | % is limited to 19 MHz) |
---|
| 137 | % - Lowest frequency component is limited to 30 kHz |
---|
| 138 | Node1_Radio2_TxData = exp(t*j*2*pi*1e6); |
---|
| 139 | |
---|
| 140 | % Download the samples to be transmitted |
---|
| 141 | %-------------------------------------------------------------------------% |
---|
| 142 | % USER CODE HERE |
---|
| 143 | % Download the 'Node1_Radio2_TxData' vector to WARP node 1 using the |
---|
| 144 | % 'warplab_writeSMWO' function. The 'Node1_Radio2_TxData' vector is the |
---|
| 145 | % vector of samples to be transmitted. |
---|
| 146 | |
---|
| 147 | % Hints: |
---|
| 148 | |
---|
| 149 | % 1. The first argument of the 'warplab_writeSMWO' function identifies the |
---|
| 150 | % node to which samples will be downloaded to. In this exercise we will set |
---|
| 151 | % node 1 as the transmitter node, the id or handle to node 1 is 'udp_node1'. |
---|
| 152 | |
---|
| 153 | % 2. The second argument of the 'warplab_writeSMWO' function identifies the |
---|
| 154 | % transmit buffer where the samples will be written. For this exercise we |
---|
| 155 | % will transmit from radio 2, hence, samples must be downloaded to radio 2 |
---|
| 156 | % Tx buffer, the id for this buffer is 'RADIO2_TXDATA'. |
---|
| 157 | |
---|
| 158 | % 3. The third argument of the 'warplab_writeSMWO' function is the |
---|
| 159 | % vector of samples to download, it must be a row vector. For this |
---|
| 160 | % exercise the 'Node1_Radio2_TxData' vector is the vector of samples to be |
---|
| 161 | % transmitted, hence, this is the vector that must be downloaded to radio 2 |
---|
| 162 | % Tx buffer. |
---|
| 163 | |
---|
| 164 | % 4. The 'warplab_writeSMWO' function was used in the previous exercise. |
---|
| 165 | |
---|
| 166 | %-------------------------------------------------------------------------% |
---|
| 167 | |
---|
| 168 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 169 | % 0.2. Prepare WARP boards for transmission and reception and send trigger to |
---|
| 170 | % start transmission and reception (trigger is the SYNC packet) |
---|
| 171 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 172 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
| 173 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
| 174 | % packet. |
---|
| 175 | |
---|
| 176 | % Enable transmitter radio path in radio 2 in node 1 (enable radio 2 in |
---|
| 177 | % node 1 as transmitter) |
---|
| 178 | warplab_sendCmd(udp_node1, RADIO2_TXEN, packetNum); |
---|
| 179 | |
---|
| 180 | % Enable transmission of node1's radio 2 Tx buffer (enable transmission |
---|
| 181 | % of samples stored in radio 2 Tx Buffer in node 1) |
---|
| 182 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXEN, packetNum); |
---|
| 183 | |
---|
| 184 | % Enable receiver radio path in radio 2 in node 2 (enable radio 2 in |
---|
| 185 | % node 2 as receiver) |
---|
| 186 | warplab_sendCmd(udp_node2, RADIO2_RXEN, packetNum); |
---|
| 187 | |
---|
| 188 | % Enable capture in node2's radio 2 Rx Buffer (enable radio 2 rx buffer in |
---|
| 189 | % node 2 for storage of samples) |
---|
| 190 | warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXEN, packetNum); |
---|
| 191 | |
---|
| 192 | % Prime transmitter state machine in node 1. Node 1 will be |
---|
| 193 | % waiting for the SYNC packet. Transmission from node 1 will be triggered |
---|
| 194 | % when node 1 receives the SYNC packet. |
---|
| 195 | warplab_sendCmd(udp_node1, TX_START, packetNum); |
---|
| 196 | |
---|
| 197 | % Prime receiver state machine in node 2. Node 2 will be waiting |
---|
| 198 | % for the SYNC packet. Capture at node 2 will be triggered when node 2 |
---|
| 199 | % receives the SYNC packet. |
---|
| 200 | warplab_sendCmd(udp_node2, RX_START, packetNum); |
---|
| 201 | |
---|
| 202 | % Send the SYNC packet |
---|
| 203 | warplab_sendSync(udp_Sync); |
---|
| 204 | |
---|
| 205 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 206 | % 0.3. Read the received smaples from the WARP board |
---|
| 207 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 208 | %-------------------------------------------------------------------------% |
---|
| 209 | % USER CODE HERE |
---|
| 210 | |
---|
| 211 | % Read the received samples from the WARP board using the |
---|
| 212 | % 'warplab_readSMRO' function. Store the samples in a variable named |
---|
| 213 | % 'Node2_Radio2_RawRxData' |
---|
| 214 | |
---|
| 215 | % Hints: |
---|
| 216 | |
---|
| 217 | % 1. The first argument of the 'warplab_readSMRO' function identifies the |
---|
| 218 | % node from which samples will be read. In this exercise we set node 2 as |
---|
| 219 | % the receiver node, the id or handle to node 2 is 'udp_node2'. |
---|
| 220 | |
---|
| 221 | % 2. The second argument of the 'warplab_readSMRO' function identifies the |
---|
| 222 | % receive buffer from which samples will be read. For this exercise samples |
---|
| 223 | % were captured in node 2 radio 2, hence, samples must be read from radio 2 |
---|
| 224 | % Rx buffer, the id for this buffer is 'RADIO2_RXDATA'. |
---|
| 225 | |
---|
| 226 | % 3. The third argument of the 'warplab_readSMRO' function is the number of |
---|
| 227 | % samples to read; reading of samples always starts from address zero. |
---|
| 228 | % For this exercise the third argument of the 'warplab_readSMRO' |
---|
| 229 | % function must be equal to 'TxLength+TxDelay', since TxLength is the |
---|
| 230 | % number of samples that were transmitted and the first TxDelay samples |
---|
| 231 | % that were captured correspond to noise samples captured before the data |
---|
| 232 | % was transmitted. |
---|
| 233 | |
---|
| 234 | % 4. The 'warplab_readSMRO' function was used in the previous exercise. |
---|
| 235 | |
---|
| 236 | %-------------------------------------------------------------------------% |
---|
| 237 | |
---|
| 238 | % Process the received samples to obtain meaningful data |
---|
| 239 | [Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData); |
---|
| 240 | |
---|
| 241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 242 | % 0.4. Reset and disable the boards |
---|
| 243 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 244 | % Set radio 2 Tx buffer in node 1 back to Tx disabled mode |
---|
| 245 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXDIS, packetNum); |
---|
| 246 | |
---|
| 247 | % Disable the transmitter radio |
---|
| 248 | warplab_sendCmd(udp_node1, RADIO2_TXDIS, packetNum); |
---|
| 249 | |
---|
| 250 | % Set radio 2 Rx buffer in node 2 back to Rx disabled mode |
---|
| 251 | warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXDIS, packetNum); |
---|
| 252 | |
---|
| 253 | % Disable the receiver radio |
---|
| 254 | warplab_sendCmd(udp_node2, RADIO2_RXDIS, packetNum); |
---|
| 255 | |
---|
| 256 | |
---|
| 257 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 258 | % 0.5. Plot the transmitted and received data |
---|
| 259 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 260 | figure; |
---|
| 261 | subplot(2,2,1); |
---|
| 262 | plot(real(Node1_Radio2_TxData)); |
---|
| 263 | title('Tx Node 1 Radio 2 I'); |
---|
| 264 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 265 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 266 | subplot(2,2,2); |
---|
| 267 | plot(imag(Node1_Radio2_TxData)); |
---|
| 268 | title('Tx Node 1 Radio 2 Q'); |
---|
| 269 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 270 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 271 | subplot(2,2,3); |
---|
| 272 | plot(real(Node2_Radio2_RxData)); |
---|
| 273 | title('Rx Node 2 Radio 2 I'); |
---|
| 274 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 275 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 276 | subplot(2,2,4); |
---|
| 277 | plot(imag(Node2_Radio2_RxData)); |
---|
| 278 | title('Rx Node 2 Radio 2 Q'); |
---|
| 279 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 280 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
| 281 | |
---|
| 282 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 283 | % 1. Remove from the received vector the samples that do not correspond to |
---|
| 284 | % transmitted data. In other words, remove from the received vector samples |
---|
| 285 | % 1 to TxDelay. This step will remove samples that correspond to measured |
---|
| 286 | % noise and make the RxData vector the same length as the TxData vector |
---|
| 287 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 288 | Node2_Radio2_RxData = Node2_Radio2_RxData(TxDelay+1:end); |
---|
| 289 | |
---|
| 290 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 291 | % 2. Compute the amplitude and the phase of the transmitted and received |
---|
| 292 | % sammples |
---|
| 293 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 294 | |
---|
| 295 | %-------------------------------------------------------------------------% |
---|
| 296 | % USER CODE HERE |
---|
| 297 | % Compute the magnitude per sample of the transmitted and received |
---|
| 298 | % data. Store the magnitude of the transmitted data in a variable named |
---|
| 299 | % 'mag_TxData'. Store the magnitude of the received data in a variable |
---|
| 300 | % named 'mag_RxData'. |
---|
| 301 | |
---|
| 302 | % Hints: You can use Matlab's 'abs' function, the transmitted data is stored |
---|
| 303 | % in vector 'Node1_Radio2_TxData', and the received data is stored in vector |
---|
| 304 | % 'Node2_Radio2_RxData' |
---|
| 305 | |
---|
| 306 | %-------------------------------------------------------------------------% |
---|
| 307 | |
---|
| 308 | %-------------------------------------------------------------------------% |
---|
| 309 | % USER CODE HERE |
---|
| 310 | % Compute the phase per sample of the transmitted and received |
---|
| 311 | % data. Store the phase (in radians) of the transmitted data in a variable |
---|
| 312 | % named 'phase_TxData'. Store the phase (in radians) of the received data |
---|
| 313 | % in a variable named 'phase_RxData'. |
---|
| 314 | |
---|
| 315 | % Hints: You can use Matlab's 'angle' function, the transmitted data is stored |
---|
| 316 | % in vector 'Node1_Radio2_TxData', and the received data is stored in vector |
---|
| 317 | % 'Node2_Radio2_RxData'. |
---|
| 318 | |
---|
| 319 | %-------------------------------------------------------------------------% |
---|
| 320 | |
---|
| 321 | phase_TxData_unw = unwrap(phase_TxData); |
---|
| 322 | phase_TxData = phase_TxData *180/pi; %Convert to degrees |
---|
| 323 | phase_TxData_unw = phase_TxData_unw *180/pi; %Convert to degrees |
---|
| 324 | |
---|
| 325 | phase_RxData_unw = unwrap(phase_RxData); |
---|
| 326 | phase_RxData = phase_RxData *180/pi; %Convert to degrees |
---|
| 327 | phase_RxData_unw = phase_RxData_unw *180/pi; %Convert to degrees |
---|
| 328 | |
---|
| 329 | % Plot magnitude and phase of transmitted and received samples |
---|
| 330 | figure; |
---|
| 331 | subplot(2,3,1); |
---|
| 332 | plot(mag_TxData); |
---|
| 333 | title('Tx Node 1 Radio 2 magnitude'); |
---|
| 334 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 335 | subplot(2,3,2); |
---|
| 336 | plot(phase_TxData); |
---|
| 337 | title('Tx Node 1 Radio 2 Phase'); |
---|
| 338 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
| 339 | subplot(2,3,3); |
---|
| 340 | plot(phase_TxData_unw); |
---|
| 341 | title('Tx Node 1 Radio 2 Phase unwrapped'); |
---|
| 342 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
| 343 | subplot(2,3,4); |
---|
| 344 | plot(mag_RxData); |
---|
| 345 | title('Rx Node 2 Radio 2 Magnitude'); |
---|
| 346 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 347 | subplot(2,3,5); |
---|
| 348 | plot(phase_RxData); |
---|
| 349 | title('Rx Node 2 Radio 2 Phase'); |
---|
| 350 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
| 351 | subplot(2,3,6); |
---|
| 352 | plot(phase_RxData_unw); |
---|
| 353 | title('Rx Node 2 Radio 2 Phase unwrapped'); |
---|
| 354 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
| 355 | |
---|
| 356 | |
---|
| 357 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 358 | % 3. Compute the channel amplitude and channel phase per sample and close |
---|
| 359 | % sockets |
---|
| 360 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 361 | |
---|
| 362 | %-------------------------------------------------------------------------% |
---|
| 363 | % USER CODE HERE |
---|
| 364 | % Compute the channel amplitude per sample. Store the result in a variable |
---|
| 365 | % named 'channel_amplitude' |
---|
| 366 | % Hint 1: |
---|
| 367 | % Channel amplitude = Magnitude of received samples / Magnitude of transmited samples |
---|
| 368 | % Hint 2: |
---|
| 369 | % You can use Matlab's './' function to implement division of vetors entry |
---|
| 370 | % by entry. To learn more about this function enter 'help ./' in the Matlab |
---|
| 371 | % command window |
---|
| 372 | |
---|
| 373 | |
---|
| 374 | %-------------------------------------------------------------------------% |
---|
| 375 | |
---|
| 376 | %-------------------------------------------------------------------------% |
---|
| 377 | % USER CODE HERE |
---|
| 378 | % Compute the channel phase per sample. Store the result in a variable |
---|
| 379 | % named 'channel_phase' |
---|
| 380 | % Hint: |
---|
| 381 | % Channel Phase = Phase of received samples - Phase of transmitted samples |
---|
| 382 | |
---|
| 383 | %-------------------------------------------------------------------------% |
---|
| 384 | |
---|
| 385 | % Plot channel amplitude and phase |
---|
| 386 | figure |
---|
| 387 | subplot(2,1,1) |
---|
| 388 | plot(channel_amplitude) |
---|
| 389 | title('Channel Amplitude per sample'); |
---|
| 390 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
| 391 | subplot(2,1,2) |
---|
| 392 | plot(channel_phase) |
---|
| 393 | title('Channel Phase per sample'); |
---|
| 394 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
| 395 | |
---|
| 396 | % Close sockets |
---|
| 397 | pnet('closeall'); |
---|
| 398 | |
---|
| 399 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 400 | % Code to avoid conflict between users, only needed for the workshop |
---|
| 401 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
| 402 | % !del c:\boards_lock.txt |
---|
| 403 | catch, |
---|
| 404 | % Reset nodes |
---|
| 405 | warplab_reset2x2Node(udp_node1); |
---|
| 406 | warplab_reset2x2Node(udp_node2); |
---|
| 407 | % Close sockets |
---|
| 408 | pnet('closeall'); |
---|
| 409 | % !del c:\boards_lock.txt |
---|
| 410 | lasterr |
---|
| 411 | end |
---|
| 412 | |
---|