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 | % The specific steps implemented in this script are the following: |
---|
6 | |
---|
7 | % 0. Transmit a narrowband signal using Warplab. For 2x2 channel estimation |
---|
8 | % first silence Tx radio 3 and transmit from Tx radio 2, then silence Tx |
---|
9 | % radio 2 and transmit from Tx radio 3. During both transimissions both |
---|
10 | % receive radios are capturing data. |
---|
11 | % 1. Remove from the received vectors the samples that do not correspond to |
---|
12 | % transmitted data. |
---|
13 | % 2. Compute the amplitude and the phase of the transmitted and received |
---|
14 | % samples |
---|
15 | % 3. Compute the channel amplitude and channel phase per sample for each of |
---|
16 | % the 4 SISO channels, and compute the channel matrix |
---|
17 | |
---|
18 | % Note: The amplitude and phase computed in this exercise correspond to the |
---|
19 | % amplitude and phase of the channel together with the amplitude and phase |
---|
20 | % of the hardware. In other words, the effect of the radios is also part of |
---|
21 | % the channel. |
---|
22 | |
---|
23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
24 | % 0. Transmit a narrowband signal using Warplab. For 2x2 channel estimation |
---|
25 | % first silence Tx radio 3 and transmit from Tx radio 2, then silence Tx |
---|
26 | % radio 2 and transmit from Tx radio 3. During both transimissions both |
---|
27 | % receive radios are capturing data. |
---|
28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
29 | |
---|
30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
31 | % 0.0. Initializaton and definition of parameters |
---|
32 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
33 | %Load some global definitions (packet types, etc.) |
---|
34 | warplab_defines |
---|
35 | |
---|
36 | % Create Socket handles and intialize nodes |
---|
37 | [socketHandles, packetNum] = warplab_initialize; |
---|
38 | |
---|
39 | % Separate the socket handles for easier access |
---|
40 | % The first socket handle is always the magic SYNC |
---|
41 | % The rest of the handles are the handles to the WARP nodes |
---|
42 | udp_Sync = socketHandles(1); |
---|
43 | udp_node1 = socketHandles(2); |
---|
44 | udp_node2 = socketHandles(3); |
---|
45 | |
---|
46 | % Define WARPLab parameters. |
---|
47 | TxDelay = 1000; % Number of noise samples per Rx capture. In [0:2^14] |
---|
48 | TxLength = 2^14-1-1000; % Length of transmission. In [0:2^14-1-TxDelay] |
---|
49 | TxMode = 0; % Transmission mode. In [0:1] |
---|
50 | % 0: Single Transmission |
---|
51 | % 1: Continuous Transmission. Tx board will continue |
---|
52 | % transmitting the vector of samples until the user manually |
---|
53 | % disables the transmitter. |
---|
54 | CarrierChannel = 12; % Channel in the 2.4 GHz band. In [1:14] |
---|
55 | Node1_Radio2_TxGain_BB = 3; % Tx Baseband Gain. In [0:3] |
---|
56 | Node1_Radio2_TxGain_RF = 40; % Tx RF Gain. In [0:63] |
---|
57 | Node1_Radio3_TxGain_BB = 3; % Tx Baseband Gain. In [0:3] |
---|
58 | Node1_Radio3_TxGain_RF = 40; % Tx RF Gain. In [0:63] |
---|
59 | Node2_Radio2_RxGain_BB = 13; % Rx Baseband Gain. In [0:31] |
---|
60 | Node2_Radio2_RxGain_RF = 1; % Rx RF Gain. In [1:3] |
---|
61 | Node2_Radio3_RxGain_BB = 13; % Rx Baseband Gain. In [0:31] |
---|
62 | Node2_Radio3_RxGain_RF = 1; % Rx RF Gain. In [1:3] |
---|
63 | % Note: For this experiment node 1 will be set as the transmitter and node |
---|
64 | % 2 will be set as the receiver (this is done later in the code), hence, |
---|
65 | % there is no need to define receive gains for node1 and there is no |
---|
66 | % need to define transmitter gains for node2. |
---|
67 | Node2_MGC_AGC_Select = 0; % Set MGC_AGC_Select=1 to enable Automatic Gain Control (AGC). |
---|
68 | % Set MGC_AGC_Select=0 to enable Manual Gain Control (MGC). |
---|
69 | % By default, the nodes are set to MGC. |
---|
70 | |
---|
71 | % Download the WARPLab parameters to the WARP nodes. |
---|
72 | % The nodes store the TxDelay, TxLength, and TxMode parameters in |
---|
73 | % registers defined in the WARPLab sysgen model. The nodes set radio |
---|
74 | % related parameters CarrierChannel, TxGains, and RxGains, using the |
---|
75 | % radio controller functions. |
---|
76 | % The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter; |
---|
77 | % the receiver doesn't require knowledge of these parameters (the receiver |
---|
78 | % will always capture 2^14 samples). For this exercise node 1 will be set as |
---|
79 | % the transmitter (this is done later in the code). Since TxDelay, TxLength and |
---|
80 | % TxMode are only required at the transmitter we download the TxDelay, TxLength and |
---|
81 | % TxMode parameters only to the transmitter node (node 1). |
---|
82 | warplab_writeRegister(udp_node1,TX_DELAY,TxDelay); |
---|
83 | warplab_writeRegister(udp_node1,TX_LENGTH,TxLength); |
---|
84 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
85 | % The CarrierChannel parameter must be downloaded to all nodes |
---|
86 | warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel); |
---|
87 | warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel); |
---|
88 | % Node 1 will be set as the transmitter so download Tx gains to node 1. |
---|
89 | warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16)); |
---|
90 | warplab_setRadioParameter(udp_node1,RADIO3_TXGAINS,(Node1_Radio3_TxGain_RF + Node1_Radio3_TxGain_BB*2^16)); |
---|
91 | % Node 2 will be set as the receiver so download Rx gains to node 2. |
---|
92 | warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16)); |
---|
93 | warplab_setRadioParameter(udp_node2,RADIO3_RXGAINS,(Node2_Radio3_RxGain_BB + Node2_Radio3_RxGain_RF*2^16)); |
---|
94 | % Set MGC mode in node 2 (receiver) |
---|
95 | warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select); |
---|
96 | |
---|
97 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
98 | % 0.1. Generate a vector of samples to transmit and send the samples to the |
---|
99 | % Warp board (Sample Frequency is 40MHz) |
---|
100 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
101 | % Prepare some data to be transmitted |
---|
102 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; %Create time vector. |
---|
103 | % Create a signal to transmit, the signal can be real or complex. |
---|
104 | % The signal must meet the following requirements: |
---|
105 | % - Signal to transmit must be a row vector. |
---|
106 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
107 | % of the imaginary part must be in [-1:1]. |
---|
108 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
109 | % is limited to 19 MHz) |
---|
110 | % - Lowest frequency component is limited to 30 kHz |
---|
111 | Node1_Radio2Radio3_TxData = exp(t*j*2*pi*1e6); |
---|
112 | |
---|
113 | % Download the samples to be transmitted to Tx radio 2 buffer |
---|
114 | warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2Radio3_TxData); |
---|
115 | |
---|
116 | % Download the samples to be transmitted to Tx radio 3 buffer |
---|
117 | warplab_writeSMWO(udp_node1, RADIO3_TXDATA, Node1_Radio2Radio3_TxData); |
---|
118 | |
---|
119 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
120 | % 0.2 Prepare boards for transmission from Tx radio 2 and reception on |
---|
121 | % both receiver antennas. Send trigger to start transmission and reception |
---|
122 | % (trigger is the SYNC packet) |
---|
123 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
124 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
125 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
126 | % packet. |
---|
127 | |
---|
128 | % Enable transmitter radio path in radio 2 in node 1 (enable radio 2 |
---|
129 | % in node 1 as transmitter) |
---|
130 | warplab_sendCmd(udp_node1, RADIO2_TXEN, packetNum); |
---|
131 | |
---|
132 | % Enable transmission of node1's radio 2 Tx buffer (enable |
---|
133 | % transmission of samples stored in radio 2 Tx Buffer in node 1) |
---|
134 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXEN, packetNum); |
---|
135 | |
---|
136 | % Enable receiver radio path in radios 2 and 3 in node 2 (enable radios 2 |
---|
137 | % and 3 in node 2 as receivers) |
---|
138 | warplab_sendCmd(udp_node2, [RADIO2_RXEN, RADIO3_RXEN], packetNum); |
---|
139 | |
---|
140 | % Enable capture in node2's radio 2 and radio 3 Rx Buffer (enable radio 2 |
---|
141 | % Rx buffer and radio 3 Rx buffer in node 2 for storage of samples) |
---|
142 | warplab_sendCmd(udp_node2, [RADIO2RXBUFF_RXEN, RADIO3RXBUFF_RXEN], packetNum); |
---|
143 | |
---|
144 | % Prime transmitter state machine in node 1. Node 1 will be |
---|
145 | % waiting for the SYNC packet. Transmission from node 1 will be triggered |
---|
146 | % when node 1 receives the SYNC packet. |
---|
147 | warplab_sendCmd(udp_node1, TX_START, packetNum); |
---|
148 | |
---|
149 | % Prime receiver state machine in node 2. Node 2 will be waiting |
---|
150 | % for the SYNC packet. Capture at node 2 will be triggered when node 2 |
---|
151 | % receives the SYNC packet. |
---|
152 | warplab_sendCmd(udp_node2, RX_START, packetNum); |
---|
153 | |
---|
154 | % Send the SYNC packet |
---|
155 | warplab_sendSync(udp_Sync); |
---|
156 | |
---|
157 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
158 | % 0.3 Read the received smaples from the WARP board |
---|
159 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
160 | % Read back the received samples from radio 2 |
---|
161 | [Node1_Radio2_to_Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay); |
---|
162 | % Read back the received samples from radio 3 |
---|
163 | [Node1_Radio2_to_Node2_Radio3_RawRxData] = warplab_readSMRO(udp_node2, RADIO3_RXDATA, TxLength+TxDelay); |
---|
164 | % Process the received samples to obtain meaningful data |
---|
165 | [Node1_Radio2_to_Node2_Radio2_RxData,Node1_Radio2_to_Node2_Radio2_RxOTR] = warplab_processRawRxData(Node1_Radio2_to_Node2_Radio2_RawRxData); |
---|
166 | [Node1_Radio2_to_Node2_Radio3_RxData,Node1_Radio2_to_Node2_Radio3_RxOTR] = warplab_processRawRxData(Node1_Radio2_to_Node2_Radio3_RawRxData); |
---|
167 | |
---|
168 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
169 | % 0.4 Reset and disable the boards |
---|
170 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
171 | % Set radio 2 Tx buffer in node 1 back to Tx disabled mode |
---|
172 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXDIS, packetNum); |
---|
173 | |
---|
174 | % Disable the transmitter radio 2 |
---|
175 | warplab_sendCmd(udp_node1, RADIO2_TXDIS, packetNum); |
---|
176 | |
---|
177 | % Let the receiver know that samples have been read and system is ready for |
---|
178 | % a new capture |
---|
179 | warplab_sendCmd(udp_node2, RX_DONEREADING, packetNum); |
---|
180 | |
---|
181 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
182 | % 0.5 Prepare WARP boards for transmission from Tx radio 3 and reception on |
---|
183 | % both receiver antennas. Send trigger to start transmission and reception |
---|
184 | % (trigger is the SYNC packet) |
---|
185 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
186 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
187 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
188 | % packet. |
---|
189 | |
---|
190 | % Enable transmitter radio path in radio 3 in node 1 (enable radio 3 |
---|
191 | % in node 1 as transmitter) |
---|
192 | warplab_sendCmd(udp_node1, RADIO3_TXEN, packetNum); |
---|
193 | |
---|
194 | % Enable transmission of node1's radio 3 Tx buffer (enable |
---|
195 | % transmission of samples stored in radio 3 Tx Buffer in node 1) |
---|
196 | warplab_sendCmd(udp_node1, RADIO3TXBUFF_TXEN, packetNum); |
---|
197 | |
---|
198 | % Notice receive radios in node 2 are still enabled so there is no need to |
---|
199 | % enable them again |
---|
200 | |
---|
201 | % Prime transmitter state machine in transmitter node. Transmitter will be |
---|
202 | % waiting for the SYNC packet. Transmission will be triggered when the |
---|
203 | % transmitter node receives the SYNC packet. |
---|
204 | warplab_sendCmd(udp_node1, TX_START, packetNum); |
---|
205 | |
---|
206 | % Prime receiver state machine in receiver node. Receiver will be waiting |
---|
207 | % for the SYNC packet. Capture will be triggered when the receiver |
---|
208 | % node receives the SYNC packet. |
---|
209 | warplab_sendCmd(udp_node2, RX_START, packetNum); |
---|
210 | |
---|
211 | % Send the SYNC packet |
---|
212 | warplab_sendSync(udp_Sync); |
---|
213 | |
---|
214 | |
---|
215 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
216 | % 0.6 Read the received smaples from the Warp board |
---|
217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
218 | % Read back the received samples from radio 2 |
---|
219 | [Node1_Radio3_to_Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay); |
---|
220 | % Read back the received samples from radio 3 |
---|
221 | [Node1_Radio3_to_Node2_Radio3_RawRxData] = warplab_readSMRO(udp_node2, RADIO3_RXDATA, TxLength+TxDelay); |
---|
222 | % Process the received samples to obtain meaningful data |
---|
223 | [Node1_Radio3_to_Node2_Radio2_RxData,Node1_Radio2_to_Node2_Radio2_RxOTR] = warplab_processRawRxData(Node1_Radio3_to_Node2_Radio2_RawRxData); |
---|
224 | [Node1_Radio3_to_Node2_Radio3_RxData,Node1_Radio2_to_Node2_Radio3_RxOTR] = warplab_processRawRxData(Node1_Radio3_to_Node2_Radio3_RawRxData); |
---|
225 | |
---|
226 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
227 | % 0.7 Reset and disable the boards |
---|
228 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
229 | % Set radio 3 Tx buffer in node 1 back to Tx disabled mode |
---|
230 | warplab_sendCmd(udp_node1, RADIO3TXBUFF_TXDIS, packetNum); |
---|
231 | |
---|
232 | % Disable the transmitter radio 3 |
---|
233 | warplab_sendCmd(udp_node1, RADIO3_TXDIS, packetNum); |
---|
234 | |
---|
235 | % Set radios 2 and 3 Rx buffer in node 2 back to Rx disabled mode |
---|
236 | warplab_sendCmd(udp_node2, [RADIO2RXBUFF_RXDIS, RADIO3RXBUFF_RXDIS], packetNum); |
---|
237 | |
---|
238 | % Disable the receiver radios |
---|
239 | warplab_sendCmd(udp_node2, [RADIO2_RXDIS,RADIO3_RXDIS], packetNum); |
---|
240 | |
---|
241 | % Close sockets |
---|
242 | pnet('closeall'); |
---|
243 | |
---|
244 | |
---|
245 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
246 | % 0.8 Plot the transmitted and received data |
---|
247 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
248 | figure; |
---|
249 | subplot(5,2,1); |
---|
250 | plot(real(Node1_Radio2Radio3_TxData)); |
---|
251 | title('Tx Node 1 Radio 2 I and Tx Node 1 Radio 3 I'); |
---|
252 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
253 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
254 | subplot(5,2,2); |
---|
255 | plot(imag(Node1_Radio2Radio3_TxData)); |
---|
256 | title('Tx Node 1 Radio 2 Q and Tx Node 1 Radio 3 Q '); |
---|
257 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
258 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
259 | subplot(5,2,3); |
---|
260 | plot(real(Node1_Radio2_to_Node2_Radio2_RxData)); |
---|
261 | title('Rx Node 2 Radio 2 I when Node 1 Radio 2 was transmitting'); |
---|
262 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
263 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
264 | subplot(5,2,4); |
---|
265 | plot(imag(Node1_Radio2_to_Node2_Radio2_RxData)); |
---|
266 | title('Rx Node 2 Radio 2 Q when Node 1 Radio 2 was transmitting'); |
---|
267 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
268 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
269 | subplot(5,2,5); |
---|
270 | plot(real(Node1_Radio2_to_Node2_Radio3_RxData)); |
---|
271 | title('Rx Node 2 Radio 3 I when Node 1 Radio 2 was transmitting'); |
---|
272 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
273 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
274 | subplot(5,2,6); |
---|
275 | plot(imag(Node1_Radio2_to_Node2_Radio3_RxData)); |
---|
276 | title('Rx Node 2 Radio 3 Q when Node 1 Radio 2 was transmitting'); |
---|
277 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
278 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
279 | subplot(5,2,7); |
---|
280 | plot(real(Node1_Radio3_to_Node2_Radio2_RxData)); |
---|
281 | title('Rx Node 2 Radio 2 I when Node 1 Radio 3 was transmitting'); |
---|
282 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
283 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
284 | subplot(5,2,8); |
---|
285 | plot(imag(Node1_Radio3_to_Node2_Radio2_RxData)); |
---|
286 | title('Rx Node 2 Radio 2 Q when Node 1 Radio 3 was transmitting'); |
---|
287 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
288 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
289 | subplot(5,2,9); |
---|
290 | plot(real(Node1_Radio3_to_Node2_Radio3_RxData)); |
---|
291 | title('Rx Node2 Radio 3 I when Node 1 Radio 3 was transmitting'); |
---|
292 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
293 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
294 | subplot(5,2,10); |
---|
295 | plot(imag(Node1_Radio3_to_Node2_Radio3_RxData)); |
---|
296 | title('Rx Node 2 Radio 3 Q when Node 1 Radio 3 was transmitting'); |
---|
297 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
298 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
299 | |
---|
300 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
301 | % 1. Remove from the received vector the samples that do not correspond to |
---|
302 | % transmitted data. In other words, remove from the received vector samples |
---|
303 | % 1 to TxDelay. This step will remove samples that correspond to measured |
---|
304 | % noise and make the RxData vector the same length as the TxData vector |
---|
305 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
306 | Tx2_Rx2_RxData = Node1_Radio2_to_Node2_Radio2_RxData(TxDelay+1:end); |
---|
307 | Tx2_Rx3_RxData = Node1_Radio2_to_Node2_Radio3_RxData(TxDelay+1:end); |
---|
308 | Tx3_Rx2_RxData = Node1_Radio3_to_Node2_Radio2_RxData(TxDelay+1:end); |
---|
309 | Tx3_Rx3_RxData = Node1_Radio3_to_Node2_Radio3_RxData(TxDelay+1:end); |
---|
310 | |
---|
311 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
312 | % 2. Compute the amplitude and the phase of the transmitted and received |
---|
313 | % sammples |
---|
314 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
315 | % Compute the magnitude per sample of the transmitted and received |
---|
316 | % data |
---|
317 | mag_TxData = abs(Node1_Radio2Radio3_TxData); % Tx data |
---|
318 | mag_Tx2_Rx2_RxData = abs(Tx2_Rx2_RxData); |
---|
319 | mag_Tx2_Rx3_RxData = abs(Tx2_Rx3_RxData); |
---|
320 | mag_Tx3_Rx2_RxData = abs(Tx3_Rx2_RxData); |
---|
321 | mag_Tx3_Rx3_RxData = abs(Tx3_Rx3_RxData); |
---|
322 | |
---|
323 | % Compute the phase per sample of the transmitted data |
---|
324 | phase_TxData = angle(Node1_Radio2Radio3_TxData); |
---|
325 | phase_TxData_unw = unwrap(phase_TxData); |
---|
326 | phase_TxData = phase_TxData *180/pi; %Convert to degrees |
---|
327 | phase_TxData_unw = phase_TxData_unw *180/pi; %Convert to degrees |
---|
328 | |
---|
329 | phase_Tx2_Rx2_RxData = angle(Tx2_Rx2_RxData); |
---|
330 | phase_Tx2_Rx2_RxData_unw = unwrap(phase_Tx2_Rx2_RxData); |
---|
331 | phase_Tx2_Rx2_RxData = phase_Tx2_Rx2_RxData *180/pi; %Convert to degrees |
---|
332 | phase_Tx2_Rx2_RxData_unw = phase_Tx2_Rx2_RxData_unw *180/pi; %Convert to degrees |
---|
333 | |
---|
334 | phase_Tx2_Rx3_RxData = angle(Tx2_Rx3_RxData); |
---|
335 | phase_Tx2_Rx3_RxData_unw = unwrap(phase_Tx2_Rx3_RxData); |
---|
336 | phase_Tx2_Rx3_RxData = phase_Tx2_Rx3_RxData *180/pi; %Convert to degrees |
---|
337 | phase_Tx2_Rx3_RxData_unw = phase_Tx2_Rx3_RxData_unw *180/pi; %Convert to degrees |
---|
338 | |
---|
339 | phase_Tx3_Rx2_RxData = angle(Tx3_Rx2_RxData); |
---|
340 | phase_Tx3_Rx2_RxData_unw = unwrap(phase_Tx3_Rx2_RxData); |
---|
341 | phase_Tx3_Rx2_RxData = phase_Tx3_Rx2_RxData *180/pi; %Convert to degrees |
---|
342 | phase_Tx3_Rx2_RxData_unw = phase_Tx3_Rx2_RxData_unw *180/pi; %Convert to degrees |
---|
343 | |
---|
344 | phase_Tx3_Rx3_RxData = angle(Tx3_Rx3_RxData); |
---|
345 | phase_Tx3_Rx3_RxData_unw = unwrap(phase_Tx3_Rx3_RxData); |
---|
346 | phase_Tx3_Rx3_RxData = phase_Tx3_Rx3_RxData *180/pi; %Convert to degrees |
---|
347 | phase_Tx3_Rx3_RxData_unw = phase_Tx3_Rx3_RxData_unw *180/pi; %Convert to degrees |
---|
348 | |
---|
349 | % Plot magnitude and phase of transmitted and received samples |
---|
350 | figure; |
---|
351 | subplot(5,2,1); |
---|
352 | plot(mag_TxData); |
---|
353 | title('Tx Node 1 Radio 2 magnitude and Tx Node 1 Radio 3 magnitude '); |
---|
354 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
355 | subplot(5,2,2); |
---|
356 | plot(phase_TxData_unw); |
---|
357 | title('Tx Node 1 Radio 2 phase and Tx Node 1 Radio 3 phase '); |
---|
358 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
359 | subplot(5,2,3); |
---|
360 | plot(mag_Tx2_Rx2_RxData); |
---|
361 | title('Rx Node 2 Radio 2 magnitude when Node 1 Radio 2 was transmitting'); |
---|
362 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
363 | subplot(5,2,4); |
---|
364 | plot(phase_Tx2_Rx2_RxData_unw); |
---|
365 | title('Rx Node 2 Radio 2 phase when Node 1 Radio 2 was transmitting'); |
---|
366 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
367 | subplot(5,2,5); |
---|
368 | plot(mag_Tx2_Rx3_RxData); |
---|
369 | title('Rx Node 2 Radio 3 magnitude when Node 1 Radio 2 was transmitting'); |
---|
370 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
371 | subplot(5,2,6); |
---|
372 | plot(phase_Tx2_Rx3_RxData_unw); |
---|
373 | title('Rx Node 2 Radio 3 phase when Node 1 Radio 2 was transmitting'); |
---|
374 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
375 | subplot(5,2,7); |
---|
376 | plot(mag_Tx3_Rx2_RxData); |
---|
377 | title('Rx Node 2 Radio 2 magnitude when Node 1 Radio 3 was transmitting'); |
---|
378 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
379 | subplot(5,2,8); |
---|
380 | plot(phase_Tx3_Rx2_RxData_unw); |
---|
381 | title('Rx Node 2 Radio 2 phase when Node 1 Radio 3 was transmitting'); |
---|
382 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
383 | subplot(5,2,9); |
---|
384 | plot(mag_Tx3_Rx3_RxData); |
---|
385 | title('Rx Node 2 Radio 3 magnitude when Node 1 Radio 3 was transmitting'); |
---|
386 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
387 | subplot(5,2,10); |
---|
388 | plot(phase_Tx3_Rx3_RxData_unw); |
---|
389 | title('Rx Node 2 Radio 3 phase when Node 1 Radio 3 was transmitting'); |
---|
390 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
391 | |
---|
392 | % Plot magnitude and phase of transmitted and received samples |
---|
393 | |
---|
394 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
395 | % 3. Compute the channel amplitude and channel phase per sample |
---|
396 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
397 | % Compute the channel amplitudes |
---|
398 | channel_amplitude_Tx2_Rx2 = mag_Tx2_Rx2_RxData./mag_TxData; |
---|
399 | channel_amplitude_Tx2_Rx3 = mag_Tx2_Rx3_RxData./mag_TxData; |
---|
400 | channel_amplitude_Tx3_Rx2 = mag_Tx3_Rx2_RxData./mag_TxData; |
---|
401 | channel_amplitude_Tx3_Rx3 = mag_Tx3_Rx3_RxData./mag_TxData; |
---|
402 | |
---|
403 | % Compute the channel phases |
---|
404 | channel_phase_Tx2_Rx2 = phase_Tx2_Rx2_RxData_unw - phase_TxData_unw; |
---|
405 | channel_phase_Tx2_Rx3 = phase_Tx2_Rx3_RxData_unw - phase_TxData_unw; |
---|
406 | channel_phase_Tx3_Rx2 = phase_Tx3_Rx2_RxData_unw - phase_TxData_unw; |
---|
407 | channel_phase_Tx3_Rx3 = phase_Tx3_Rx3_RxData_unw - phase_TxData_unw; |
---|
408 | |
---|
409 | % Plot channel amplitude |
---|
410 | figure |
---|
411 | subplot(2,2,1) |
---|
412 | plot(channel_amplitude_Tx2_Rx2) |
---|
413 | title('Node1Radio2-Node2Radio2 path - Channel Amplitude per sample') |
---|
414 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
415 | subplot(2,2,2) |
---|
416 | plot(channel_amplitude_Tx2_Rx3) |
---|
417 | title('Node1Radio2-Node2Radio3 path - Channel Amplitude per sample') |
---|
418 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
419 | subplot(2,2,3) |
---|
420 | plot(channel_amplitude_Tx3_Rx2) |
---|
421 | title('Node1Radio3-Node2Radio2 path - Channel Amplitude per sample') |
---|
422 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
423 | subplot(2,2,4) |
---|
424 | plot(channel_amplitude_Tx3_Rx3) |
---|
425 | title('Node1Radio3-Node2Radio3 path - Channel Amplitude per sample') |
---|
426 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
427 | |
---|
428 | %Plot channel phase |
---|
429 | figure |
---|
430 | subplot(2,2,1) |
---|
431 | plot(channel_phase_Tx2_Rx2) |
---|
432 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
433 | title('Node1Radio2-Node2Radio2 path - Channel Phase per sample') |
---|
434 | subplot(2,2,2) |
---|
435 | plot(channel_phase_Tx2_Rx3) |
---|
436 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
437 | title('Node1Radio2-Node2Radio3 path - Channel Phase per sample') |
---|
438 | subplot(2,2,3) |
---|
439 | plot(channel_phase_Tx3_Rx2) |
---|
440 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
441 | title('Node1Radio3-Node2Radio2 path - Channel Phase per sample') |
---|
442 | subplot(2,2,4) |
---|
443 | plot(channel_phase_Tx3_Rx3) |
---|
444 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
445 | title('Node1Radio3-Node2Radio3 path - Channel Phase per sample') |
---|
446 | |
---|