source: ResearchApps/PHY/WARPLAB/WARPLab_v05_2/WorkshopExercises/warplab_siso_example_TxRx_WorkshopExercise.m

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

workshop exercises

File size: 10.8 KB
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% Transmitting and Receiving Data using WARPLab (SISO Configuration)
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4
5% The specific steps implemented in this script are the following
6
7% 0. Initializaton and definition of parameters
8% 1. Generate a vector of samples to transmit and send the samples to the
9% WARP board (Sample Frequency is 40MHz)
10% 2. Prepare WARP boards for transmission and reception and send trigger to
11% start transmission and reception (trigger is the SYNC packet)
12% 3. Read the received samples from the WARP board
13% 4. Reset and disable the boards
14% 5. Plot the transmitted and received data and close sockets
15
16% In this lab exercise you will write a matlab script that implements the
17% six steps above. Part of the code is provided, some part of the code you
18% will write. Read the code below and fill in with your code wherever you
19% are asked to do so.
20
21% NOTE: To avoid conflict with other groups using the boards, please test
22% the code you write in this script in any of the following three ways:
23%
24% Option 1. Run this script from MATLAB's Command Window by entering the
25% name of the script (enter warplab_siso_example_TxRx_WorkshopExercise in
26% matlab's Command Window).
27% Option 2. In the menu bar go to Debug and select Run. If there
28% are errors in the code, error messages will appear in the Command Window.
29% Option 3. Press F5. If the are errors in the code, error messages will
30% appear in the Command Window.
31%
32% DO NOT USE the Evaluate selection option and DO NOT run the script by
33% sections. To test any change, always run the whole script by following
34% any of the three options above.
35
36% WARPLab documentation can be found online at
37% http://warp.rice.edu/trac/wiki/WARPLab
38
39
40try,
41%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42% Code to avoid conflict between users, only needed for the workshop, go to
43% step 0 below to start the initialization and definition of parameters
44%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45% fid = fopen('c:\boards_lock.txt');
46%
47% if(fid > -1)
48%     fclose('all');
49%   errordlg('Boards already in use - Please try again!');
50%   return;
51% end
52
53% !echo > c:\boards_lock.txt
54
55
56%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57% 0. Initializaton and definition of parameters
58%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59%Load some global definitions (packet types, etc.)
60warplab_defines
61
62% Create Socket handles and intialize nodes
63[socketHandles, packetNum] = warplab_initialize;
64
65% Separate the socket handles for easier access
66% The first socket handle is always the magic SYNC
67% The rest of the handles are the handles to the WARP nodes
68udp_Sync = socketHandles(1);
69udp_node1 = socketHandles(2);
70udp_node2 = socketHandles(3);
71
72% Define WARPLab parameters.
73%-------------------------------------------------------------------------%
74% USER CODE HERE
75
76% Create the following variables and assign them valid values:
77
78% TxDelay: Number of noise samples per Rx capture. In [0:2^14]
79% TxLength: Length of transmission. In [0:2^14-1-TxDelay]
80% CarrierChannel: Channel in the 2.4 GHz band. In [1:14]
81% Node1_Radio2_TxGain_BB: Tx Baseband Gain. In [0:3]
82% Node1_Radio2_TxGain_RF: Tx RF Gain. In [0:63]
83% Node2_Radio2_RxGain_BB: Rx Baseband Gain. In [0:31]
84% Node2_Radio2_RxGain_RF: Rx RF Gain. In [1:3] 
85
86% Note: For this experiment node 1 will be set as the transmitter and node
87% 2 will be set as the receiver (this is done later in the code), hence,
88% there is no need to define receive gains for node 1 and there is no
89% need to define transmitter gains for node 2.
90
91
92%-------------------------------------------------------------------------%
93
94TxMode = 0; % Transmission mode. In [0:1]
95            % 0: Single Transmission
96            % 1: Continuous Transmission. Tx board will continue
97            % transmitting the vector of samples until the user manually
98            % disables the transmitter.
99
100% Download the WARPLab parameters to the WARP nodes.
101% The nodes store the TxDelay, TxLength, and TxMode parameters in
102% registers defined in the WARPLab sysgen model. The nodes set radio
103% related parameters CarrierChannel, TxGains, and RxGains, using the
104% radio controller functions.
105
106% The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter;
107% the receiver doesn't require knowledge of these parameters (the receiver
108% will always capture 2^14 samples). For this exercise node 1 will be set as
109% the transmitter (this is done later in the code). Since TxDelay, TxLength and
110% TxMode are only required at the transmitter we download the TxDelay, TxLength and
111% TxMode parameters only to the transmitter node (node 1).
112warplab_writeRegister(udp_node1,TX_DELAY,TxDelay);
113warplab_writeRegister(udp_node1,TX_LENGTH,TxLength);
114warplab_writeRegister(udp_node1,TX_MODE,TxMode);
115% The CarrierChannel parameter must be downloaded to all nodes 
116warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel);
117warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel);
118% Node 1 will be set as the transmitter so download Tx gains to node 1.
119warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16));
120% Node 2 will be set as the receiver so download Rx gains to node 2.
121warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16));
122
123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124% 1. Generate a vector of samples to transmit and send the samples to the
125% WARP board (Sample Frequency is 40MHz)
126%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127% Prepare some data to be transmitted
128t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector.
129
130%-------------------------------------------------------------------------%
131% USER CODE HERE
132
133% Create a signal to transmit, the signal is a function of the time vector
134% 't' the signal can be real or complex. Store the signal to transmit in a
135% variable named 'Node1_Radio2_TxData' (Node1_Radio2_TxData = your signal).
136
137% The signal must meet the following requirements:
138% - Signal to transmit must be a row vector.
139% - The amplitude of the real part must be in [-1:1] and the amplitude
140% of the imaginary part must be in [-1:1].
141% - Highest frequency component is limited to 9.5 MHz (signal bandwidth
142% is limited to 19 MHz)
143% - Lowest frequency component is limited to 30 kHz
144
145%-------------------------------------------------------------------------%
146
147% Download the samples to be transmitted
148warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData);
149
150%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151% 2. Prepare WARP boards for transmission and reception and send trigger to
152% start transmission and reception (trigger is the SYNC packet)
153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154% The following lines of code set node 1 as transmitter and node 2 as
155% receiver; transmission and capture are triggered by sending the SYNC
156% packet.
157
158% Enable transmitter radio path in radio 2 in node 1 (enable radio 2 in
159% node 1 as transmitter)
160warplab_sendCmd(udp_node1, RADIO2_TXEN, packetNum);
161
162% Enable transmission of node1's radio 2 Tx buffer (enable transmission
163% of samples stored in radio 2 Tx Buffer in node 1)
164warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXEN, packetNum);
165
166% Enable receiver radio path in radio 2 in node 2 (enable radio 2 in
167% node 2 as receiver)
168warplab_sendCmd(udp_node2, RADIO2_RXEN, packetNum);
169
170% Enable capture in node2's radio 2 Rx Buffer (enable radio 2 rx buffer in
171% node 2 for storage of samples)
172warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXEN, packetNum);
173
174% Prime transmitter state machine in node 1. Node 1 will be
175% waiting for the SYNC packet. Transmission from node 1 will be triggered
176% when node 1 receives the SYNC packet.
177warplab_sendCmd(udp_node1, TX_START, packetNum);
178
179% Prime receiver state machine in node 2. Node 2 will be waiting
180% for the SYNC packet. Capture at node 2 will be triggered when node 2
181% receives the SYNC packet.
182warplab_sendCmd(udp_node2, RX_START, packetNum);
183
184% Send the SYNC packet
185warplab_sendSync(udp_Sync);
186
187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188% 3. Read the received samples from the WARP board
189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190% Read back the received samples
191[Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay);
192% Process the received samples to obtain meaningful data
193[Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData);
194% Read stored RSSI data
195[Node2_Radio2_RawRSSIData] = warplab_readSMRO(udp_node2, RADIO2_RSSIDATA, ceil((TxLength+TxDelay)/8));
196% Procecss Raw RSSI data to obtain meningful RSSI values
197[Node2_Radio2_RSSIData] = warplab_processRawRSSIData(Node2_Radio2_RawRSSIData);
198
199%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200% 4. Reset and disable the boards
201%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202% Set radio 2 Tx buffer in node 1 back to Tx disabled mode
203warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXDIS, packetNum);
204
205% Disable the transmitter radio
206warplab_sendCmd(udp_node1, RADIO2_TXDIS, packetNum);
207
208% Set radio 2 Rx buffer in node 2 back to Rx disabled mode
209warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXDIS, packetNum);
210
211% Disable the receiver radio
212warplab_sendCmd(udp_node2, RADIO2_RXDIS, packetNum);
213
214%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
215% 5. Plot the transmitted and received data and close sockets
216%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
217figure;
218subplot(2,2,1);
219plot(real(Node1_Radio2_TxData));
220title('Tx Node 1 Radio 2 I');
221xlabel('n (samples)'); ylabel('Amplitude');
222axis([0 2^14 -1 1]); % Set axis ranges.
223subplot(2,2,2);
224plot(imag(Node1_Radio2_TxData));
225title('Tx Node 1 Radio 2 Q');
226xlabel('n (samples)'); ylabel('Amplitude');
227axis([0 2^14 -1 1]); % Set axis ranges.
228subplot(2,2,3);
229plot(real(Node2_Radio2_RxData));
230title('Rx Node 2 Radio 2 I');
231xlabel('n (samples)'); ylabel('Amplitude');
232axis([0 2^14 -1 1]); % Set axis ranges.
233subplot(2,2,4);
234plot(imag(Node2_Radio2_RxData));
235title('Rx Node 2 Radio 2 Q');
236xlabel('n (samples)'); ylabel('Amplitude');
237axis([0 2^14 -1 1]); % Set axis ranges.
238
239% Close sockets
240pnet('closeall');
241
242% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
243% % Code to avoid conflict between users, only needed for the workshop
244% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
245% !del c:\boards_lock.txt
246catch,
247% Reset nodes
248warplab_reset2x2Node(udp_node1);
249warplab_reset2x2Node(udp_node2);
250% Close sockets
251pnet('closeall');
252% !del c:\boards_lock.txt
253lasterr
254end
Note: See TracBrowser for help on using the repository browser.