1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | % Using WARPLab (SISO configuration) to Estimate the Amplitude and Phase of |
---|
3 | % a Narrowband Flat Fading Wireless Channel |
---|
4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
5 | % The specific steps implemented in this script are the following: |
---|
6 | |
---|
7 | % 0. Transmit a narrowband signal using WARPLab |
---|
8 | % 1. Remove from the received vector the samples that do not correspond to |
---|
9 | % transmitted data. |
---|
10 | % 2. Compute the amplitude and the phase of the transmitted and received |
---|
11 | % samples |
---|
12 | % 3. Compute the channel amplitude and channel phase per sample and close |
---|
13 | % sockets |
---|
14 | |
---|
15 | % Note: The amplitude and phase computed in this exercise correspond to the |
---|
16 | % amplitude and phase of the channel together with the amplitude and phase |
---|
17 | % of the hardware. In other words, the effect of the radios (like gains and |
---|
18 | % carrier frequency offset)is also part of the channel. |
---|
19 | |
---|
20 | |
---|
21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
22 | % 0. Transmit a narrowband signal using WARPLab |
---|
23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
24 | % Follow the steps for transmission and reception of data using WARPLab. |
---|
25 | % These are the steps implemented in the previous lab exercise, the |
---|
26 | % following sections (0.0 to 0.5) guide you through the steps. |
---|
27 | |
---|
28 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
29 | % 0.0. Initializaton and definition of parameters |
---|
30 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
31 | %Load some global definitions (packet types, etc.) |
---|
32 | warplab_defines |
---|
33 | |
---|
34 | % Create Socket handles and intialize nodes |
---|
35 | [socketHandles, packetNum] = warplab_initialize; |
---|
36 | |
---|
37 | % Separate the socket handles for easier access |
---|
38 | % The first socket handle is always the magic SYNC |
---|
39 | % The rest of the handles are the handles to the WARP nodes |
---|
40 | udp_Sync = socketHandles(1); |
---|
41 | udp_node1 = socketHandles(2); |
---|
42 | udp_node2 = socketHandles(3); |
---|
43 | |
---|
44 | % Define WARPLab parameters. |
---|
45 | % Note: For this experiment node 1 will be set as the transmitter and node |
---|
46 | % 2 will be set as the receiver (this is done later in the code), hence, |
---|
47 | % there is no need to define receive gains for node 1 and there is no |
---|
48 | % need to define transmitter gains for node 2. |
---|
49 | TxDelay = 2000; % Number of noise samples per Rx capture. In [0:2^14] |
---|
50 | TxLength = 2^14-1-2000; % Length of transmission. In [0:2^14-TxDelay] |
---|
51 | CarrierChannel = 12; % Channel in the 2.4 GHz band. In [1:14] |
---|
52 | Node1_Radio2_TxGain_BB = 1; % Tx Baseband Gain. In [0:3] |
---|
53 | Node1_Radio2_TxGain_RF = 25; % Tx RF Gain. In [0:63] |
---|
54 | Node2_Radio2_RxGain_BB = 15; % Rx Baseband Gain. In [0:31] |
---|
55 | Node2_Radio2_RxGain_RF = 1; % Rx RF Gain. In [1:3] |
---|
56 | TxMode = 0; %Transmission mode. In [0:1] |
---|
57 | % 0: Single Transmission |
---|
58 | % 1: Continuous Transmission. Tx board will continue |
---|
59 | % transmitting the vector of samples until the user manually |
---|
60 | % disables the transmitter. |
---|
61 | Node2_MGC_AGC_Select = 0; % Set MGC_AGC_Select=1 to enable Automatic Gain Control (AGC). |
---|
62 | % Set MGC_AGC_Select=0 to enable Manual Gain Control (MGC). |
---|
63 | % By default, the nodes are set to MGC. |
---|
64 | |
---|
65 | % Download the WARPLab parameters to the WARP nodes. |
---|
66 | % The nodes store the TxDelay, TxLength, and TxMode parameters in |
---|
67 | % registers defined in the WARPLab sysgen model. The nodes set radio |
---|
68 | % related parameters CarrierChannel, TxGains, and RxGains, using the |
---|
69 | % radio controller functions. |
---|
70 | % The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter; |
---|
71 | % the receiver doesn't require knowledge of these parameters (the receiver |
---|
72 | % will always capture 2^14 samples). For this exercise node 1 will be set as |
---|
73 | % the transmitter (this is done later in the code). Since TxDelay, TxLength and |
---|
74 | % TxMode are only required at the transmitter we download the TxDelay, TxLength and |
---|
75 | % TxMode parameters only to the transmitter node (node 1). |
---|
76 | warplab_writeRegister(udp_node1,TX_DELAY,TxDelay); |
---|
77 | warplab_writeRegister(udp_node1,TX_LENGTH,TxLength); |
---|
78 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
79 | % The CarrierChannel parameter must be downloaded to all nodes |
---|
80 | warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel); |
---|
81 | warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel); |
---|
82 | % Node 1 will be set as the transmitter so download Tx gains to node 1. |
---|
83 | warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16)); |
---|
84 | % Node 2 will be set as the receiver so download Rx gains to node 2. |
---|
85 | warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16)); |
---|
86 | % Set MGC mode in node 2 (receiver) |
---|
87 | warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select); |
---|
88 | |
---|
89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
90 | % 0.1. Generate a vector of samples to transmit and send the samples to the |
---|
91 | % WARP board (Sample Frequency is 40MHz) |
---|
92 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
93 | % Prepare some data to be transmitted |
---|
94 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector. |
---|
95 | |
---|
96 | % The signal must meet the following requirements: |
---|
97 | % - Signal to transmit must be a row vector. |
---|
98 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
99 | % of the imaginary part must be in [-1:1]. |
---|
100 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
101 | % is limited to 19 MHz) |
---|
102 | % - Lowest frequency component is limited to 30 kHz |
---|
103 | Node1_Radio2_TxData = exp(t*j*2*pi*1e6); |
---|
104 | |
---|
105 | % Download the samples to be transmitted |
---|
106 | % Hints: |
---|
107 | % 1. The first argument of the 'warplab_writeSMWO' function identifies the |
---|
108 | % node to which samples will be downloaded to. In this exercise we will set |
---|
109 | % node 1 as the transmitter node, the id or handle to node 1 is 'udp_node1'. |
---|
110 | % 2. The second argument of the 'warplab_writeSMWO' function identifies the |
---|
111 | % transmit buffer where the samples will be written. A node programmed with |
---|
112 | % the warplab_mimo_2x2_v04.bit bitstream has 2 transmit buffers and a node |
---|
113 | % programmed with the warplab_mimo_4x4_v04.bit bitstream has 4 transmit |
---|
114 | % buffers. For this exercise we will transmit from radio 2, hence, samples |
---|
115 | % must be downloaded to radio 2 Tx buffer, the id for this buffer is |
---|
116 | % 'RADIO2_TXDATA'. |
---|
117 | % 3. The third argument of the 'warplab_writeSMWO' function is the |
---|
118 | % vector of samples to download, it must be a row vector. For this |
---|
119 | % exercise the 'Node1_Radio2_TxData' vector is the vector of samples to be |
---|
120 | % transmitted, hence, this is the vector that must be downloaded to radio 2 |
---|
121 | % Tx buffer. |
---|
122 | |
---|
123 | warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData); |
---|
124 | |
---|
125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
126 | % 0.2. Prepare WARP boards for transmission and reception and send trigger to |
---|
127 | % start transmission and reception (trigger is the SYNC packet) |
---|
128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
129 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
130 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
131 | % packet. |
---|
132 | |
---|
133 | % Enable transmitter radio path in radio 2 in node 1 (enable radio 2 in |
---|
134 | % node 1 as transmitter) |
---|
135 | warplab_sendCmd(udp_node1, RADIO2_TXEN, packetNum); |
---|
136 | |
---|
137 | % Enable transmission of node1's radio 2 Tx buffer (enable transmission |
---|
138 | % of samples stored in radio 2 Tx Buffer in node 1) |
---|
139 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXEN, packetNum); |
---|
140 | |
---|
141 | % Enable receiver radio path in radio 2 in node 2 (enable radio 2 in |
---|
142 | % node 2 as receiver) |
---|
143 | warplab_sendCmd(udp_node2, RADIO2_RXEN, packetNum); |
---|
144 | |
---|
145 | % Enable capture in node2's radio 2 Rx Buffer (enable radio 2 rx buffer in |
---|
146 | % node 2 for storage of samples) |
---|
147 | warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXEN, packetNum); |
---|
148 | |
---|
149 | % Prime transmitter state machine in node 1. Node 1 will be |
---|
150 | % waiting for the SYNC packet. Transmission from node 1 will be triggered |
---|
151 | % when node 1 receives the SYNC packet. |
---|
152 | warplab_sendCmd(udp_node1, TX_START, packetNum); |
---|
153 | |
---|
154 | % Prime receiver state machine in node 2. Node 2 will be waiting |
---|
155 | % for the SYNC packet. Capture at node 2 will be triggered when node 2 |
---|
156 | % receives the SYNC packet. |
---|
157 | warplab_sendCmd(udp_node2, RX_START, packetNum); |
---|
158 | |
---|
159 | % Send the SYNC packet |
---|
160 | warplab_sendSync(udp_Sync); |
---|
161 | |
---|
162 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
163 | % 0.3. Read the received smaples from the WARP board |
---|
164 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
165 | % Hints: |
---|
166 | % 1. The first argument of the 'warplab_readSMRO' function identifies the |
---|
167 | % node from which samples will be read. In this exercise we set node 2 as |
---|
168 | % the receiver node, the id or handle to node 2 is 'udp_node2'. |
---|
169 | % 2. The second argument of the 'warplab_readSMRO' function identifies the |
---|
170 | % receive buffer from which samples will be read. A node programmed with |
---|
171 | % the warplab_mimo_2x2_v04.bit bitstream has 2 receive buffers and a node |
---|
172 | % programmed with the warplab_mimo_4x4_v04.bit bitstream has 4 receive |
---|
173 | % buffers. For this exercise samples were captured in node 2 radio 2, |
---|
174 | % hence, samples must be read from radio 2 Rx buffer, the id for this |
---|
175 | % buffer is 'RADIO2_RXDATA'. |
---|
176 | % 3. The third argument of the 'warplab_readSMRO' function is the number of |
---|
177 | % samples to read; reading of samples always starts from address zero. |
---|
178 | % For this exercise the third argument of the 'warplab_readSMRO' |
---|
179 | % function must be equal to 'TxLength+TxDelay', since TxLength is the |
---|
180 | % number of samples that were transmitted and the first TxDelay samples |
---|
181 | % that were captured correspond to noise samples captured before the data |
---|
182 | % was transmitted. |
---|
183 | % Read back the received samples |
---|
184 | [Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay); |
---|
185 | |
---|
186 | % Process the received samples to obtain meaningful data |
---|
187 | [Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData); |
---|
188 | |
---|
189 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
190 | % 0.4. Reset and disable the boards |
---|
191 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
192 | % Set radio 2 Tx buffer in node 1 back to Tx disabled mode |
---|
193 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXDIS, packetNum); |
---|
194 | |
---|
195 | % Disable the transmitter radio |
---|
196 | warplab_sendCmd(udp_node1, RADIO2_TXDIS, packetNum); |
---|
197 | |
---|
198 | % Set radio 2 Rx buffer in node 2 back to Rx disabled mode |
---|
199 | warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXDIS, packetNum); |
---|
200 | |
---|
201 | % Disable the receiver radio |
---|
202 | warplab_sendCmd(udp_node2, RADIO2_RXDIS, packetNum); |
---|
203 | |
---|
204 | |
---|
205 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
206 | % 0.5. Plot the transmitted and received data |
---|
207 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
208 | figure; |
---|
209 | subplot(2,2,1); |
---|
210 | plot(real(Node1_Radio2_TxData)); |
---|
211 | title('Tx Node 1 Radio 2 I'); |
---|
212 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
213 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
214 | subplot(2,2,2); |
---|
215 | plot(imag(Node1_Radio2_TxData)); |
---|
216 | title('Tx Node 1 Radio 2 Q'); |
---|
217 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
218 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
219 | subplot(2,2,3); |
---|
220 | plot(real(Node2_Radio2_RxData)); |
---|
221 | title('Rx Node 2 Radio 2 I'); |
---|
222 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
223 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
224 | subplot(2,2,4); |
---|
225 | plot(imag(Node2_Radio2_RxData)); |
---|
226 | title('Rx Node 2 Radio 2 Q'); |
---|
227 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
228 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
229 | |
---|
230 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
231 | % 1. Remove from the received vector the samples that do not correspond to |
---|
232 | % transmitted data. In other words, remove from the received vector samples |
---|
233 | % 1 to TxDelay. This step will remove samples that correspond to measured |
---|
234 | % noise and make the RxData vector the same length as the TxData vector |
---|
235 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
236 | Node2_Radio2_RxData = Node2_Radio2_RxData(TxDelay+1:end); |
---|
237 | |
---|
238 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
239 | % 2. Compute the amplitude and the phase of the transmitted and received |
---|
240 | % sammples |
---|
241 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
242 | % Compute the magnitude per sample of the transmitted and received |
---|
243 | % data |
---|
244 | mag_TxData = abs(Node1_Radio2_TxData); |
---|
245 | mag_RxData = abs(Node2_Radio2_RxData); |
---|
246 | |
---|
247 | % Compute the phase per sample of the transmitted and received data |
---|
248 | phase_TxData = angle(Node1_Radio2_TxData); |
---|
249 | phase_RxData = angle(Node2_Radio2_RxData); |
---|
250 | |
---|
251 | phase_TxData_unw = unwrap(phase_TxData); |
---|
252 | phase_TxData = phase_TxData *180/pi; %Convert to degrees |
---|
253 | phase_TxData_unw = phase_TxData_unw *180/pi; %Convert to degrees |
---|
254 | |
---|
255 | phase_RxData_unw = unwrap(phase_RxData); |
---|
256 | phase_RxData = phase_RxData *180/pi; %Convert to degrees |
---|
257 | phase_RxData_unw = phase_RxData_unw *180/pi; %Convert to degrees |
---|
258 | |
---|
259 | % Plot magnitude and phase of transmitted and received samples |
---|
260 | figure; |
---|
261 | subplot(2,3,1); |
---|
262 | plot(mag_TxData); |
---|
263 | title('Tx Node 1 Radio 2 magnitude'); |
---|
264 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
265 | subplot(2,3,2); |
---|
266 | plot(phase_TxData); |
---|
267 | title('Tx Node 1 Radio 2 Phase'); |
---|
268 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
269 | subplot(2,3,3); |
---|
270 | plot(phase_TxData_unw); |
---|
271 | title('Tx Node 1 Radio 2 Phase unwrapped'); |
---|
272 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
273 | subplot(2,3,4); |
---|
274 | plot(mag_RxData); |
---|
275 | title('Rx Node 2 Radio 2 Magnitude'); |
---|
276 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
277 | subplot(2,3,5); |
---|
278 | plot(phase_RxData); |
---|
279 | title('Rx Node 2 Radio 2 Phase'); |
---|
280 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
281 | subplot(2,3,6); |
---|
282 | plot(phase_RxData_unw); |
---|
283 | title('Rx Node 2 Radio 2 Phase unwrapped'); |
---|
284 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
285 | |
---|
286 | |
---|
287 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
288 | % 3. Compute the channel amplitude and channel phase per sample and close |
---|
289 | % sockets |
---|
290 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
291 | % Compute the channel amplitude |
---|
292 | channel_amplitude = mag_RxData./mag_TxData; |
---|
293 | |
---|
294 | % Compute the channel phase |
---|
295 | channel_phase = phase_RxData_unw - phase_TxData_unw; |
---|
296 | |
---|
297 | % Plot channel amplitude and phase |
---|
298 | figure |
---|
299 | subplot(2,1,1) |
---|
300 | plot(channel_amplitude) |
---|
301 | title('Channel Amplitude per sample'); |
---|
302 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
303 | subplot(2,1,2) |
---|
304 | plot(channel_phase) |
---|
305 | title('Channel Phase per sample'); |
---|
306 | xlabel('n (samples)'); ylabel('Degrees'); |
---|
307 | |
---|
308 | % Close sockets |
---|
309 | pnet('closeall'); |
---|
310 | |
---|