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