root/ResearchApps/PHY/WARPLAB/WARPLab_SISO_MIMO2x2/M_Code/warplab_siso_example_TxRxTwoWay.m
| Revision 839, 9.8 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 | |
| 29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 30 | % 0. Initializaton and definition of parameters |
| 31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 32 | %Load some global definitions (packet types, etc.) |
| 33 | warplab_defines |
| 34 | |
| 35 | % Create Socket handles and intialize nodes |
| 36 | [socketHandles, packetNum] = warplab_initialize; |
| 37 | |
| 38 | %Separate the socket handles for easier access |
| 39 | % The first socket handle is always the magic SYNC |
| 40 | % The rest can be arranged in any combination of Tx and Rx |
| 41 | udp_Sync = socketHandles(1); |
| 42 | udp_nodeA = socketHandles(2); |
| 43 | udp_nodeB = socketHandles(3); |
| 44 | |
| 45 | % Define the warplab options (parameters) |
| 46 | CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14] |
| 47 | TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset] |
| 48 | TransMode = 0; %Transmission mode; in [0:1] |
| 49 | % 0: Single Transmission |
| 50 | % 1: Continuous Transmission. Tx board will continue |
| 51 | % transmitting the vector of samples until the user manually |
| 52 | % disables the transmitter. |
| 53 | CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14] |
| 54 | TxGainBB = 3; %Tx Baseband Gain in [0:3] |
| 55 | TxGainRF = 40; %Tx RF Gain in [0:63] |
| 56 | RxGainBB = 15; %Rx Baseband Gain in [0:31] |
| 57 | RxGainRF = 1; %Rx RF Gain in [1:3] |
| 58 | |
| 59 | % Define the options vector; the order of options is set by the FPGA's code |
| 60 | % (C code) |
| 61 | optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)]; |
| 62 | % Send options vector to the nodes |
| 63 | warplab_setOptions(socketHandles,optionsVector); |
| 64 | |
| 65 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 66 | % 1. Generate the vector of samples that node A will transmit to node B and |
| 67 | % the vector of samples that node B will transmit to node A, then download |
| 68 | % the samples to the Warp boards (Sample Frequency is 40MHz) |
| 69 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 70 | % Create time vector. |
| 71 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; |
| 72 | |
| 73 | % Create a signal to transmit from node A to node B |
| 74 | TxDataAB = exp(t*j*2*pi*1e6); %Signal must be a row vector. The signal can |
| 75 | % be real or complex, the only constraint is that the amplitude of the real |
| 76 | % part must be in [-1:1] and the amplitude of the imaginary part must be |
| 77 | % in [-1:1] |
| 78 | |
| 79 | % Download the samples to be transmitted |
| 80 | warplab_writeSMWO(udp_nodeA, TxDataAB, RADIO2_TXDATA); % Download samples to node A |
| 81 | |
| 82 | % Create a signal to transmit from node B to node A |
| 83 | TxDataBA = linspace(0,1,TxLength).*exp(t*j*2*pi*5e6); |
| 84 | % Signal must be a row vector. The signal can be real or complex, |
| 85 | % the only constraint is that the amplitude of the real part must be in |
| 86 | % [-1:1] and the amplitude of the imaginary part must be in [-1:1] |
| 87 | |
| 88 | warplab_writeSMWO(udp_nodeB, TxDataBA, RADIO2_TXDATA); % Download samples to node B |
| 89 | |
| 90 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 91 | % 2. Prepare boards for transmission and reception from node A to node B |
| 92 | % and send trigger to start transmission and reception (trigger is the SYNC |
| 93 | % packet) |
| 94 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 95 | % Enable transmitter radio path in node A |
| 96 | warplab_sendCmd(udp_nodeA, RADIO2_TXEN, packetNum); |
| 97 | |
| 98 | % Enable receiver radio path in node B |
| 99 | warplab_sendCmd(udp_nodeB, RADIO2_RXEN, packetNum); |
| 100 | |
| 101 | % Prime transmitter state machine in node A. Node A will be waiting for |
| 102 | % the SYNC packet. Transmission will be triggered when node A receives |
| 103 | % the SYNC packet. |
| 104 | warplab_sendCmd(udp_nodeA, TX_START, packetNum); |
| 105 | |
| 106 | % Prime receiver state machine in node B. Node B will be waiting for |
| 107 | % the SYNC packet. Capture will be triggered when node B receives |
| 108 | % the SYNC packet. |
| 109 | warplab_sendCmd(udp_nodeB, RX_START, packetNum); |
| 110 | |
| 111 | % Send the SYNC packet |
| 112 | warplab_sendSync(udp_Sync) |
| 113 | |
| 114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 115 | % 3. Disable the radios |
| 116 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 117 | % Disable the receiver |
| 118 | warplab_sendCmd(udp_nodeB, RADIO2_RXDIS, packetNum); |
| 119 | |
| 120 | % Disable the transmitter |
| 121 | warplab_sendCmd(udp_nodeA, RADIO2_TXDIS, packetNum); |
| 122 | |
| 123 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 124 | % 4. Prepare boards for transmission and reception from node B to node A |
| 125 | % and send trigger to start transmission and reception (trigger is the SYNC |
| 126 | % packet) |
| 127 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 128 | % Enable transmitter radio path in node B |
| 129 | warplab_sendCmd(udp_nodeB, RADIO2_TXEN, packetNum); |
| 130 | |
| 131 | % Enable receiver radio path in node A |
| 132 | warplab_sendCmd(udp_nodeA, RADIO2_RXEN, packetNum); |
| 133 | |
| 134 | % Prime transmitter state machine in node B. Node B will be waiting for |
| 135 | % the SYNC packet. Transmission will be triggered when node B receives |
| 136 | % the SYNC packet. |
| 137 | warplab_sendCmd(udp_nodeB, TX_START, packetNum); |
| 138 | |
| 139 | % Prime receiver state machine in node A. Node A will be waiting for |
| 140 | % the SYNC packet. Capture will be triggered when node A receives |
| 141 | % the SYNC packet. |
| 142 | warplab_sendCmd(udp_nodeA, RX_START, packetNum); |
| 143 | |
| 144 | % Send the SYNC packet |
| 145 | warplab_sendSync(udp_Sync) |
| 146 | |
| 147 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 148 | % 5. Disable the radios |
| 149 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 150 | % Disable the receiver |
| 151 | warplab_sendCmd(udp_nodeA, RADIO2_RXDIS, packetNum); |
| 152 | |
| 153 | % Disable the transmitter |
| 154 | warplab_sendCmd(udp_nodeB, RADIO2_TXDIS, packetNum); |
| 155 | |
| 156 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 157 | % 6. Read the received samples from the Warp boards |
| 158 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 159 | % Read back the received samples sent from A to B |
| 160 | [RawRxDataAB] = warplab_readSMRO(udp_nodeB, RADIO2_RXDATA, TxLength+CaptOffset); |
| 161 | % Process the received samples to obtain meaningful data |
| 162 | [RxDataAB,RxOTRAB] = warplab_processRawRxData(RawRxDataAB); |
| 163 | % Read stored RSSI data corresponding to A to B transmission |
| 164 | [RawRSSIDataAB] = warplab_readSMRO(udp_nodeB, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8); |
| 165 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 166 | [RxRSSIAB] = warplab_processRawRSSIData(RawRSSIDataAB); |
| 167 | |
| 168 | % Read back the received samples sent from B to A |
| 169 | [RawRxDataBA] = warplab_readSMRO(udp_nodeA, RADIO2_RXDATA, TxLength+CaptOffset); |
| 170 | % Process the received samples to obtain meaningful data |
| 171 | [RxDataBA,RxOTRBA] = warplab_processRawRxData(RawRxDataBA); |
| 172 | % Read stored RSSI data corresponding to B to A transmission |
| 173 | [RawRSSIDataBA] = warplab_readSMRO(udp_nodeA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8); |
| 174 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 175 | [RxRSSIBA] = warplab_processRawRSSIData(RawRSSIDataBA); |
| 176 | |
| 177 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 178 | % 7. Reset the boards and close sockets |
| 179 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 180 | % Reset node A |
| 181 | warplab_sendCmd(udp_nodeA, RX_DONEREADING, packetNum); |
| 182 | |
| 183 | % Reset node B |
| 184 | warplab_sendCmd(udp_nodeB, RX_DONEREADING, packetNum); |
| 185 | |
| 186 | % Close sockets |
| 187 | pnet('closeall'); |
| 188 | |
| 189 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 190 | % 5. Plot the transmitted and received data |
| 191 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 192 | % Plot data from A to B transmissio |
| 193 | figure; |
| 194 | subplot(2,2,1); |
| 195 | plot(real(TxDataAB)); |
| 196 | title('Tx I A to B'); |
| 197 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 198 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 199 | subplot(2,2,2); |
| 200 | plot(imag(TxDataAB)); |
| 201 | title('Tx Q A to B'); |
| 202 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 203 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 204 | subplot(2,2,3); |
| 205 | plot(real(RxDataAB)); |
| 206 | title('Rx I A to B'); |
| 207 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 208 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 209 | subplot(2,2,4); |
| 210 | plot(imag(RxDataAB)); |
| 211 | title('Rx Q A to B'); |
| 212 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 213 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 214 | |
| 215 | % Plot data from B to A transmission |
| 216 | figure; |
| 217 | subplot(2,2,1); |
| 218 | plot(real(TxDataBA)); |
| 219 | title('Tx I B to A'); |
| 220 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 221 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 222 | subplot(2,2,2); |
| 223 | plot(imag(TxDataBA)); |
| 224 | title('Tx Q B to A'); |
| 225 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 226 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 227 | subplot(2,2,3); |
| 228 | plot(real(RxDataBA)); |
| 229 | title('Rx I B to A'); |
| 230 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 231 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 232 | subplot(2,2,4); |
| 233 | plot(imag(RxDataBA)); |
| 234 | title('Rx Q B to A'); |
| 235 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 236 | axis([0 2^14 -1 1]); % Set axis ranges. |
Note: See TracBrowser
for help on using the browser.