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

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

M-code note update

File size: 11.3 KB
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% Transmitting and Receiving Data using WARPLab (1x4 SIMO 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 = 1; % Tx Baseband Gain. In [0:3]
44Node1_Radio1_TxGain_RF = 25; % Tx RF Gain. In [0:63]
45Node2_Radio1_RxGain_BB = 17; % Rx Baseband Gain. In [0:31]
46Node2_Radio1_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
47Node2_Radio2_RxGain_BB = 17; % Rx Baseband Gain. In [0:31]
48Node2_Radio2_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
49Node2_Radio3_RxGain_BB = 17; % Rx Baseband Gain. In [0:31]
50Node2_Radio3_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
51Node2_Radio4_RxGain_BB = 17; % Rx Baseband Gain. In [0:31]
52Node2_Radio4_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.
57Node2_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).
72warplab_writeRegister(udp_node1,TX_DELAY,TxDelay);
73warplab_writeRegister(udp_node1,TX_LENGTH,TxLength);
74warplab_writeRegister(udp_node1,TX_MODE,TxMode);
75% The CarrierChannel parameter must be downloaded to all nodes 
76warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel);
77warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel);
78% Node 1 will be set as the transmitter so download Tx gains to node 1.
79warplab_setRadioParameter(udp_node1,RADIO1_TXGAINS,(Node1_Radio1_TxGain_RF + Node1_Radio1_TxGain_BB*2^16));
80% Node 2 will be set as the receiver so download Rx gains to node 2.
81warplab_setRadioParameter(udp_node2,RADIO1_RXGAINS,(Node2_Radio1_RxGain_BB + Node2_Radio1_RxGain_RF*2^16));
82warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16));
83warplab_setRadioParameter(udp_node2,RADIO3_RXGAINS,(Node2_Radio3_RxGain_BB + Node2_Radio3_RxGain_RF*2^16));
84warplab_setRadioParameter(udp_node2,RADIO4_RXGAINS,(Node2_Radio4_RxGain_BB + Node2_Radio4_RxGain_RF*2^16));
85% Set MGC mode in node 2 (receiver)
86warplab_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
93t = 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
103Node1_Radio1_TxData = exp(t*j*2*pi*1e6);
104
105% Download the samples to be transmitted
106warplab_writeSMWO(udp_node1, RADIO1_TXDATA, Node1_Radio1_TxData); % Download samples to
107% radio 1 Tx Buffer
108
109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110% 2. Prepare WARP boards for transmission and reception and send trigger to
111% start transmission and reception (trigger is the SYNC packet)
112%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113% The following lines of code set node 1 as transmitter and node 2 as
114% receiver; transmission and capture are triggered by sending the SYNC
115% packet.
116
117% Enable transmitter radio path in radio 1 in node 1 (enable radio 1
118% in node 1 as transmitters)
119warplab_sendCmd(udp_node1, RADIO1_TXEN, packetNum);
120
121% Enable transmission of node1's radio 1 Tx buffer (enable
122% transmission of samples stored in radio 1 Tx buffer in node 1)
123warplab_sendCmd(udp_node1, RADIO1TXBUFF_TXEN, packetNum);
124
125% Enable receiver radio path in all radios in node 2 (enable all radios
126% in node 2 as receivers)
127warplab_sendCmd(udp_node2, [RADIO1_RXEN, RADIO2_RXEN, RADIO3_RXEN, RADIO4_RXEN], packetNum);
128
129% Enable capture in node2's Rx Buffers (enable all Rx buffers in node 2
130% for storage of samples)
131warplab_sendCmd(udp_node2, [RADIO1RXBUFF_RXEN, RADIO2RXBUFF_RXEN, RADIO3RXBUFF_RXEN, RADIO4RXBUFF_RXEN], packetNum);
132
133% Prime transmitter state machine in node 1. Node 1 will be
134% waiting for the SYNC packet. Transmission from node 1 will be triggered
135% when node 1 receives the SYNC packet.
136warplab_sendCmd(udp_node1, TX_START, packetNum);
137
138% Prime receiver state machine in node 2. Node 2 will be waiting
139% for the SYNC packet. Capture at node 2 will be triggered when node 2
140% receives the SYNC packet.
141warplab_sendCmd(udp_node2, RX_START, packetNum);
142
143% Send the SYNC packet
144warplab_sendSync(udp_Sync);
145
146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147% 3. Read the received samples from the Warp board
148%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
149% Read back the received samples from radio 1
150[Node2_Radio1_RawRxData] = warplab_readSMRO(udp_node2, RADIO1_RXDATA, TxLength+TxDelay);
151% Read back the received samples from radio 2
152[Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay);
153% Read back the received samples from radio 3
154[Node2_Radio3_RawRxData] = warplab_readSMRO(udp_node2, RADIO3_RXDATA, TxLength+TxDelay);
155% Read back the received samples from radio 4
156[Node2_Radio4_RawRxData] = warplab_readSMRO(udp_node2, RADIO4_RXDATA, TxLength+TxDelay);
157% Process the received samples to obtain meaningful data
158[Node2_Radio1_RxData,Node2_Radio1_RxOTR] = warplab_processRawRxData(Node2_Radio1_RawRxData);
159[Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData);
160[Node2_Radio3_RxData,Node2_Radio3_RxOTR] = warplab_processRawRxData(Node2_Radio3_RawRxData);
161[Node2_Radio4_RxData,Node2_Radio4_RxOTR] = warplab_processRawRxData(Node2_Radio4_RawRxData);
162
163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164% 4. Reset and disable the boards
165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166% Set radio 1 Tx buffers in node 1 back to Tx disabled mode
167warplab_sendCmd(udp_node1, RADIO1TXBUFF_TXDIS, packetNum);
168
169% Disable the transmitter radio
170warplab_sendCmd(udp_node1, RADIO1_TXDIS, packetNum);
171
172% Set all Rx buffers in node 2 back to Rx disabled mode
173warplab_sendCmd(udp_node2, [RADIO1RXBUFF_RXDIS, RADIO2RXBUFF_RXDIS, RADIO3RXBUFF_RXDIS, RADIO4RXBUFF_RXDIS], packetNum);
174
175% Disable the receiver radios
176warplab_sendCmd(udp_node2, [RADIO1_RXDIS, RADIO2_RXDIS, RADIO3_RXDIS, RADIO4_RXDIS], packetNum);
177
178% Close sockets
179pnet('closeall');
180
181%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182% 5. Plot the transmitted and received data
183%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184figure;
185subplot(2,1,1);
186plot(real(Node1_Radio1_TxData));
187title('Tx Node 1 Radio 1 I');
188xlabel('n (samples)'); ylabel('Amplitude');
189axis([0 2^14 -1 1]); % Set axis ranges.
190subplot(2,1,2);
191plot(imag(Node1_Radio1_TxData));
192title('Tx Node 1 Radio 1 Q');
193xlabel('n (samples)'); ylabel('Amplitude');
194axis([0 2^14 -1 1]); % Set axis ranges.
195
196
197figure;
198subplot(4,2,1);
199plot(real(Node2_Radio1_RxData));
200title('Rx Node 2 Radio 1 I');
201xlabel('n (samples)'); ylabel('Amplitude');
202axis([0 2^14 -1 1]); % Set axis ranges.
203subplot(4,2,2);
204plot(imag(Node2_Radio1_RxData));
205title('Rx Node 2 Radio 1 Q');
206xlabel('n (samples)'); ylabel('Amplitude');
207axis([0 2^14 -1 1]); % Set axis ranges.
208subplot(4,2,3);
209plot(real(Node2_Radio2_RxData));
210title('Rx Node 2 Radio 2 I');
211xlabel('n (samples)'); ylabel('Amplitude');
212axis([0 2^14 -1 1]); % Set axis ranges.
213subplot(4,2,4);
214plot(imag(Node2_Radio2_RxData));
215title('Rx Node 2 Radio 2 Q');
216xlabel('n (samples)'); ylabel('Amplitude');
217axis([0 2^14 -1 1]); % Set axis ranges.
218subplot(4,2,5);
219plot(real(Node2_Radio3_RxData));
220title('Rx Node 2 Radio 3 I');
221xlabel('n (samples)'); ylabel('Amplitude');
222axis([0 2^14 -1 1]); % Set axis ranges.
223subplot(4,2,6);
224plot(imag(Node2_Radio3_RxData));
225title('Rx Node 2 Radio 4 Q');
226xlabel('n (samples)'); ylabel('Amplitude');
227axis([0 2^14 -1 1]); % Set axis ranges.
228subplot(4,2,7);
229plot(real(Node2_Radio4_RxData));
230title('Rx Node 2 Radio 4 I');
231xlabel('n (samples)'); ylabel('Amplitude');
232axis([0 2^14 -1 1]); % Set axis ranges.
233subplot(4,2,8);
234plot(imag(Node2_Radio4_RxData));
235title('Rx Node 2 Radio 4 Q');
236xlabel('n (samples)'); ylabel('Amplitude');
237axis([0 2^14 -1 1]); % Set axis ranges.
Note: See TracBrowser for help on using the repository browser.