1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | % Transmitting and Receiving Data using WARPLab (4x1 MISO configuration) |
---|
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4 | % To run this M-code the boards must be programmed with the |
---|
5 | % 4x4 MIMO 5.x version of WARPLab bitstream |
---|
6 | |
---|
7 | % The specific steps implemented in this script are the following |
---|
8 | |
---|
9 | % 0. Initializaton and definition of parameters |
---|
10 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
11 | % WARP board (Sample Frequency is 40MHz) |
---|
12 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
13 | % start transmission and reception (trigger is the SYNC packet) |
---|
14 | % 3. Read the received samples from the Warp board |
---|
15 | % 4. Reset and disable the boards |
---|
16 | % 5. Plot the transmitted and received data |
---|
17 | |
---|
18 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
19 | % 0. Initializaton and definition of parameters |
---|
20 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
21 | %Load some global definitions (packet types, etc.) |
---|
22 | warplab_defines |
---|
23 | |
---|
24 | % Create Socket handles and intialize nodes |
---|
25 | [socketHandles, packetNum] = warplab_initialize; |
---|
26 | |
---|
27 | % Separate the socket handles for easier access |
---|
28 | % The first socket handle is always the magic SYNC |
---|
29 | % The rest of the handles are the handles to the WARP nodes |
---|
30 | udp_Sync = socketHandles(1); |
---|
31 | udp_node1 = socketHandles(2); |
---|
32 | udp_node2 = socketHandles(3); |
---|
33 | |
---|
34 | % Define WARPLab parameters. |
---|
35 | TxDelay = 1000; % Number of noise samples per Rx capture. In [0:2^14] |
---|
36 | TxLength = 2^14-1-1000; % Length of transmission. In [0:2^14-1-TxDelay] |
---|
37 | TxMode = 0; % Transmission mode. In [0:1] |
---|
38 | % 0: Single Transmission |
---|
39 | % 1: Continuous Transmission. Tx board will continue |
---|
40 | % transmitting the vector of samples until the user manually |
---|
41 | % disables the transmitter. |
---|
42 | CarrierChannel = 12; % Channel in the 2.4 GHz band. In [1:14] |
---|
43 | Node1_Radio1_TxGain_BB = 3; % Tx Baseband Gain. In [0:3] |
---|
44 | Node1_Radio1_TxGain_RF = 40; % Tx RF Gain. In [0:63] |
---|
45 | Node1_Radio2_TxGain_BB = 3; % Tx Baseband Gain. In [0:3] |
---|
46 | Node1_Radio2_TxGain_RF = 40; % Tx RF Gain. In [0:63] |
---|
47 | Node1_Radio3_TxGain_BB = 3; % Tx Baseband Gain. In [0:3] |
---|
48 | Node1_Radio3_TxGain_RF = 40; % Tx RF Gain. In [0:63] |
---|
49 | Node1_Radio4_TxGain_BB = 3; % Tx Baseband Gain. In [0:3] |
---|
50 | Node1_Radio4_TxGain_RF = 40; % Tx RF Gain. In [0:63] |
---|
51 | Node2_Radio1_RxGain_BB = 10; % Rx Baseband Gain. In [0:31] |
---|
52 | Node2_Radio1_RxGain_RF = 1; % Rx RF Gain. In [1:3] |
---|
53 | % Note: For this experiment node 1 will be set as the transmitter and node |
---|
54 | % 2 will be set as the receiver (this is done later in the code), hence, |
---|
55 | % there is no need to define receive gains for node1 and there is no |
---|
56 | % need to define transmitter gains for node2. |
---|
57 | Node2_MGC_AGC_Select = 0; % Set MGC_AGC_Select=1 to enable Automatic Gain Control (AGC). |
---|
58 | % Set MGC_AGC_Select=0 to enable Manual Gain Control (MGC). |
---|
59 | % By default, the nodes are set to MGC. |
---|
60 | |
---|
61 | % Download the WARPLab parameters to the WARP nodes. |
---|
62 | % The nodes store the TxDelay, TxLength, and TxMode parameters in |
---|
63 | % registers defined in the WARPLab sysgen model. The nodes set radio |
---|
64 | % related parameters CarrierChannel, TxGains, and RxGains, using the |
---|
65 | % radio controller functions. |
---|
66 | % The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter; |
---|
67 | % the receiver doesn't require knowledge of these parameters (the receiver |
---|
68 | % will always capture 2^14 samples). For this exercise node 1 will be set as |
---|
69 | % the transmitter (this is done later in the code). Since TxDelay, TxLength and |
---|
70 | % TxMode are only required at the transmitter we download the TxDelay, TxLength and |
---|
71 | % TxMode parameters only to the transmitter node (node 1). |
---|
72 | warplab_writeRegister(udp_node1,TX_DELAY,TxDelay); |
---|
73 | warplab_writeRegister(udp_node1,TX_LENGTH,TxLength); |
---|
74 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
75 | % The CarrierChannel parameter must be downloaded to all nodes |
---|
76 | warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel); |
---|
77 | warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel); |
---|
78 | % Node 1 will be set as the transmitter so download Tx gains to node 1. |
---|
79 | warplab_setRadioParameter(udp_node1,RADIO1_TXGAINS,(Node1_Radio1_TxGain_RF + Node1_Radio1_TxGain_BB*2^16)); |
---|
80 | warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16)); |
---|
81 | warplab_setRadioParameter(udp_node1,RADIO3_TXGAINS,(Node1_Radio3_TxGain_RF + Node1_Radio3_TxGain_BB*2^16)); |
---|
82 | warplab_setRadioParameter(udp_node1,RADIO4_TXGAINS,(Node1_Radio4_TxGain_RF + Node1_Radio4_TxGain_BB*2^16)); |
---|
83 | % Node 2 will be set as the receiver so download Rx gains to node 2. |
---|
84 | warplab_setRadioParameter(udp_node2,RADIO1_RXGAINS,(Node2_Radio1_RxGain_BB + Node2_Radio1_RxGain_RF*2^16)); |
---|
85 | % Set MGC mode in node 2 (receiver) |
---|
86 | warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select); |
---|
87 | |
---|
88 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
89 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
90 | % WARP board (Sample Frequency is 40MHz) |
---|
91 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
92 | % Prepare some data to be transmitted |
---|
93 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector |
---|
94 | |
---|
95 | % Create a signal to transmit from radio 1, the signal can be real or complex. |
---|
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_Radio1_TxData = exp(t*j*2*pi*1e6); |
---|
104 | |
---|
105 | % Create a signal to transmit from radio 2, the signal can be real or complex. |
---|
106 | % The signal must meet the following requirements: |
---|
107 | % - Signal to transmit must be a row vector. |
---|
108 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
109 | % of the imaginary part must be in [-1:1]. |
---|
110 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
111 | % is limited to 19 MHz) |
---|
112 | % - Lowest frequency component is limited to 30 kHz |
---|
113 | Node1_Radio2_TxData = exp(t*j*2*pi*3e6); |
---|
114 | |
---|
115 | % Create a signal to transmit from radio 3, the signal can be real or complex. |
---|
116 | % The signal must meet the following requirements: |
---|
117 | % - Signal to transmit must be a row vector. |
---|
118 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
119 | % of the imaginary part must be in [-1:1]. |
---|
120 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
121 | % is limited to 19 MHz) |
---|
122 | % - Lowest frequency component is limited to 30 kHz |
---|
123 | Node1_Radio3_TxData = exp(t*j*2*pi*5e6); |
---|
124 | |
---|
125 | % Create a signal to transmit from radio 4, the signal can be real or complex. |
---|
126 | % The signal must meet the following requirements: |
---|
127 | % - Signal to transmit must be a row vector. |
---|
128 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
129 | % of the imaginary part must be in [-1:1]. |
---|
130 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
131 | % is limited to 19 MHz) |
---|
132 | % - Lowest frequency component is limited to 30 kHz |
---|
133 | Node1_Radio4_TxData = exp(t*j*2*pi*7e6); |
---|
134 | |
---|
135 | % Download the samples to be transmitted |
---|
136 | warplab_writeSMWO(udp_node1, RADIO1_TXDATA, Node1_Radio1_TxData); % Download samples to |
---|
137 | % radio 1 Tx Buffer |
---|
138 | warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData); % Download samples to |
---|
139 | % radio 2 Tx Buffer |
---|
140 | warplab_writeSMWO(udp_node1, RADIO3_TXDATA, Node1_Radio3_TxData); % Download samples to |
---|
141 | % radio 3 Tx Buffer |
---|
142 | warplab_writeSMWO(udp_node1, RADIO4_TXDATA, Node1_Radio4_TxData); % Download samples to |
---|
143 | % radio 4 Tx Buffer |
---|
144 | |
---|
145 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
146 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
147 | % start transmission and reception (trigger is the SYNC packet) |
---|
148 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
149 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
150 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
151 | % packet. |
---|
152 | |
---|
153 | % Enable transmitter radio path in all radios in node 1 (enable all radios |
---|
154 | % in node 1 as transmitters) |
---|
155 | warplab_sendCmd(udp_node1, [RADIO1_TXEN ,RADIO2_TXEN, RADIO3_TXEN, RADIO4_TXEN], packetNum); |
---|
156 | |
---|
157 | % Enable transmission of node1's Tx buffers (enable |
---|
158 | % transmission of samples stored in all radio Tx buffers in node 1) |
---|
159 | warplab_sendCmd(udp_node1, [RADIO1TXBUFF_TXEN, RADIO2TXBUFF_TXEN, RADIO3TXBUFF_TXEN, RADIO4TXBUFF_TXEN], packetNum); |
---|
160 | |
---|
161 | % Enable receiver radio path in radio 1 in node 2 (enable radio 1 |
---|
162 | % in node 2 as receivers) |
---|
163 | warplab_sendCmd(udp_node2, RADIO1_RXEN, packetNum); |
---|
164 | |
---|
165 | % Enable capture in node2's radio 1 Rx Buffer (enable radio 1 Rx buffer in |
---|
166 | % node 2 for storage of samples) |
---|
167 | warplab_sendCmd(udp_node2, RADIO1RXBUFF_RXEN, packetNum); |
---|
168 | |
---|
169 | % Prime transmitter state machine in node 1. Node 1 will be |
---|
170 | % waiting for the SYNC packet. Transmission from node 1 will be triggered |
---|
171 | % when node 1 receives the SYNC packet. |
---|
172 | warplab_sendCmd(udp_node1, TX_START, packetNum); |
---|
173 | |
---|
174 | % Prime receiver state machine in node 2. Node 2 will be waiting |
---|
175 | % for the SYNC packet. Capture at node 2 will be triggered when node 2 |
---|
176 | % receives the SYNC packet. |
---|
177 | warplab_sendCmd(udp_node2, RX_START, packetNum); |
---|
178 | |
---|
179 | % Send the SYNC packet |
---|
180 | warplab_sendSync(udp_Sync); |
---|
181 | |
---|
182 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
183 | % 3. Read the received samples from the Warp board |
---|
184 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
185 | % Read back the received samples from radio 1 |
---|
186 | [Node2_Radio1_RawRxData] = warplab_readSMRO(udp_node2, RADIO1_RXDATA, TxLength+TxDelay); |
---|
187 | % Process the received samples to obtain meaningful data |
---|
188 | [Node2_Radio1_RxData,Node2_Radio1_RxOTR] = warplab_processRawRxData(Node2_Radio1_RawRxData); |
---|
189 | |
---|
190 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
191 | % 4. Reset and disable the boards |
---|
192 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
193 | % Set all Tx buffers in node 1 back to Tx disabled mode |
---|
194 | warplab_sendCmd(udp_node1, [RADIO1TXBUFF_TXDIS, RADIO2TXBUFF_TXDIS, RADIO3TXBUFF_TXDIS, RADIO4TXBUFF_TXDIS], packetNum); |
---|
195 | |
---|
196 | % Disable the transmitter radios |
---|
197 | warplab_sendCmd(udp_node1, [RADIO1_TXDIS, RADIO2_TXDIS, RADIO3_TXDIS, RADIO4_TXDIS], packetNum); |
---|
198 | |
---|
199 | % Set radio 1 Rx buffer in node 2 back to Rx disabled mode |
---|
200 | warplab_sendCmd(udp_node2, RADIO1RXBUFF_RXDIS, packetNum); |
---|
201 | |
---|
202 | % Disable the receiver radios |
---|
203 | warplab_sendCmd(udp_node2, RADIO1_RXDIS, packetNum); |
---|
204 | |
---|
205 | % Close sockets |
---|
206 | pnet('closeall'); |
---|
207 | |
---|
208 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
209 | % 5. Plot the transmitted and received data |
---|
210 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
211 | figure; |
---|
212 | subplot(4,2,1); |
---|
213 | plot(real(Node1_Radio1_TxData)); |
---|
214 | title('Tx Node 1 Radio 1 I'); |
---|
215 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
216 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
217 | subplot(4,2,2); |
---|
218 | plot(imag(Node1_Radio1_TxData)); |
---|
219 | title('Tx Node 1 Radio 1 Q'); |
---|
220 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
221 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
222 | subplot(4,2,3); |
---|
223 | plot(real(Node1_Radio2_TxData)); |
---|
224 | title('Tx Node 1 Radio 2 I'); |
---|
225 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
226 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
227 | subplot(4,2,4); |
---|
228 | plot(imag(Node1_Radio2_TxData)); |
---|
229 | title('Tx Node 1 Radio 2 Q'); |
---|
230 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
231 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
232 | subplot(4,2,5); |
---|
233 | plot(real(Node1_Radio3_TxData)); |
---|
234 | title('Tx Node 1 Radio 3 I'); |
---|
235 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
236 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
237 | subplot(4,2,6); |
---|
238 | plot(imag(Node1_Radio3_TxData)); |
---|
239 | title('Tx Node 1 Radio 3 Q'); |
---|
240 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
241 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
242 | subplot(4,2,7); |
---|
243 | plot(real(Node1_Radio4_TxData)); |
---|
244 | title('Tx Node 1 Radio 4 I'); |
---|
245 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
246 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
247 | subplot(4,2,8); |
---|
248 | plot(imag(Node1_Radio4_TxData)); |
---|
249 | title('Tx Node 1 Radio 4 Q'); |
---|
250 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
251 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
252 | |
---|
253 | |
---|
254 | figure; |
---|
255 | subplot(2,1,1); |
---|
256 | plot(real(Node2_Radio1_RxData)); |
---|
257 | title('Rx Node 2 Radio 1 I'); |
---|
258 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
259 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
260 | subplot(2,1,2); |
---|
261 | plot(imag(Node2_Radio1_RxData)); |
---|
262 | title('Rx Node 2 Radio 1 Q'); |
---|
263 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
264 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|