1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | % wl_example_basic_txrx.m |
---|
3 | % |
---|
4 | % This example demonstrates basic transmission and reception of waveforms |
---|
5 | % between two WARP nodes. One node will transmit a simple sinusoid and the |
---|
6 | % other node will receive the sinusoid. |
---|
7 | % |
---|
8 | % Requirements: |
---|
9 | % 2 WARP nodes (same hardware generation); 2 RF interfaces each |
---|
10 | % |
---|
11 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
12 | |
---|
13 | clear; |
---|
14 | |
---|
15 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
16 | % Set up the WARPLab experiment |
---|
17 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
18 | |
---|
19 | % Create a vector of node objects |
---|
20 | nodes = wl_initNodes(2); |
---|
21 | |
---|
22 | % Set up transmit and receive nodes |
---|
23 | % NOTE: Transmit from nodes(1) to nodes(2) |
---|
24 | % |
---|
25 | node_tx = nodes(1); |
---|
26 | node_rx = nodes(2); |
---|
27 | |
---|
28 | |
---|
29 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
30 | % Set up Trigger Manager |
---|
31 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
32 | |
---|
33 | % Create a UDP broadcast trigger and tell each node to be ready for it |
---|
34 | % NOTE: This will allow us to trigger both nodes to begin transmission / reception of IQ data |
---|
35 | % |
---|
36 | eth_trig = wl_trigger_eth_udp_broadcast; |
---|
37 | wl_triggerManagerCmd(nodes, 'add_ethernet_trigger', [eth_trig]); |
---|
38 | |
---|
39 | % Read Trigger IDs into workspace |
---|
40 | trig_in_ids = wl_getTriggerInputIDs(nodes(1)); |
---|
41 | trig_out_ids = wl_getTriggerOutputIDs(nodes(1)); |
---|
42 | |
---|
43 | % For both nodes, we will allow Ethernet A to trigger the baseband buffers |
---|
44 | wl_triggerManagerCmd(nodes, 'output_config_input_selection', [trig_out_ids.BASEBAND], [trig_in_ids.ETH_A]); |
---|
45 | |
---|
46 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
47 | % Set up the Interface parameters |
---|
48 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
49 | |
---|
50 | % Get IDs for the interfaces on the boards. |
---|
51 | % |
---|
52 | % NOTE: This example assumes each board has the same interface capabilities (ie 2 RF |
---|
53 | % interfaces; RFA and RFB). Therefore, we only need to get the IDs from one of the boards. |
---|
54 | % |
---|
55 | ifc_ids = wl_getInterfaceIDs(nodes(1)); |
---|
56 | |
---|
57 | % Set the RF center frequency on all interfaces |
---|
58 | % - Frequency Band : Must be 2.4 or 5, to select 2.4GHz or 5GHz channels |
---|
59 | % - Channel : Must be an integer in [1,11] for BAND = 2.4; [1,23] for BAND = 5 |
---|
60 | % |
---|
61 | wl_interfaceCmd(nodes, ifc_ids.RF_ALL, 'channel', 2.4, 11); |
---|
62 | |
---|
63 | % Set the RX gains on all interfaces |
---|
64 | % - Rx RF Gain : Must be an integer in [1:3] |
---|
65 | % - Rx Baseband Gain: Must be an integer in [0:31] |
---|
66 | % |
---|
67 | % NOTE: The gains may need to be modified depending on your experimental setup |
---|
68 | % |
---|
69 | wl_interfaceCmd(nodes, ifc_ids.RF_ALL, 'rx_gain_mode', 'manual'); |
---|
70 | wl_interfaceCmd(nodes, ifc_ids.RF_ALL, 'rx_gains', 1, 15); |
---|
71 | |
---|
72 | % Set the TX gains on all interfaces |
---|
73 | % - Tx Baseband Gain: Must be an integer in [0:3] for approx [-5, -3, -1.5, 0]dB baseband gain |
---|
74 | % - Tx RF Gain : Must be an integer in [0:63] for approx [0:31]dB RF gain |
---|
75 | % |
---|
76 | % NOTE: The gains may need to be modified depending on your experimental setup |
---|
77 | % |
---|
78 | wl_interfaceCmd(nodes, ifc_ids.RF_ALL, 'tx_gains', 3, 30); |
---|
79 | |
---|
80 | |
---|
81 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
82 | % Set up the Baseband parameters |
---|
83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
84 | |
---|
85 | % Get the baseband sampling frequencies from the board |
---|
86 | ts_tx = 1 / (wl_basebandCmd(nodes(1), 'tx_buff_clk_freq')); |
---|
87 | ts_rx = 1 / (wl_basebandCmd(nodes(1), 'rx_buff_clk_freq')); |
---|
88 | ts_rssi = 1 / (wl_basebandCmd(nodes(1), 'rx_rssi_clk_freq')); |
---|
89 | |
---|
90 | % Get the maximum I/Q buffer length |
---|
91 | % |
---|
92 | % NOTE: This example assumes that each board has the same baseband capabilities (ie both nodes are |
---|
93 | % the same WARP hardware version, for example WARP v3). This example also assumes that each RF |
---|
94 | % interface has the same baseband capabilities (ie the max number of TX samples is the same as the |
---|
95 | % max number of RF samples). Therefore, we only need to read the max I/Q buffer length of RF_A for |
---|
96 | % the transmitting node. |
---|
97 | % |
---|
98 | maximum_buffer_len = wl_basebandCmd(node_tx, ifc_ids.RF_A, 'tx_buff_max_num_samples'); |
---|
99 | |
---|
100 | % Set the transmission / receptions lengths (in samples) |
---|
101 | % See WARPLab user guide for maximum length supported by WARP hardware |
---|
102 | % versions and different WARPLab versions. |
---|
103 | tx_length = 2^12; |
---|
104 | rx_length = tx_length; |
---|
105 | rssi_length = floor(rx_length / (ts_rssi / ts_rx)); |
---|
106 | |
---|
107 | % Check the transmission length |
---|
108 | if (tx_length > maximum_buffer_len) |
---|
109 | error('Node supports max transmission length of %d samples. Requested %d samples.', maximum_buffer_len, tx_length); |
---|
110 | end |
---|
111 | |
---|
112 | % Set the length for the transmit and receive buffers based on the transmission length |
---|
113 | wl_basebandCmd(nodes, 'tx_length', tx_length); |
---|
114 | wl_basebandCmd(nodes, 'rx_length', rx_length); |
---|
115 | |
---|
116 | |
---|
117 | |
---|
118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
119 | % Signal processing to generate transmit signal |
---|
120 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
121 | |
---|
122 | % Create the IQ data payload |
---|
123 | t = [0:ts_tx:((tx_length - 1) * ts_tx)].'; % Create time vector (Sample Frequency is ts_tx (Hz)) |
---|
124 | |
---|
125 | sinusoid_1 = 0.6 * exp(j*2*pi * 1e6 * t); % Create 1 MHz sinusoid |
---|
126 | % sinusoid_2 = 0.6 * exp(j*2*pi * 5e4 * t); % Create 50 kHz sinusoid to transmit on RF_B |
---|
127 | |
---|
128 | tx_data = [sinusoid_1]; % Create the data to transmit on RF_A |
---|
129 | % tx_data = [sinusoid_1, sinusoid_2]; % Create the data to transmit on both RF_A and RF_B |
---|
130 | |
---|
131 | |
---|
132 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
133 | % Transmit and receive signal using WARPLab |
---|
134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
135 | |
---|
136 | % Transmit IQ data to the TX node |
---|
137 | wl_basebandCmd(node_tx, [ifc_ids.RF_A], 'write_IQ', tx_data); |
---|
138 | % wl_basebandCmd(node_tx, [ifc_ids.RF_A, ifc_ids.RF_B], 'write_IQ', tx_data); % Write each sinusoid to a different interface |
---|
139 | |
---|
140 | % Enabled the RF interfaces for TX / RX |
---|
141 | wl_interfaceCmd(node_tx, ifc_ids.RF_A, 'tx_en'); |
---|
142 | wl_interfaceCmd(node_rx, ifc_ids.RF_A, 'rx_en'); |
---|
143 | % wl_interfaceCmd(node_tx, ifc_ids.RF_ON_BOARD, 'tx_en'); % Enable both RF_A and RF_B |
---|
144 | % wl_interfaceCmd(node_rx, ifc_ids.RF_ON_BOARD, 'rx_en'); % Enable both RF_A and RF_B |
---|
145 | |
---|
146 | % Enable the buffers for TX / RX |
---|
147 | wl_basebandCmd(node_tx, ifc_ids.RF_A, 'tx_buff_en'); |
---|
148 | wl_basebandCmd(node_rx, ifc_ids.RF_A, 'rx_buff_en'); |
---|
149 | % wl_basebandCmd(node_tx, ifc_ids.RF_ON_BOARD, 'tx_buff_en'); % Enable both RF_A and RF_B |
---|
150 | % wl_basebandCmd(node_rx, ifc_ids.RF_ON_BOARD, 'rx_buff_en'); % Enable both RF_A and RF_B |
---|
151 | |
---|
152 | % Send the Ethernet trigger to start the TX / RX |
---|
153 | eth_trig.send(); |
---|
154 | |
---|
155 | % Read the IQ and RSSI data from the RX node |
---|
156 | rx_iq = wl_basebandCmd(node_rx, [ifc_ids.RF_A], 'read_IQ', 0, rx_length); |
---|
157 | rx_rssi = wl_basebandCmd(node_rx, [ifc_ids.RF_A], 'read_RSSI', 0, rssi_length); |
---|
158 | % rx_iq = wl_basebandCmd(node_rx, [ifc_ids.RF_A, ifc_ids.RF_B], 'read_IQ', 0, rx_length); % Read IQ data from both RF_A and RF_B |
---|
159 | % rx_rssi = wl_basebandCmd(node_rx, [ifc_ids.RF_A, ifc_ids.RF_B], 'read_RSSI', 0, rssi_length); % Read RSSI data from both RF_A and RF_B |
---|
160 | |
---|
161 | % Disable the buffers and RF interfaces for TX / RX |
---|
162 | wl_basebandCmd(nodes, ifc_ids.RF_A, 'tx_rx_buff_dis'); |
---|
163 | wl_interfaceCmd(nodes, ifc_ids.RF_A, 'tx_rx_dis'); |
---|
164 | % wl_basebandCmd(nodes, ifc_ids.RF_ON_BOARD, 'tx_rx_buff_dis'); % Disable both RF_A and RF_B |
---|
165 | % wl_interfaceCmd(nodes, ifc_ids.RF_ON_BOARD, 'tx_rx_dis'); % Disable both RF_A and RF_B |
---|
166 | |
---|
167 | |
---|
168 | |
---|
169 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
170 | % Visualize results |
---|
171 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
172 | |
---|
173 | figure(1);clf; |
---|
174 | |
---|
175 | % Plot IQ Data |
---|
176 | % |
---|
177 | ax(1) = subplot(3, 2, 1); |
---|
178 | plot(0:(length(tx_data) - 1), real(tx_data(:, 1))) |
---|
179 | xlabel('Sample Index') |
---|
180 | title('Node 1 RFA: Transmitted I') |
---|
181 | axis([1 tx_length -1 1]) |
---|
182 | |
---|
183 | ax(2) = subplot(3, 2, 2); |
---|
184 | plot(0:(length(tx_data) - 1), imag(tx_data(:, 1))) |
---|
185 | xlabel('Sample Index') |
---|
186 | title('Node 1 RFA: Transmitted Q') |
---|
187 | axis([1 tx_length -1 1]) |
---|
188 | |
---|
189 | bx(1) = subplot(3, 2, 3); |
---|
190 | plot(0:(length(rx_iq) - 1), real(rx_iq(:, 1))) |
---|
191 | xlabel('Sample Index') |
---|
192 | title('Node 2 RFA: Received I') |
---|
193 | axis([1 rx_length -1 1]) |
---|
194 | |
---|
195 | bx(2) = subplot(3, 2, 4); |
---|
196 | plot(0:(length(rx_iq) - 1), imag(rx_iq(:, 1))) |
---|
197 | xlabel('Sample Index') |
---|
198 | title('Node 2 RFA: Received Q') |
---|
199 | axis([1 rx_length -1 1]) |
---|
200 | |
---|
201 | linkaxes([ax, bx], 'x') |
---|
202 | |
---|
203 | |
---|
204 | % Plot RSSI data |
---|
205 | % |
---|
206 | subplot(3, 1, 3) |
---|
207 | plot(0:(length(rx_rssi) - 1), rx_rssi(:, 1)) |
---|
208 | xlabel('Sample Index') |
---|
209 | title('Node 2 RFA: Received RSSI') |
---|
210 | axis([0 rssi_length 0 1024]) |
---|
211 | |
---|
212 | |
---|
213 | % |
---|
214 | % NOTE: It is left to the user to plot the IQ and RSSI data for RF_B in rx_iq(:, 2) |
---|
215 | % and rx_rssi(:, 2), respectively, if receiving on both RF_A and RF_B. |
---|
216 | % |
---|
217 | |
---|
218 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
219 | % END |
---|
220 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|