source: ResearchApps/PHY/WARPLAB/WARPLab_v05_2/M_Code_Examples/warplab_mimo_4x4_example_TxRx.m

Last change on this file was 1394, checked in by sgupta, 14 years ago

M-code note update

File size: 14.9 KB
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% Transmitting and Receiving Data using WARPLab (4x4 MIMO 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.)
22warplab_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
30udp_Sync = socketHandles(1);
31udp_node1 = socketHandles(2);
32udp_node2 = socketHandles(3);
33
34% Define WARPLab parameters.
35TxDelay = 1000; % Number of noise samples per Rx capture. In [0:2^14]
36TxLength = 2^14-1-1000; % Length of transmission. In [0:2^14-1-TxDelay]
37TxMode = 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.
42CarrierChannel = 12; % Channel in the 2.4 GHz band. In [1:14]
43Node1_Radio1_TxGain_BB = 3; % Tx Baseband Gain. In [0:3]
44Node1_Radio1_TxGain_RF = 40; % Tx RF Gain. In [0:63]
45Node1_Radio2_TxGain_BB = 3; % Tx Baseband Gain. In [0:3]
46Node1_Radio2_TxGain_RF = 40; % Tx RF Gain. In [0:63]
47Node1_Radio3_TxGain_BB = 3; % Tx Baseband Gain. In [0:3]
48Node1_Radio3_TxGain_RF = 40; % Tx RF Gain. In [0:63]
49Node1_Radio4_TxGain_BB = 3; % Tx Baseband Gain. In [0:3]
50Node1_Radio4_TxGain_RF = 40; % Tx RF Gain. In [0:63]
51Node2_Radio1_RxGain_BB = 12; % Rx Baseband Gain. In [0:31]
52Node2_Radio1_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
53Node2_Radio2_RxGain_BB = 12; % Rx Baseband Gain. In [0:31]
54Node2_Radio2_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
55Node2_Radio3_RxGain_BB = 12; % Rx Baseband Gain. In [0:31]
56Node2_Radio3_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
57Node2_Radio4_RxGain_BB = 12; % Rx Baseband Gain. In [0:31]
58Node2_Radio4_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
59% Note: For this experiment node 1 will be set as the transmitter and node
60% 2 will be set as the receiver (this is done later in the code), hence,
61% there is no need to define receive gains for node1 and there is no
62% need to define transmitter gains for node2.
63Node2_MGC_AGC_Select = 0;   % Set MGC_AGC_Select=1 to enable Automatic Gain Control (AGC).
64                            % Set MGC_AGC_Select=0 to enable Manual Gain Control (MGC).
65                            % By default, the nodes are set to MGC. 
66
67% Download the WARPLab parameters to the WARP nodes.
68% The nodes store the TxDelay, TxLength, and TxMode parameters in
69% registers defined in the WARPLab sysgen model. The nodes set radio
70% related parameters CarrierChannel, TxGains, and RxGains, using the
71% radio controller functions.
72% The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter;
73% the receiver doesn't require knowledge of these parameters (the receiver
74% will always capture 2^14 samples). For this exercise node 1 will be set as
75% the transmitter (this is done later in the code). Since TxDelay, TxLength and
76% TxMode are only required at the transmitter we download the TxDelay, TxLength and
77% TxMode parameters only to the transmitter node (node 1).
78warplab_writeRegister(udp_node1,TX_DELAY,TxDelay);
79warplab_writeRegister(udp_node1,TX_LENGTH,TxLength);
80warplab_writeRegister(udp_node1,TX_MODE,TxMode);
81% The CarrierChannel parameter must be downloaded to all nodes 
82warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel);
83warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel);
84% Node 1 will be set as the transmitter so download Tx gains to node 1.
85warplab_setRadioParameter(udp_node1,RADIO1_TXGAINS,(Node1_Radio1_TxGain_RF + Node1_Radio1_TxGain_BB*2^16));
86warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16));
87warplab_setRadioParameter(udp_node1,RADIO3_TXGAINS,(Node1_Radio3_TxGain_RF + Node1_Radio3_TxGain_BB*2^16));
88warplab_setRadioParameter(udp_node1,RADIO4_TXGAINS,(Node1_Radio4_TxGain_RF + Node1_Radio4_TxGain_BB*2^16));
89% Node 2 will be set as the receiver so download Rx gains to node 2.
90warplab_setRadioParameter(udp_node2,RADIO1_RXGAINS,(Node2_Radio1_RxGain_BB + Node2_Radio1_RxGain_RF*2^16));
91warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16));
92warplab_setRadioParameter(udp_node2,RADIO3_RXGAINS,(Node2_Radio3_RxGain_BB + Node2_Radio3_RxGain_RF*2^16));
93warplab_setRadioParameter(udp_node2,RADIO4_RXGAINS,(Node2_Radio4_RxGain_BB + Node2_Radio4_RxGain_RF*2^16));
94% Set MGC mode in node 2 (receiver)
95warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select);
96
97%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98% 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
102t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector
103
104% Create a signal to transmit from radio 1, the signal can be real or complex.
105% The signal must meet the following requirements:
106% - Signal to transmit must be a row vector.
107% - The amplitude of the real part must be in [-1:1] and the amplitude
108% of the imaginary part must be in [-1:1].
109% - Highest frequency component is limited to 9.5 MHz (signal bandwidth
110% is limited to 19 MHz)
111% - Lowest frequency component is limited to 30 kHz
112Node1_Radio1_TxData = exp(t*j*2*pi*1e6); 
113
114% Create a signal to transmit from radio 2, the signal can be real or complex.
115% The signal must meet the following requirements:
116% - Signal to transmit must be a row vector.
117% - The amplitude of the real part must be in [-1:1] and the amplitude
118% of the imaginary part must be in [-1:1].
119% - Highest frequency component is limited to 9.5 MHz (signal bandwidth
120% is limited to 19 MHz)
121% - Lowest frequency component is limited to 30 kHz
122Node1_Radio2_TxData = exp(t*j*2*pi*3e6); 
123
124% Create a signal to transmit from radio 3, the signal can be real or complex.
125% The signal must meet the following requirements:
126% - Signal to transmit must be a row vector.
127% - The amplitude of the real part must be in [-1:1] and the amplitude
128% of the imaginary part must be in [-1:1].
129% - Highest frequency component is limited to 9.5 MHz (signal bandwidth
130% is limited to 19 MHz)
131% - Lowest frequency component is limited to 30 kHz
132Node1_Radio3_TxData = exp(t*j*2*pi*5e6); 
133
134% Create a signal to transmit from radio 4, the signal can be real or complex.
135% The signal must meet the following requirements:
136% - Signal to transmit must be a row vector.
137% - The amplitude of the real part must be in [-1:1] and the amplitude
138% of the imaginary part must be in [-1:1].
139% - Highest frequency component is limited to 9.5 MHz (signal bandwidth
140% is limited to 19 MHz)
141% - Lowest frequency component is limited to 30 kHz
142Node1_Radio4_TxData = exp(t*j*2*pi*7e6); 
143
144% Download the samples to be transmitted
145warplab_writeSMWO(udp_node1, RADIO1_TXDATA, Node1_Radio1_TxData); % Download samples to
146% radio 1 Tx Buffer
147warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData); % Download samples to
148% radio 2 Tx Buffer
149warplab_writeSMWO(udp_node1, RADIO3_TXDATA, Node1_Radio3_TxData); % Download samples to
150% radio 3 Tx Buffer
151warplab_writeSMWO(udp_node1, RADIO4_TXDATA, Node1_Radio4_TxData); % Download samples to
152% radio 4 Tx Buffer
153
154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155% 2. Prepare WARP boards for transmission and reception and send trigger to
156% start transmission and reception (trigger is the SYNC packet)
157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158% The following lines of code set node 1 as transmitter and node 2 as
159% receiver; transmission and capture are triggered by sending the SYNC
160% packet.
161
162% Enable transmitter radio path in all radios in node 1 (enable all radios
163% in node 1 as transmitters)
164warplab_sendCmd(udp_node1, [RADIO1_TXEN ,RADIO2_TXEN, RADIO3_TXEN, RADIO4_TXEN], packetNum);
165
166% Enable transmission of node1's  Tx buffers (enable
167% transmission of samples stored in all radio Tx buffers in node 1)
168warplab_sendCmd(udp_node1, [RADIO1TXBUFF_TXEN, RADIO2TXBUFF_TXEN, RADIO3TXBUFF_TXEN, RADIO4TXBUFF_TXEN], packetNum);
169
170% Enable receiver radio path in all radios in node 2 (enable all radios
171% in node 2 as receivers)
172warplab_sendCmd(udp_node2, [RADIO1_RXEN, RADIO2_RXEN, RADIO3_RXEN, RADIO4_RXEN], packetNum);
173
174% Enable capture in node2's Rx Buffers (enable all Rx buffers in node 2
175% for storage of samples)
176warplab_sendCmd(udp_node2, [RADIO1RXBUFF_RXEN, RADIO2RXBUFF_RXEN, RADIO3RXBUFF_RXEN, RADIO4RXBUFF_RXEN], packetNum);
177
178% Prime transmitter state machine in node 1. Node 1 will be
179% waiting for the SYNC packet. Transmission from node 1 will be triggered
180% when node 1 receives the SYNC packet.
181warplab_sendCmd(udp_node1, TX_START, packetNum);
182
183% Prime receiver state machine in node 2. Node 2 will be waiting
184% for the SYNC packet. Capture at node 2 will be triggered when node 2
185% receives the SYNC packet.
186warplab_sendCmd(udp_node2, RX_START, packetNum);
187
188% Send the SYNC packet
189warplab_sendSync(udp_Sync);
190
191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192% 3. Read the received samples from the Warp board
193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194% Read back the received samples from radio 1
195[Node2_Radio1_RawRxData] = warplab_readSMRO(udp_node2, RADIO1_RXDATA, TxLength+TxDelay);
196% Read back the received samples from radio 2
197[Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay);
198% Read back the received samples from radio 3
199[Node2_Radio3_RawRxData] = warplab_readSMRO(udp_node2, RADIO3_RXDATA, TxLength+TxDelay);
200% Read back the received samples from radio 4
201[Node2_Radio4_RawRxData] = warplab_readSMRO(udp_node2, RADIO4_RXDATA, TxLength+TxDelay);
202% Process the received samples to obtain meaningful data
203[Node2_Radio1_RxData,Node2_Radio1_RxOTR] = warplab_processRawRxData(Node2_Radio1_RawRxData);
204[Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData);
205[Node2_Radio3_RxData,Node2_Radio3_RxOTR] = warplab_processRawRxData(Node2_Radio3_RawRxData);
206[Node2_Radio4_RxData,Node2_Radio4_RxOTR] = warplab_processRawRxData(Node2_Radio4_RawRxData);
207
208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209% 4. Reset and disable the boards
210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211% Set all Tx buffers in node 1 back to Tx disabled mode
212warplab_sendCmd(udp_node1, [RADIO1TXBUFF_TXDIS, RADIO2TXBUFF_TXDIS, RADIO3TXBUFF_TXDIS, RADIO4TXBUFF_TXDIS], packetNum);
213
214% Disable the transmitter radios
215warplab_sendCmd(udp_node1, [RADIO1_TXDIS, RADIO2_TXDIS, RADIO3_TXDIS, RADIO4_TXDIS], packetNum);
216
217% Set all Rx buffers in node 2 back to Rx disabled mode
218warplab_sendCmd(udp_node2, [RADIO1RXBUFF_RXDIS, RADIO2RXBUFF_RXDIS, RADIO3RXBUFF_RXDIS, RADIO4RXBUFF_RXDIS], packetNum);
219
220% Disable the receiver radios
221warplab_sendCmd(udp_node2, [RADIO1_RXDIS, RADIO2_RXDIS, RADIO3_RXDIS, RADIO4_RXDIS], packetNum);
222
223% Close sockets
224pnet('closeall');
225
226%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227% 5. Plot the transmitted and received data
228%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229figure;
230subplot(4,2,1);
231plot(real(Node1_Radio1_TxData));
232title('Tx Node 1 Radio 1 I');
233xlabel('n (samples)'); ylabel('Amplitude');
234axis([0 2^14 -1 1]); % Set axis ranges.
235subplot(4,2,2);
236plot(imag(Node1_Radio1_TxData));
237title('Tx Node 1 Radio 1 Q');
238xlabel('n (samples)'); ylabel('Amplitude');
239axis([0 2^14 -1 1]); % Set axis ranges.
240subplot(4,2,3);
241plot(real(Node1_Radio2_TxData));
242title('Tx Node 1 Radio 2 I');
243xlabel('n (samples)'); ylabel('Amplitude');
244axis([0 2^14 -1 1]); % Set axis ranges.
245subplot(4,2,4);
246plot(imag(Node1_Radio2_TxData));
247title('Tx Node 1 Radio 2 Q');
248xlabel('n (samples)'); ylabel('Amplitude');
249axis([0 2^14 -1 1]); % Set axis ranges.
250subplot(4,2,5);
251plot(real(Node1_Radio3_TxData));
252title('Tx Node 1 Radio 3 I');
253xlabel('n (samples)'); ylabel('Amplitude');
254axis([0 2^14 -1 1]); % Set axis ranges.
255subplot(4,2,6);
256plot(imag(Node1_Radio3_TxData));
257title('Tx Node 1 Radio 3 Q');
258xlabel('n (samples)'); ylabel('Amplitude');
259axis([0 2^14 -1 1]); % Set axis ranges.
260subplot(4,2,7);
261plot(real(Node1_Radio4_TxData));
262title('Tx Node 1 Radio 4 I');
263xlabel('n (samples)'); ylabel('Amplitude');
264axis([0 2^14 -1 1]); % Set axis ranges.
265subplot(4,2,8);
266plot(imag(Node1_Radio4_TxData));
267title('Tx Node 1 Radio 4 Q');
268xlabel('n (samples)'); ylabel('Amplitude');
269axis([0 2^14 -1 1]); % Set axis ranges.
270
271
272figure;
273subplot(4,2,1);
274plot(real(Node2_Radio1_RxData));
275title('Rx Node 2 Radio 1 I');
276xlabel('n (samples)'); ylabel('Amplitude');
277axis([0 2^14 -1 1]); % Set axis ranges.
278subplot(4,2,2);
279plot(imag(Node2_Radio1_RxData));
280title('Rx Node 2 Radio 1 Q');
281xlabel('n (samples)'); ylabel('Amplitude');
282axis([0 2^14 -1 1]); % Set axis ranges.
283subplot(4,2,3);
284plot(real(Node2_Radio2_RxData));
285title('Rx Node 2 Radio 2 I');
286xlabel('n (samples)'); ylabel('Amplitude');
287axis([0 2^14 -1 1]); % Set axis ranges.
288subplot(4,2,4);
289plot(imag(Node2_Radio2_RxData));
290title('Rx Node 2 Radio 2 Q');
291xlabel('n (samples)'); ylabel('Amplitude');
292axis([0 2^14 -1 1]); % Set axis ranges.
293subplot(4,2,5);
294plot(real(Node2_Radio3_RxData));
295title('Rx Node 2 Radio 3 I');
296xlabel('n (samples)'); ylabel('Amplitude');
297axis([0 2^14 -1 1]); % Set axis ranges.
298subplot(4,2,6);
299plot(imag(Node2_Radio3_RxData));
300title('Rx Node 2 Radio 4 Q');
301xlabel('n (samples)'); ylabel('Amplitude');
302axis([0 2^14 -1 1]); % Set axis ranges.
303subplot(4,2,7);
304plot(real(Node2_Radio4_RxData));
305title('Rx Node 2 Radio 4 I');
306xlabel('n (samples)'); ylabel('Amplitude');
307axis([0 2^14 -1 1]); % Set axis ranges.
308subplot(4,2,8);
309plot(imag(Node2_Radio4_RxData));
310title('Rx Node 2 Radio 4 Q');
311xlabel('n (samples)'); ylabel('Amplitude');
312axis([0 2^14 -1 1]); % Set axis ranges.
Note: See TracBrowser for help on using the repository browser.