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

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

M-code note update

File size: 12.4 KB
Line 
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.)
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 = 10; % Rx Baseband Gain. In [0:31]
52Node2_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.
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));
80warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16));
81warplab_setRadioParameter(udp_node1,RADIO3_TXGAINS,(Node1_Radio3_TxGain_RF + Node1_Radio3_TxGain_BB*2^16));
82warplab_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.
84warplab_setRadioParameter(udp_node2,RADIO1_RXGAINS,(Node2_Radio1_RxGain_BB + Node2_Radio1_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% 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 
113Node1_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
123Node1_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
133Node1_Radio4_TxData = exp(t*j*2*pi*7e6); 
134
135% Download the samples to be transmitted
136warplab_writeSMWO(udp_node1, RADIO1_TXDATA, Node1_Radio1_TxData); % Download samples to
137% radio 1 Tx Buffer
138warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData); % Download samples to
139% radio 2 Tx Buffer
140warplab_writeSMWO(udp_node1, RADIO3_TXDATA, Node1_Radio3_TxData); % Download samples to
141% radio 3 Tx Buffer
142warplab_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)
155warplab_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)
159warplab_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)
163warplab_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)
167warplab_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.
172warplab_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.
177warplab_sendCmd(udp_node2, RX_START, packetNum);
178
179% Send the SYNC packet
180warplab_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
194warplab_sendCmd(udp_node1, [RADIO1TXBUFF_TXDIS, RADIO2TXBUFF_TXDIS, RADIO3TXBUFF_TXDIS, RADIO4TXBUFF_TXDIS], packetNum);
195
196% Disable the transmitter radios
197warplab_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
200warplab_sendCmd(udp_node2, RADIO1RXBUFF_RXDIS, packetNum);
201
202% Disable the receiver radios
203warplab_sendCmd(udp_node2, RADIO1_RXDIS, packetNum);
204
205% Close sockets
206pnet('closeall');
207
208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209% 5. Plot the transmitted and received data
210%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
211figure;
212subplot(4,2,1);
213plot(real(Node1_Radio1_TxData));
214title('Tx Node 1 Radio 1 I');
215xlabel('n (samples)'); ylabel('Amplitude');
216axis([0 2^14 -1 1]); % Set axis ranges.
217subplot(4,2,2);
218plot(imag(Node1_Radio1_TxData));
219title('Tx Node 1 Radio 1 Q');
220xlabel('n (samples)'); ylabel('Amplitude');
221axis([0 2^14 -1 1]); % Set axis ranges.
222subplot(4,2,3);
223plot(real(Node1_Radio2_TxData));
224title('Tx Node 1 Radio 2 I');
225xlabel('n (samples)'); ylabel('Amplitude');
226axis([0 2^14 -1 1]); % Set axis ranges.
227subplot(4,2,4);
228plot(imag(Node1_Radio2_TxData));
229title('Tx Node 1 Radio 2 Q');
230xlabel('n (samples)'); ylabel('Amplitude');
231axis([0 2^14 -1 1]); % Set axis ranges.
232subplot(4,2,5);
233plot(real(Node1_Radio3_TxData));
234title('Tx Node 1 Radio 3 I');
235xlabel('n (samples)'); ylabel('Amplitude');
236axis([0 2^14 -1 1]); % Set axis ranges.
237subplot(4,2,6);
238plot(imag(Node1_Radio3_TxData));
239title('Tx Node 1 Radio 3 Q');
240xlabel('n (samples)'); ylabel('Amplitude');
241axis([0 2^14 -1 1]); % Set axis ranges.
242subplot(4,2,7);
243plot(real(Node1_Radio4_TxData));
244title('Tx Node 1 Radio 4 I');
245xlabel('n (samples)'); ylabel('Amplitude');
246axis([0 2^14 -1 1]); % Set axis ranges.
247subplot(4,2,8);
248plot(imag(Node1_Radio4_TxData));
249title('Tx Node 1 Radio 4 Q');
250xlabel('n (samples)'); ylabel('Amplitude');
251axis([0 2^14 -1 1]); % Set axis ranges.
252
253
254figure;
255subplot(2,1,1);
256plot(real(Node2_Radio1_RxData));
257title('Rx Node 2 Radio 1 I');
258xlabel('n (samples)'); ylabel('Amplitude');
259axis([0 2^14 -1 1]); % Set axis ranges.
260subplot(2,1,2);
261plot(imag(Node2_Radio1_RxData));
262title('Rx Node 2 Radio 1 Q');
263xlabel('n (samples)'); ylabel('Amplitude');
264axis([0 2^14 -1 1]); % Set axis ranges.
Note: See TracBrowser for help on using the repository browser.