1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | % Transmitting and Receiving Data using WARPLab with Automatic Gain Control |
---|
3 | % (SISO Configuration) |
---|
4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
5 | % To run this M-code the boards must be programmed with the |
---|
6 | % 4x4 MIMO 5.x version of WARPLab bitstream |
---|
7 | |
---|
8 | % Before looking at this code we recommend getting familiar with the |
---|
9 | % warplab_siso_example_TxRx.m code which doesn't use AGC hence it is easier |
---|
10 | % to understand. |
---|
11 | |
---|
12 | % The specific steps implemented in this script are the following |
---|
13 | |
---|
14 | % 0. Initializaton and definition of parameters |
---|
15 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
16 | % WARP board (Sample Frequency is 40MHz) |
---|
17 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
18 | % start transmission and reception (trigger is the SYNC packet) |
---|
19 | % 3. Read the received samples from the WARP board |
---|
20 | % 4. Read values related to AGC |
---|
21 | % 5. Reset and disable the boards |
---|
22 | % 6. Plot the transmitted and received data and close sockets |
---|
23 | |
---|
24 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
25 | % 0. Initializaton and definition of parameters |
---|
26 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
27 | %Load some global definitions (packet types, etc.) |
---|
28 | warplab_defines |
---|
29 | |
---|
30 | % Create Socket handles and intialize nodes |
---|
31 | [socketHandles, packetNum] = warplab_initialize; |
---|
32 | |
---|
33 | % Separate the socket handles for easier access |
---|
34 | % The first socket handle is always the magic SYNC |
---|
35 | % The rest of the handles are the handles to the WARP nodes |
---|
36 | udp_Sync = socketHandles(1); |
---|
37 | udp_node1 = socketHandles(2); |
---|
38 | udp_node2 = socketHandles(3); |
---|
39 | |
---|
40 | % Define WARPLab parameters. |
---|
41 | % For this experiment node 1 will be set as the transmitter and node |
---|
42 | % 2 will be set as the receiver (this is done later in the code), hence, |
---|
43 | % there is no need to define receive gains for node 1 and there is no |
---|
44 | % need to define transmitter gains for node 2. |
---|
45 | TxDelay = 0; % Number of noise samples per Rx capture. In [0:2^14] |
---|
46 | TxLength = 2^14-1; % Length of transmission. In [0:2^14-1-TxDelay] |
---|
47 | CarrierChannel = 12; % Channel in the 2.4 GHz band. In [1:14] |
---|
48 | Node1_Radio2_TxGain_BB = 1; % Tx Baseband Gain. In [0:3] |
---|
49 | Node1_Radio2_TxGain_RF = 25; % Tx RF Gain. In [0:63] |
---|
50 | TxMode = 0; % Transmission mode. In [0:1] |
---|
51 | % 0: Single Transmission |
---|
52 | % 1: Continuous Transmission. Tx board will continue |
---|
53 | % transmitting the vector of samples until the user manually |
---|
54 | % disables the transmitter. |
---|
55 | Node2_MGC_AGC_Select = 1; % Set MGC_AGC_Select=1 to enable Automatic Gain Control (AGC). |
---|
56 | % Set MGC_AGC_Select=0 to enable Manual Gain Control (MGC). |
---|
57 | % By default, the nodes are set to MGC. |
---|
58 | Node2_TargetdBmAGC = -10; % AGC Target dBm. A larger target value will |
---|
59 | % result in larger Rx gains set by AGC. This is |
---|
60 | % the value we tune if AGC is not setting gains |
---|
61 | % correctly. |
---|
62 | Node2_NoiseEstdBmAGC = -95; % Noise power in dBm. -95dBm is a reasonable |
---|
63 | % value for wireless. If AGC is not setting gains correctly |
---|
64 | % this value may need to be modified. Usually we first try to |
---|
65 | % change the TargetdBmAGC before changing the NoiseEstdBmAGC |
---|
66 | Node2_Thresh1 = -90; |
---|
67 | Node2_Thresh2 = -53; |
---|
68 | Node2_Thresh3 = -43; |
---|
69 | % Change format of Thresholds so they can be correctly understood by |
---|
70 | % the FPGA: |
---|
71 | Node_2Thresholds = uint32(Node2_Thresh3+2^8)*2^16+uint32(Node2_Thresh2+2^8)*2^8+uint32(Node2_Thresh1+2^8); |
---|
72 | % The three thresholds above are used to set the Rx RF gain. If the RSSI in |
---|
73 | % dBm of the received signal is less than -90 then the AGC declares the |
---|
74 | % signal to be too low and quits. If the RSSI in dBm of the received signal |
---|
75 | % is between -53 and -90 then the AGC selects the largest RF gain : 3. If |
---|
76 | % the RSSI dBm is between -43 and -53 then the AGC sets medium RF gain : 2. If |
---|
77 | % the RSSI dBm is larger than -43 then the AGC sets low RF gain :1. |
---|
78 | % If AGC is no setting gains correctly then these three thresholds may need |
---|
79 | % to be modified. Usually we first try to change the TargetdBmAGC before |
---|
80 | % changing the Thresholds. |
---|
81 | % Remember there are 3 possible Rx RF gains: 1,2,3. Each step corresponds |
---|
82 | % to 15dB: Changing the gain from 2 to 3 increases the Rx gain by 15 dB. |
---|
83 | Node2_AGCTrigger_nsamps_delay = 50; % The AGC core should not be started before the |
---|
84 | % signal arrives. If TxDelay=0 then Tx and Rx should start at exactly the |
---|
85 | % same time (upon reception of magic sync) however, because of jitter in |
---|
86 | % reception of the magic sync, it may happed that the Rx gets the magic |
---|
87 | % sync before the Tx. If this is the case then the AGC will set wrong gains |
---|
88 | % because AGC will use RSSI values that are measured before reception of the signal. |
---|
89 | % To avoid this we can delay the trigger of the AGC core by |
---|
90 | % Node2_AGCTrigger_nsamps_delay samples relative to the reception of the |
---|
91 | % magic sync. We recommend to set this value between 0 and 50 samples. We |
---|
92 | % have not observed magic sync jitters greater than 50 samples. |
---|
93 | Node2_Enable_DCOffset_Correction = 1; % Enable/disable correction of DC Offsets (DCO). |
---|
94 | % Node2_Enable_DCOffset_Correction = 0; Disable correction of DC Offsets at |
---|
95 | % AGC |
---|
96 | % Node2_Enable_DCOffset_Correction = 1; Enable correction of DC Offsets at |
---|
97 | % AGC |
---|
98 | % Change of Rx gains by AGC may result in DC offsets. The AGC can correct |
---|
99 | % these offsets but the user must be very careful on the choice of preamble |
---|
100 | % used for AGC. For DCO correction at AGC to work properly the first 320 |
---|
101 | % samples must correspond to a periodic signal with an average (DC) of zero |
---|
102 | % over 32 consecutive samples, this will generate the right signal required |
---|
103 | % by AGC DCO correction for a sampling frequency of 40 MHz. AGC DCO |
---|
104 | % correction can be disabled by setting Node2_Enable_DCOffset_Correction=0, |
---|
105 | % in this case there is no requirement for the periodicity of the |
---|
106 | % preamble used for AGC. |
---|
107 | |
---|
108 | % NOTES ON AGC: |
---|
109 | % 1. As soon as AGC is triggered, it takes the AGC core |
---|
110 | % approximately 250 samples (at 40MHz sampling frequency) to set gains. If |
---|
111 | % DCO correction at AGC is enabled it takes the AGC an extra 32 samples to |
---|
112 | % filter DCO. This means that the first 250 samples received (282 when using DCO |
---|
113 | % correction) may not contain useful data because during reception of these |
---|
114 | % samples Rx gains (and DCO correction) were not set correctly. |
---|
115 | % 2. The first 250 samples must be representative of the rest of signal |
---|
116 | % being transmitted (similar bandwidth and amplitude), otherwise the gains |
---|
117 | % set by the AGC will work for the first 250 samples but will be wrong |
---|
118 | % (causing saturation or underflow) for the rest of the signal. |
---|
119 | |
---|
120 | % Download the WARPLab parameters to the WARP nodes. |
---|
121 | % The nodes store the TxDelay, TxLength, and TxMode parameters in |
---|
122 | % registers defined in the WARPLab sysgen model. The nodes set radio |
---|
123 | % related parameters CarrierChannel, TxGains, and RxGains, using the |
---|
124 | % radio controller functions. |
---|
125 | |
---|
126 | % The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter; |
---|
127 | % the receiver doesn't require knowledge of these parameters (the receiver |
---|
128 | % will always capture 2^14 samples). For this exercise node 1 will be set as |
---|
129 | % the transmitter (this is done later in the code). Since TxDelay, TxLength and |
---|
130 | % TxMode are only required at the transmitter we download the TxDelay, TxLength and |
---|
131 | % TxMode parameters only to the transmitter node (node 1). |
---|
132 | warplab_writeRegister(udp_node1,TX_DELAY,TxDelay); |
---|
133 | warplab_writeRegister(udp_node1,TX_LENGTH,TxLength); |
---|
134 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
135 | % The CarrierChannel parameter must be downloaded to all nodes |
---|
136 | warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel); |
---|
137 | warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel); |
---|
138 | % Node 1 will be set as the transmitter so download Tx gains to node 1. |
---|
139 | warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16)); |
---|
140 | % Node 2 will be set as the receiver so download AGC related parameters to node 2. |
---|
141 | warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select); % AGC mode is enabled when |
---|
142 | % Node2_MGC_AGC_Select = 1. THIS COMMAND RESETS AND INITIALIZES THE AGC. THIS COMMAND INITIALIZES |
---|
143 | % AGC PARAMETER TO DEFAULTS. Default values are hard coded in warplab C code. |
---|
144 | % The default values can be changed as is done in the 5 lines below. |
---|
145 | warplab_setAGCParameter(udp_node2,SET_AGC_TARGET_dBm, Node2_TargetdBmAGC); |
---|
146 | warplab_setAGCParameter(udp_node2,SET_AGC_NOISEEST_dBm, Node2_NoiseEstdBmAGC); |
---|
147 | warplab_setAGCParameter(udp_node2,SET_AGC_THRESHOLDS, Node_2Thresholds); |
---|
148 | warplab_setAGCParameter(udp_node2,SET_AGC_TRIG_DELAY, Node2_AGCTrigger_nsamps_delay); |
---|
149 | warplab_setAGCParameter(udp_node2,SET_AGC_DCO_EN_DIS, Node2_Enable_DCOffset_Correction); |
---|
150 | |
---|
151 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
152 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
153 | % WARP board (Sample Frequency is 40MHz) |
---|
154 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
155 | % First generate the preamble for AGC. The preamble corresponds to the |
---|
156 | % short symbols borrowed from the 802.11a PHY standard |
---|
157 | shortSymbol_freq = [0 0 0 0 0 0 0 0 1+i 0 0 0 -1+i 0 0 0 -1-i 0 0 0 1-i 0 0 0 -1-i 0 0 0 1-i 0 0 0 0 0 0 0 1-i 0 0 0 -1-i 0 0 0 1-i 0 0 0 -1-i 0 0 0 -1+i 0 0 0 1+i 0 0 0 0 0 0 0].'; |
---|
158 | shortSymbol_time = ifft(fftshift(shortSymbol_freq)); |
---|
159 | shortSymbol_time = shortSymbol_time(1:16).'; |
---|
160 | shortsyms_10 = repmat(shortSymbol_time,1,10); |
---|
161 | preamble_I = real(shortsyms_10); |
---|
162 | preamble_Q = imag(shortsyms_10); |
---|
163 | % Upsample by 2 so the standard preamble occupies a bandwith of +-10MHz (computed |
---|
164 | % for a sampling frequency of 40 MHz) |
---|
165 | [preamble_I_up2] = interp(preamble_I, 2); |
---|
166 | [preamble_Q_up2] = interp(preamble_Q, 2); |
---|
167 | % Scale to span -1,1 range of DAC |
---|
168 | scale_ShortSyms = max([ max(abs(preamble_I_up2)), max(abs(preamble_Q_up2)) ]); |
---|
169 | [preamble_I_up2] = (1/scale_ShortSyms)*preamble_I_up2; |
---|
170 | [preamble_Q_up2] = (1/scale_ShortSyms)*preamble_Q_up2; |
---|
171 | ShortTrainingSyms_up2 = (preamble_I_up2 + sqrt(-1)*preamble_Q_up2); |
---|
172 | % Notice that ShortTrainingSyms_up2 meets periodicity requirement for |
---|
173 | % correct function of AGC DC Offset correction |
---|
174 | |
---|
175 | |
---|
176 | % Create a signal to transmit after AGC preamble |
---|
177 | |
---|
178 | % The signal must meet the following requirements: |
---|
179 | % - Signal to transmit must be a row vector. |
---|
180 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
181 | % of the imaginary part must be in [-1:1]. |
---|
182 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
183 | % is limited to 19 MHz) |
---|
184 | % - Lowest frequency component is limited to 30 kHz |
---|
185 | |
---|
186 | % We will send 1000 zeros after AGC preamble, then we will send one |
---|
187 | % sequence of long training symbols borrowed from the 802.11a PHY standard, |
---|
188 | % then we will anlternate bewteen zeros and long training symbols and |
---|
189 | % short training symbols |
---|
190 | |
---|
191 | % Generate zero vector |
---|
192 | zero_vector = zeros(1,1000); |
---|
193 | |
---|
194 | % Generate long 802.11a long training symbols. |
---|
195 | % Generate one long training symbol |
---|
196 | LongSymbol_freq_bot = [0 0 0 0 0 0 1 1 -1 -1 1 1 -1 1 -1 1 1 1 1 1 1 -1 -1 1 1 -1 1 -1 1 1 1 1]'; |
---|
197 | LongSymbol_freq_top = [1 -1 -1 1 1 -1 1 -1 1 -1 -1 -1 -1 -1 1 1 -1 -1 1 -1 1 -1 1 1 1 1 0 0 0 0 0]'; |
---|
198 | LongSymbol_freq = [LongSymbol_freq_bot ; 0 ; LongSymbol_freq_top]; |
---|
199 | LongSymbol_time = ifft(fftshift(LongSymbol_freq)).'; |
---|
200 | LongSymbol_time_up2 = interp(LongSymbol_time,2); % Upsample by 2 so that |
---|
201 | % the final LongTrainingSyms_up2 signal will have a bandwidth of +-10MHz |
---|
202 | % (computed for a sampling frequency of 40 MHz) |
---|
203 | scale = 1/max([ max(abs(real(LongSymbol_time_up2))), max(abs(imag(LongSymbol_time_up2))) ]); |
---|
204 | LongSymbol_time_up2 = scale * LongSymbol_time_up2; % Scale to span -1,1 range of DAC |
---|
205 | % Concatenate two long training symbols and add cyclic prefix |
---|
206 | %longsyms_2_cp = [longSymbol_time(33:64) repmat(longSymbol_time,1,2)]; |
---|
207 | %longsyms_2_cp_up2 = interp(longsyms_2_cp,2); % Upsample by 2 |
---|
208 | LongTrainingSyms_up2 = [LongSymbol_time_up2(65:128) repmat(LongSymbol_time_up2,1,2)]; |
---|
209 | |
---|
210 | Node1_Radio2_TxData = [ShortTrainingSyms_up2, zero_vector, LongTrainingSyms_up2, zero_vector]; |
---|
211 | Node1_Radio2_TxData = repmat(Node1_Radio2_TxData,1,5); |
---|
212 | Node1_Radio2_TxData = [Node1_Radio2_TxData zeros(1,TxLength-length(Node1_Radio2_TxData))]; |
---|
213 | |
---|
214 | % Download the samples to be transmitted |
---|
215 | warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData); |
---|
216 | |
---|
217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
218 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
219 | % start transmission and reception (trigger is the SYNC packet) |
---|
220 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
221 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
222 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
223 | % packet. |
---|
224 | |
---|
225 | % Enable transmitter radio path in radio 2 in node 1 (enable radio 2 in |
---|
226 | % node 1 as transmitter) |
---|
227 | warplab_sendCmd(udp_node1, RADIO2_TXEN, packetNum); |
---|
228 | |
---|
229 | % Enable transmission of node1's radio 2 Tx buffer (enable transmission |
---|
230 | % of samples stored in radio 2 Tx Buffer in node 1) |
---|
231 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXEN, packetNum); |
---|
232 | |
---|
233 | % Enable receiver radio path in all radios (enable all radios in node 2 as receiver) |
---|
234 | warplab_sendCmd(udp_node2, [RADIO1_RXEN RADIO2_RXEN RADIO3_RXEN RADIO4_RXEN], packetNum); |
---|
235 | |
---|
236 | % Enable capture in all of node2's radios Rx Buffer (enable rx buffers in |
---|
237 | % node 2 for storage of samples) |
---|
238 | warplab_sendCmd(udp_node2, [RADIO1RXBUFF_RXEN RADIO2RXBUFF_RXEN RADIO3RXBUFF_RXEN RADIO4RXBUFF_RXEN], packetNum); |
---|
239 | |
---|
240 | % Prime transmitter state machine in node 1. Node 1 will be |
---|
241 | % waiting for the SYNC packet. Transmission from node 1 will be triggered |
---|
242 | % when node 1 receives the SYNC packet. |
---|
243 | warplab_sendCmd(udp_node1, TX_START, packetNum); |
---|
244 | |
---|
245 | % Prime receiver state machine in node 2. Node 2 will be waiting |
---|
246 | % for the SYNC packet. Capture at node 2 will be triggered when node 2 |
---|
247 | % receives the SYNC packet. |
---|
248 | warplab_sendCmd(udp_node2, RX_START, packetNum); |
---|
249 | |
---|
250 | % Send the SYNC packet |
---|
251 | warplab_sendSync(udp_Sync); |
---|
252 | |
---|
253 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
254 | % 3. Read the received samples from the WARP board |
---|
255 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
256 | % Read back the received samples |
---|
257 | [Node2_Radio1_RawRxData] = warplab_readSMRO(udp_node2, RADIO1_RXDATA, TxLength+TxDelay); |
---|
258 | [Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay); |
---|
259 | [Node2_Radio3_RawRxData] = warplab_readSMRO(udp_node2, RADIO3_RXDATA, TxLength+TxDelay); |
---|
260 | [Node2_Radio4_RawRxData] = warplab_readSMRO(udp_node2, RADIO4_RXDATA, TxLength+TxDelay); |
---|
261 | % Process the received samples to obtain meaningful data |
---|
262 | [Node2_Radio1_RxData,Node2_Radio1_RxOTR] = warplab_processRawRxData(Node2_Radio1_RawRxData); |
---|
263 | [Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData); |
---|
264 | [Node2_Radio3_RxData,Node2_Radio3_RxOTR] = warplab_processRawRxData(Node2_Radio3_RawRxData); |
---|
265 | [Node2_Radio4_RxData,Node2_Radio4_RxOTR] = warplab_processRawRxData(Node2_Radio4_RawRxData); |
---|
266 | |
---|
267 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
268 | % 4. Read values related to AGC |
---|
269 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
270 | % Read the sample number that corresponds to AGC being done setting gains |
---|
271 | [Node2_AGC_Set_Addr] = warplab_readAGCValue(udp_node2, READ_AGC_DONE_ADDR); |
---|
272 | % Received samples are stored in Received buffer, when AGC is done the |
---|
273 | % address of the sample being written at that moment is stored, this |
---|
274 | % address is Node2_AGC_Set_Addr. This means that samples after |
---|
275 | % Node2_AGC_Set_Addr sample are applied the Rx Gains computed by AGC. From |
---|
276 | % sample zero the Node2_AGC_Set_Addr the amplitude of the received signal |
---|
277 | % may vary a lot because during this time the AGC was not done setting |
---|
278 | % gains. |
---|
279 | |
---|
280 | % Read the value of the RSSI that corresponds to AGC being done setting |
---|
281 | % gains. When AGC is done the currrent RSSI value measured by node 2 radio2 |
---|
282 | % and radio 3 is stored in registers which can be read as shown below. |
---|
283 | [Node2_Radio1_AGC_Set_RSSI] = warplab_readAGCValue(udp_node2, READ_RADIO1AGCDONERSSI); |
---|
284 | [Node2_Radio2_AGC_Set_RSSI] = warplab_readAGCValue(udp_node2, READ_RADIO2AGCDONERSSI); |
---|
285 | [Node2_Radio3_AGC_Set_RSSI] = warplab_readAGCValue(udp_node2, READ_RADIO3AGCDONERSSI); |
---|
286 | [Node2_Radio4_AGC_Set_RSSI] = warplab_readAGCValue(udp_node2, READ_RADIO4AGCDONERSSI); |
---|
287 | |
---|
288 | % Read the gains set by AGC |
---|
289 | [Node2_Raw_AGC_Set_Gains] = warplab_readAGCValue(udp_node2, READ_AGC_GAINS); |
---|
290 | [Node2_GainsRF,Node2_GainsBB] = warplab_processRawAGCGainsData(Node2_Raw_AGC_Set_Gains); |
---|
291 | Node2_Radio1_GainsRF = Node2_GainsRF(1); |
---|
292 | Node2_Radio1_GainsBB = Node2_GainsBB(1); |
---|
293 | Node2_Radio2_GainsRF = Node2_GainsRF(2); |
---|
294 | Node2_Radio2_GainsBB = Node2_GainsBB(2); |
---|
295 | Node2_Radio3_GainsRF = Node2_GainsRF(3); |
---|
296 | Node2_Radio3_GainsBB = Node2_GainsBB(3); |
---|
297 | Node2_Radio4_GainsRF = Node2_GainsRF(4); |
---|
298 | Node2_Radio4_GainsBB = Node2_GainsBB(4); |
---|
299 | |
---|
300 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
301 | % 5. Reset and disable the boards |
---|
302 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
303 | % Set radio 2 Tx buffer in node 1 back to Tx disabled mode |
---|
304 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXDIS, packetNum); |
---|
305 | |
---|
306 | % Disable the transmitter radio |
---|
307 | warplab_sendCmd(udp_node1, RADIO2_TXDIS, packetNum); |
---|
308 | |
---|
309 | % Set radio 2 and 3 Rx buffer in node 2 back to Rx disabled mode |
---|
310 | warplab_sendCmd(udp_node2, [RADIO1RXBUFF_RXDIS RADIO2RXBUFF_RXDIS RADIO3RXBUFF_RXDIS RADIO4RXBUFF_RXDIS], packetNum); |
---|
311 | |
---|
312 | % Disable the receiver radios |
---|
313 | warplab_sendCmd(udp_node2, [RADIO1_RXDIS RADIO2_RXDIS RADIO3_RXDIS RADIO4_RXDIS], packetNum); |
---|
314 | |
---|
315 | % Resets Rx gains to default values of RF Gain of 3 and Baseband gain of |
---|
316 | % 26. Sets AGC ready for a new capture. |
---|
317 | warplab_sendCmd(udp_node2, AGC_RESET, packetNum); |
---|
318 | |
---|
319 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
320 | % 6. Plot the transmitted and received data and close sockets |
---|
321 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
322 | figure; |
---|
323 | subplot(2,1,1); |
---|
324 | plot(real(Node1_Radio2_TxData)); |
---|
325 | title('Tx Node 1 Radio 1 I'); |
---|
326 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
327 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
328 | subplot(2,1,2); |
---|
329 | plot(imag(Node1_Radio2_TxData)); |
---|
330 | title('Tx Node 1 Radio 1 Q'); |
---|
331 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
332 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
333 | |
---|
334 | figure; |
---|
335 | subplot(4,2,1); |
---|
336 | plot(real(Node2_Radio1_RxData)); |
---|
337 | title('Rx Node 2 Radio 1 I'); |
---|
338 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
339 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
340 | subplot(4,2,2); |
---|
341 | plot(imag(Node2_Radio1_RxData)); |
---|
342 | title('Rx Node 2 Radio 1 Q'); |
---|
343 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
344 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
345 | subplot(4,2,3); |
---|
346 | plot(real(Node2_Radio2_RxData)); |
---|
347 | title('Rx Node 2 Radio 2 I'); |
---|
348 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
349 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
350 | subplot(4,2,4); |
---|
351 | plot(imag(Node2_Radio2_RxData)); |
---|
352 | title('Rx Node 2 Radio 2 Q'); |
---|
353 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
354 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
355 | subplot(4,2,5); |
---|
356 | plot(real(Node2_Radio3_RxData)); |
---|
357 | title('Rx Node 2 Radio 3 I'); |
---|
358 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
359 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
360 | subplot(4,2,6); |
---|
361 | plot(imag(Node2_Radio3_RxData)); |
---|
362 | title('Rx Node 2 Radio 3 Q'); |
---|
363 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
364 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
365 | subplot(4,2,7); |
---|
366 | plot(real(Node2_Radio4_RxData)); |
---|
367 | title('Rx Node 2 Radio 4 I'); |
---|
368 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
369 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
370 | subplot(4,2,8); |
---|
371 | plot(imag(Node2_Radio4_RxData)); |
---|
372 | title('Rx Node 2 Radio 4 Q'); |
---|
373 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
374 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
375 | |
---|
376 | % Close sockets |
---|
377 | pnet('closeall'); |
---|