root/ResearchApps/PHY/WARPLAB/WARPLab_SISO_MIMO2x2/M_Code/warplab_mimo_example_ChannelEstim_WorkshopExercise_Solution.m
| Revision 839, 19.9 kB (checked in by MelissaDuarte, 4 months ago) |
|---|
| Line | |
|---|---|
| 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | % Using Warplab to Estimate the Amplitude and Phase of a Narrowband Flat |
| 3 | % Fading 2-Input 2-Output Wireless Channel (2x2 MIMO Configuration) |
| 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5 | % To run this code the boards must be programmed with the |
| 6 | % warplab_mimo_v02.bit bitstream |
| 7 | |
| 8 | % The specific steps implemented in this script are the following: |
| 9 | |
| 10 | % 0. Transmit a narrowband signal using Warplab. For 2x2 channel estimation |
| 11 | % first silence Tx radio 3 and transmit from Tx radio 2, then silence Tx |
| 12 | % radio 2 and transmit from Tx radio 3. During both transimissions both |
| 13 | % receive radios are capturing data. |
| 14 | % 1. Remove from the received vectors the samples that do not correspond to |
| 15 | % transmitted data. |
| 16 | % 2. Compute the amplitude and the phase of the transmitted and received |
| 17 | % samples |
| 18 | % 3. Compute the channel amplitude and channel phase per sample for each of |
| 19 | % the 4 SISO channels, and compute the channel matrix |
| 20 | |
| 21 | % NOTE 1: The amplitude and phase computed in this exercise correspond to the |
| 22 | % amplitude and phase of the channel together with the amplitude and phase |
| 23 | % of the hardware. In other words, the effect of the radios is also part of |
| 24 | % the channel. |
| 25 | |
| 26 | % You will write a matlab script that implements the four steps above. |
| 27 | % Part of the code is provided, some part of the code you will write. Read |
| 28 | % the code below and fill in with your code wherever you are asked to do |
| 29 | % so. |
| 30 | |
| 31 | % NOTE 2 : To avoid conflict with other groups using the boards, please |
| 32 | % test the code you write in this script in any of the following three |
| 33 | % ways: |
| 34 | % |
| 35 | % Option 1. Run this script from matlab's Command Window by entering the |
| 36 | % name of the script (enter warplab_example_ChannelEstimation_WorkshopExercise |
| 37 | % in matlab's Command Window). |
| 38 | % Option 2. In the menu bar go to Debug and select Run. If there |
| 39 | % are errors in the code, error messages will appear in the Command Window. |
| 40 | % Option 3. Press F5. If the are errors in the code, error messages will |
| 41 | % appear in the Command Window. |
| 42 | % |
| 43 | % DO NOT USE the Evaluate selection option and DO NOT run the script by |
| 44 | % sections. To test any change, always run the whole script by following |
| 45 | % any of the three options above. |
| 46 | |
| 47 | try, |
| 48 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 49 | % Code to avoid conflict between users, only needed for the workshop, go to |
| 50 | % step 0 below to transmit a narrowband signal using Warplab |
| 51 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 52 | fid = fopen('c:\boards_lock.txt'); |
| 53 | |
| 54 | if(fid > -1) |
| 55 | fclose('all'); |
| 56 | errordlg('Boards already in use - Please try again!'); |
| 57 | return; |
| 58 | end |
| 59 | |
| 60 | !echo > c:\boards_lock.txt |
| 61 | |
| 62 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 63 | % 0. Transmit a narrowband signal using Warplab. For 2x2 channel estimation |
| 64 | % first silence Tx radio 3 and transmit from Tx radio 2, then silence Tx |
| 65 | % radio 2 and transmit from Tx radio 3. During both transimissions both |
| 66 | % receive radios are capturing data. |
| 67 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 68 | |
| 69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 70 | % 0.0. Initializaton and definition of parameters |
| 71 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 72 | %Load some global definitions (packet types, etc.) |
| 73 | warplab_defines |
| 74 | |
| 75 | % Create Socket handles and intialize nodes |
| 76 | [socketHandles, packetNum] = warplab_initialize; |
| 77 | |
| 78 | %Separate the socket handles for easier access |
| 79 | % The first socket handle is always the magic SYNC |
| 80 | % The rest can be arranged in any combination of Tx and Rx |
| 81 | udp_Sync = socketHandles(1); |
| 82 | udp_Tx = socketHandles(2); |
| 83 | udp_RxA = socketHandles(3); |
| 84 | |
| 85 | % Define the warplab options (parameters) |
| 86 | CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14] |
| 87 | TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset] |
| 88 | TransMode = 0; %Transmission mode; in [0:1] |
| 89 | % 0: Single Transmission |
| 90 | % 1: Continuous Transmission. Tx board will continue |
| 91 | % transmitting the vector of samples until the user manually |
| 92 | % disables the transmitter. |
| 93 | CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14] |
| 94 | Tx2GainBB = 3; %Tx Baseband Gain in [0:3] |
| 95 | Tx2GainRF = 40; %Tx RF Gain in [0:63] |
| 96 | Rx2GainBB = 15; %Rx Baseband Gain in [0:31] |
| 97 | Rx2GainRF = 1; %Rx RF Gain in [1:3] |
| 98 | Tx3GainBB = 3; %Tx Baseband Gain in [0:3] |
| 99 | Tx3GainRF = 40; %Tx RF Gain in [0:63] |
| 100 | Rx3GainBB = 15; %Rx Baseband Gain in [0:31] |
| 101 | Rx3GainRF = 1; %Rx RF Gain in [1:3] |
| 102 | TxSelect = 2; % Select transmitter radio [0:2] 0:Radio2, 1:Radio3, 2: Both |
| 103 | RxSelect = 2; % Select transmitter radio [0:2] 0:Radio2, 1:Radio3, 2: Both |
| 104 | |
| 105 | % Define the options vector; the order of options is set by the FPGA's code |
| 106 | % (C code) |
| 107 | optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (Rx2GainBB + Rx2GainRF*2^16) (Tx2GainRF + Tx2GainBB*2^16) (Rx3GainBB + Rx3GainRF*2^16) (Tx3GainRF + Tx3GainBB*2^16) TxSelect RxSelect]; |
| 108 | % Send options vector to the nodes |
| 109 | warplab_setOptions(socketHandles,optionsVector); |
| 110 | |
| 111 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 112 | % 0.1. Generate a vector of samples to transmit and send the samples to the |
| 113 | % Warp board (Sample Frequency is 40MHz) |
| 114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 115 | % Prepare some data to be transmitted |
| 116 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; %Create time vector. |
| 117 | TxData = exp(t*j*2*pi*1e6); % Create a signal to transmit. Signal must be a |
| 118 | % row vector |
| 119 | |
| 120 | % Download the samples to be transmitted to Tx radio 2 buffer |
| 121 | warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA); |
| 122 | |
| 123 | % Download the samples to be transmitted to Tx radio 3 buffer |
| 124 | warplab_writeSMWO(udp_Tx, TxData, RADIO3_TXDATA); |
| 125 | |
| 126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 127 | % 0.2 Prepare boards for transmission from Tx radio 2 and reception on |
| 128 | % both receiver antennas. Send trigger to start transmission and reception |
| 129 | % (trigger is the SYNC packet) |
| 130 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 131 | % Enable transmitter radio path on radio 2 in transmitter node (enable |
| 132 | % radio 2 in transmitter node as transmitter) |
| 133 | warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum); |
| 134 | |
| 135 | % Enable receiver radio path in receiver node (enable radio 2 and |
| 136 | % radio 3 in receiver node as receivers) |
| 137 | warplab_sendCmd(udp_RxA, [RADIO2_RXEN RADIO3_RXEN], packetNum); |
| 138 | |
| 139 | % Prime transmitter state machine in transmitter node. Transmitter will be |
| 140 | % waiting for the SYNC packet. Transmission will be triggered when the |
| 141 | % transmitter node receives the SYNC packet. |
| 142 | warplab_sendCmd(udp_Tx, TX_START, packetNum); |
| 143 | |
| 144 | % Prime receiver state machine in receiver node. Receiver will be waiting |
| 145 | % for the SYNC packet. Capture will be triggered when the receiver |
| 146 | % node receives the SYNC packet. |
| 147 | warplab_sendCmd(udp_RxA, RX_START, packetNum); |
| 148 | |
| 149 | % Send the SYNC packet |
| 150 | warplab_sendSync(udp_Sync); |
| 151 | |
| 152 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 153 | % 0.3 Read the received smaples from the Warp board |
| 154 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 155 | % Read back the received samples from Rx radio2 |
| 156 | [Tx2_Rx2_RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset); |
| 157 | % Process the received samples to obtain meaningful data |
| 158 | [Tx2_Rx2_RxData,Tx2_Rx2_RxOTR] = warplab_processRawRxData(Tx2_Rx2_RawRxData); |
| 159 | % Read stored RSSI data |
| 160 | [Tx2_Rx2_RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8); |
| 161 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 162 | [Tx2_Rx2_RxRSSI] = warplab_processRawRSSIData(Tx2_Rx2_RawRSSIData); |
| 163 | |
| 164 | % Read back the received samples from Rx radio3 |
| 165 | [Tx2_Rx3_RawRxData] = warplab_readSMRO(udp_RxA, RADIO3_RXDATA, TxLength+CaptOffset); |
| 166 | % Process the received samples to obtain meaningful data |
| 167 | [Tx2_Rx3_RxData,Tx2_Rx3_RxOTR] = warplab_processRawRxData(Tx2_Rx3_RawRxData); |
| 168 | % Read stored RSSI data |
| 169 | [Tx2_Rx3_RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO3_RSSIDATA, (TxLength+CaptOffset)/8); |
| 170 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 171 | [Tx2_Rx3_RxRSSI] = warplab_processRawRSSIData(Tx2_Rx3_RawRSSIData); |
| 172 | |
| 173 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 174 | % 0.4 Reset and disable the boards |
| 175 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 176 | % Reset the receiver |
| 177 | warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum); |
| 178 | |
| 179 | % Disable the receiver radio 2 and radio 3 |
| 180 | warplab_sendCmd(udp_RxA, [RADIO2_RXDIS RADIO3_RXDIS], packetNum); |
| 181 | |
| 182 | % Disable the transmitter radio 2 |
| 183 | warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum); |
| 184 | |
| 185 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 186 | % 0.5 Prepare boards for transmission from Tx radio 3 and reception on |
| 187 | % both receiver antennas. Send trigger to start transmission and reception |
| 188 | % (trigger is the SYNC packet) |
| 189 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 190 | % Enable transmitter radio path on radio 3 in transmitter node (enable |
| 191 | % radio 3 in transmitter node as transmitter) |
| 192 | warplab_sendCmd(udp_Tx, RADIO3_TXEN, packetNum); |
| 193 | |
| 194 | % Enable receiver radio path in receiver node (enable radio 2 and |
| 195 | % radio 3 in receiver node as receivers) |
| 196 | warplab_sendCmd(udp_RxA, [RADIO2_RXEN RADIO3_RXEN], packetNum); |
| 197 | |
| 198 | % Prime transmitter state machine in transmitter node. Transmitter will be |
| 199 | % waiting for the SYNC packet. Transmission will be triggered when the |
| 200 | % transmitter node receives the SYNC packet. |
| 201 | warplab_sendCmd(udp_Tx, TX_START, packetNum); |
| 202 | |
| 203 | % Prime receiver state machine in receiver node. Receiver will be waiting |
| 204 | % for the SYNC packet. Capture will be triggered when the receiver |
| 205 | % node receives the SYNC packet. |
| 206 | warplab_sendCmd(udp_RxA, RX_START, packetNum); |
| 207 | |
| 208 | % Send the SYNC packet |
| 209 | warplab_sendSync(udp_Sync); |
| 210 | |
| 211 | |
| 212 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 213 | % 0.6 Read the received smaples from the Warp board |
| 214 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 215 | % Read back the received samples from Rx radio2 |
| 216 | [Tx3_Rx2_RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset); |
| 217 | % Process the received samples to obtain meaningful data |
| 218 | [Tx3_Rx2_RxData,Tx3_Rx2_RxOTR] = warplab_processRawRxData(Tx3_Rx2_RawRxData); |
| 219 | % Read stored RSSI data |
| 220 | [Tx3_Rx2_RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8); |
| 221 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 222 | [Tx3_Rx2_RxRSSI] = warplab_processRawRSSIData(Tx3_Rx2_RawRSSIData); |
| 223 | |
| 224 | % Read back the received samples from Rx radio3 |
| 225 | [Tx3_Rx3_RawRxData] = warplab_readSMRO(udp_RxA, RADIO3_RXDATA, TxLength+CaptOffset); |
| 226 | % Process the received samples to obtain meaningful data |
| 227 | [Tx3_Rx3_RxData,Tx3_Rx3_RxOTR] = warplab_processRawRxData(Tx3_Rx3_RawRxData); |
| 228 | % Read stored RSSI data |
| 229 | [Tx3_Rx3_RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO3_RSSIDATA, (TxLength+CaptOffset)/8); |
| 230 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 231 | [Tx3_Rx3_RxRSSI] = warplab_processRawRSSIData(Tx3_Rx3_RawRSSIData); |
| 232 | |
| 233 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 234 | % 0.7 Reset and disable the boards |
| 235 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 236 | % Reset the receiver |
| 237 | warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum); |
| 238 | |
| 239 | % Disable the receiver radio 2 and radio 3 |
| 240 | warplab_sendCmd(udp_RxA, [RADIO2_RXDIS RADIO3_RXDIS], packetNum); |
| 241 | |
| 242 | % Disable the transmitter radio 3 |
| 243 | warplab_sendCmd(udp_Tx, RADIO3_TXDIS, packetNum); |
| 244 | |
| 245 | % Close sockets |
| 246 | pnet('closeall'); |
| 247 | |
| 248 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 249 | % 0.8 Plot the transmitted and received data |
| 250 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 251 | figure; |
| 252 | subplot(5,2,1); |
| 253 | plot(real(TxData)); |
| 254 | title('Tx Radio 2 I and Tx Radio 3 I '); |
| 255 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 256 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 257 | subplot(5,2,2); |
| 258 | plot(imag(TxData)); |
| 259 | title('Tx Radio 2 Q Tx Radio 3 Q '); |
| 260 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 261 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 262 | subplot(5,2,3); |
| 263 | plot(real(Tx2_Rx2_RxData)); |
| 264 | title('Rx Radio 2 I when Tx Radio 2 was transmitting'); |
| 265 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 266 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 267 | subplot(5,2,4); |
| 268 | plot(imag(Tx2_Rx2_RxData)); |
| 269 | title('Rx Radio 2 Q when Tx Radio 2 was transmitting'); |
| 270 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 271 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 272 | subplot(5,2,5); |
| 273 | plot(real(Tx2_Rx3_RxData)); |
| 274 | title('Rx Radio 3 I when Tx Radio 2 was transmitting'); |
| 275 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 276 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 277 | subplot(5,2,6); |
| 278 | plot(imag(Tx2_Rx3_RxData)); |
| 279 | title('Rx Radio 3 Q when Tx Radio 2 was transmitting'); |
| 280 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 281 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 282 | subplot(5,2,7); |
| 283 | plot(real(Tx3_Rx2_RxData)); |
| 284 | title('Rx Radio 2 I when Tx Radio 3 was transmitting'); |
| 285 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 286 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 287 | subplot(5,2,8); |
| 288 | plot(imag(Tx3_Rx2_RxData)); |
| 289 | title('Rx Radio 2 Q when Tx Radio 3 was transmitting'); |
| 290 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 291 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 292 | subplot(5,2,9); |
| 293 | plot(real(Tx3_Rx3_RxData)); |
| 294 | title('Rx Radio 3 I when Tx Radio 3 was transmitting'); |
| 295 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 296 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 297 | subplot(5,2,10); |
| 298 | plot(imag(Tx3_Rx3_RxData)); |
| 299 | title('Rx Radio 3 Q when Tx Radio 3 was transmitting'); |
| 300 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 301 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 302 | |
| 303 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 304 | % 1. Remove from the received vector the samples that do not correspond to |
| 305 | % transmitted data. In other words, remove from the received vector samples |
| 306 | % 1 to CaptOffset. This step will remove samples that correspond to measured |
| 307 | % noise and make the RxData vector the same length as the TxData vector |
| 308 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 309 | Tx2_Rx2_RxData = Tx2_Rx2_RxData(CaptOffset+1:end); |
| 310 | Tx2_Rx3_RxData = Tx2_Rx3_RxData(CaptOffset+1:end); |
| 311 | Tx3_Rx2_RxData = Tx3_Rx2_RxData(CaptOffset+1:end); |
| 312 | Tx3_Rx3_RxData = Tx3_Rx3_RxData(CaptOffset+1:end); |
| 313 | |
| 314 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 315 | % 2. Compute the amplitude and the phase of the transmitted and received |
| 316 | % sammples |
| 317 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 318 | % Compute the magnitude per sample of the transmitted and received |
| 319 | % data |
| 320 | mag_TxData = abs(TxData); % Tx data |
| 321 | mag_Tx2_Rx2_RxData = abs(Tx2_Rx2_RxData); |
| 322 | mag_Tx2_Rx3_RxData = abs(Tx2_Rx3_RxData); |
| 323 | mag_Tx3_Rx2_RxData = abs(Tx3_Rx2_RxData); |
| 324 | mag_Tx3_Rx3_RxData = abs(Tx3_Rx3_RxData); |
| 325 | |
| 326 | % Compute the phase per sample of the transmitted data |
| 327 | phase_TxData = angle(TxData); |
| 328 | phase_TxData_unw = unwrap(phase_TxData); |
| 329 | phase_TxData = phase_TxData *180/pi; %Convert to degrees |
| 330 | phase_TxData_unw = phase_TxData_unw *180/pi; %Convert to degrees |
| 331 | |
| 332 | phase_Tx2_Rx2_RxData = angle(Tx2_Rx2_RxData); |
| 333 | phase_Tx2_Rx2_RxData_unw = unwrap(phase_Tx2_Rx2_RxData); |
| 334 | phase_Tx2_Rx2_RxData = phase_Tx2_Rx2_RxData *180/pi; %Convert to degrees |
| 335 | phase_Tx2_Rx2_RxData_unw = phase_Tx2_Rx2_RxData_unw *180/pi; %Convert to degrees |
| 336 | |
| 337 | phase_Tx2_Rx3_RxData = angle(Tx2_Rx3_RxData); |
| 338 | phase_Tx2_Rx3_RxData_unw = unwrap(phase_Tx2_Rx3_RxData); |
| 339 | phase_Tx2_Rx3_RxData = phase_Tx2_Rx3_RxData *180/pi; %Convert to degrees |
| 340 | phase_Tx2_Rx3_RxData_unw = phase_Tx2_Rx3_RxData_unw *180/pi; %Convert to degrees |
| 341 | |
| 342 | phase_Tx3_Rx2_RxData = angle(Tx3_Rx2_RxData); |
| 343 | phase_Tx3_Rx2_RxData_unw = unwrap(phase_Tx3_Rx2_RxData); |
| 344 | phase_Tx3_Rx2_RxData = phase_Tx3_Rx2_RxData *180/pi; %Convert to degrees |
| 345 | phase_Tx3_Rx2_RxData_unw = phase_Tx3_Rx2_RxData_unw *180/pi; %Convert to degrees |
| 346 | |
| 347 | phase_Tx3_Rx3_RxData = angle(Tx3_Rx3_RxData); |
| 348 | phase_Tx3_Rx3_RxData_unw = unwrap(phase_Tx3_Rx3_RxData); |
| 349 | phase_Tx3_Rx3_RxData = phase_Tx3_Rx3_RxData *180/pi; %Convert to degrees |
| 350 | phase_Tx3_Rx3_RxData_unw = phase_Tx3_Rx3_RxData_unw *180/pi; %Convert to degrees |
| 351 | |
| 352 | % Plot magnitude and phase of transmitted and received samples |
| 353 | figure; |
| 354 | subplot(5,2,1); |
| 355 | plot(mag_TxData); |
| 356 | title('Tx Radio 2 magnitude and Tx Radio 3 magnitude '); |
| 357 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 358 | subplot(5,2,2); |
| 359 | plot(phase_TxData_unw); |
| 360 | title('Tx Radio 2 phase Tx Radio 3 phase '); |
| 361 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 362 | subplot(5,2,3); |
| 363 | plot(mag_Tx2_Rx2_RxData); |
| 364 | title('Rx Radio 2 magnitude when Tx Radio 2 was transmitting'); |
| 365 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 366 | subplot(5,2,4); |
| 367 | plot(phase_Tx2_Rx2_RxData_unw); |
| 368 | title('Rx Radio 2 phase when Tx Radio 2 was transmitting'); |
| 369 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 370 | subplot(5,2,5); |
| 371 | plot(mag_Tx2_Rx3_RxData); |
| 372 | title('Rx Radio 3 magnitude when Tx Radio 2 was transmitting'); |
| 373 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 374 | subplot(5,2,6); |
| 375 | plot(phase_Tx2_Rx3_RxData_unw); |
| 376 | title('Rx Radio 3 phase when Tx Radio 2 was transmitting'); |
| 377 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 378 | subplot(5,2,7); |
| 379 | plot(mag_Tx3_Rx2_RxData); |
| 380 | title('Rx Radio 2 magnitude when Tx Radio 3 was transmitting'); |
| 381 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 382 | subplot(5,2,8); |
| 383 | plot(phase_Tx3_Rx2_RxData_unw); |
| 384 | title('Rx Radio 2 phase when Tx Radio 3 was transmitting'); |
| 385 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 386 | subplot(5,2,9); |
| 387 | plot(mag_Tx3_Rx3_RxData); |
| 388 | title('Rx Radio 3 magnitude when Tx Radio 3 was transmitting'); |
| 389 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 390 | subplot(5,2,10); |
| 391 | plot(phase_Tx3_Rx3_RxData_unw); |
| 392 | title('Rx Radio 3 phase when Tx Radio 3 was transmitting'); |
| 393 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 394 | |
| 395 | % Plot magnitude and phase of transmitted and received samples |
| 396 | |
| 397 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 398 | % 3. Compute the channel amplitude and channel phase per sample |
| 399 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 400 | % Compute the channel amplitudes |
| 401 | channel_amplitude_Tx2_Rx2 = mag_Tx2_Rx2_RxData./mag_TxData; |
| 402 | channel_amplitude_Tx2_Rx3 = mag_Tx2_Rx3_RxData./mag_TxData; |
| 403 | channel_amplitude_Tx3_Rx2 = mag_Tx3_Rx2_RxData./mag_TxData; |
| 404 | channel_amplitude_Tx3_Rx3 = mag_Tx3_Rx3_RxData./mag_TxData; |
| 405 | |
| 406 | % Compute the channel phases |
| 407 | channel_phase_Tx2_Rx2 = phase_Tx2_Rx2_RxData_unw - phase_TxData_unw; |
| 408 | channel_phase_Tx2_Rx3 = phase_Tx2_Rx3_RxData_unw - phase_TxData_unw; |
| 409 | channel_phase_Tx3_Rx2 = phase_Tx3_Rx2_RxData_unw - phase_TxData_unw; |
| 410 | channel_phase_Tx3_Rx3 = phase_Tx3_Rx3_RxData_unw - phase_TxData_unw; |
| 411 | |
| 412 | % Plot channel amplitude |
| 413 | figure |
| 414 | subplot(2,2,1) |
| 415 | plot(channel_amplitude_Tx2_Rx2) |
| 416 | title('Tx2-Rx2 path - Channel Amplitude per sample') |
| 417 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 418 | subplot(2,2,2) |
| 419 | plot(channel_amplitude_Tx2_Rx3) |
| 420 | title('Tx2-Rx3 path - Channel Amplitude per sample') |
| 421 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 422 | subplot(2,2,3) |
| 423 | plot(channel_amplitude_Tx3_Rx2) |
| 424 | title('Tx3-Rx2 path - Channel Amplitude per sample') |
| 425 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 426 | subplot(2,2,4) |
| 427 | plot(channel_amplitude_Tx3_Rx3) |
| 428 | title('Tx3-Rx3 path - Channel Amplitude per sample') |
| 429 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 430 | |
| 431 | %Plot channel phase |
| 432 | figure |
| 433 | subplot(2,2,1) |
| 434 | plot(channel_phase_Tx2_Rx2) |
| 435 | xlabel('n (samples)'); ylabel('Degrees'); |
| 436 | title('Tx2-Rx2 path - Channel Phase per sample') |
| 437 | subplot(2,2,2) |
| 438 | plot(channel_phase_Tx2_Rx3) |
| 439 | xlabel('n (samples)'); ylabel('Degrees'); |
| 440 | title('Tx2-Rx3 path - Channel Phase per sample') |
| 441 | subplot(2,2,3) |
| 442 | plot(channel_phase_Tx3_Rx2) |
| 443 | xlabel('n (samples)'); ylabel('Degrees'); |
| 444 | title('Tx3-Rx2 path - Channel Phase per sample') |
| 445 | subplot(2,2,4) |
| 446 | plot(channel_phase_Tx3_Rx3) |
| 447 | xlabel('n (samples)'); ylabel('Degrees'); |
| 448 | title('Tx3-Rx3 path - Channel Phase per sample') |
| 449 | |
| 450 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 451 | % Code to avoid conflict between users, only needed for the workshop |
| 452 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 453 | pnet('closeall'); |
| 454 | !del c:\boards_lock.txt |
| 455 | catch, |
| 456 | % Close sockets |
| 457 | pnet('closeall'); |
| 458 | !del c:\boards_lock.txt |
| 459 | lasterr |
| 460 | end |
Note: See TracBrowser
for help on using the browser.