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

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

M-code note update

File size: 13.2 KB
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% Transmitting and Receiving Data using WARPLab (SISO Configuration) and
3% example on how to set Tx and Rx Low Pass Filter (LPF) Bandwidths
4%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5% To run this M-code the boards must be programmed with the
6% 2x2 MIMO 5.x version of WARPLab bitstream (because this bitstream provides
7% storage of RSSI values and this M-code reads RSSI values). This M-code
8% will work with the warplab_mimo_4x4_v05.bit bitstream when reading of
9% RSSI values is deleted from the M-code.
10
11% The specific steps implemented in this script are the following
12
13% 0. Initializaton and definition of parameters (Including change of Tx and Rx
14% Low Pass Filter Bandwidths)
15% 1. Generate a chirp (sweeping sinusoid) to transmit and send the samples to the
16% WARP board (Sample Frequency is 40MHz)
17% 2. Prepare WARP boards for transmission and reception and send trigger to
18% start transmission and reception (trigger is the SYNC packet)
19% 3. Read the received samples from the WARP board
20% 4. Reset and disable the boards
21% 5. Plot the transmitted and received data and close sockets
22
23%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
24% 0. Initializaton and definition of parameters
25%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26%Load some global definitions (packet types, etc.)
27warplab_defines
28
29% Create Socket handles and intialize nodes
30[socketHandles, packetNum] = warplab_initialize;
31
32% Separate the socket handles for easier access
33% The first socket handle is always the magic SYNC
34% The rest of the handles are the handles to the WARP nodes
35udp_Sync = socketHandles(1);
36udp_node1 = socketHandles(2);
37udp_node2 = socketHandles(3);
38
39% Define WARPLab parameters.
40% For this experiment node 1 will be set as the transmitter and node
41% 2 will be set as the receiver (this is done later in the code), hence,
42% there is no need to define receive gains for node 1 and there is no
43% need to define transmitter gains for node 2.
44TxDelay = 0; % Number of noise samples per Rx capture. In [0:2^14]
45TxLength = 2^14-2; % Length of transmission. In [0:2^14-1-TxDelay]
46CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14]
47Node1_Radio2_TxGain_BB = 3; % Tx Baseband Gain. In [0:3]
48Node1_Radio2_TxGain_RF = 60; % Tx RF Gain. In [0:63]
49Node2_Radio2_RxGain_BB = 14; % Rx Baseband Gain. In [0:31]
50Node2_Radio2_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
51TxMode = 0; % Transmission mode. In [0:1]
52            % 0: Single Transmission
53            % 1: Continuous Transmission. Tx board will continue
54            % transmitting the vector of samples until the user manually
55            % disables the transmitter.
56Node2_MGC_AGC_Select = 0;   % Set MGC_AGC_Select=1 to enable Automatic Gain Control (AGC).
57                            % Set MGC_AGC_Select=0 to enable Manual Gain Control (MGC).
58                            % By default, the nodes are set to MGC. 
59Node1_Tx_LowPassFilt = 1; % Transmitter Low Pass Filter (LPF) bandwidth. In [1:3]
60                   % 1: 12 MHz (nominal mode)
61                   % 2: 18 MHz (turbo mode 1)
62                   % 3: 24 MHz (turbo mode 2)
63Node2_Rx_LowPassFilt = 3; % Receiver Low Pass Filter (LPF) bandwidth. In [0:3]
64                   % 0: 7.5 MHz
65                   % 1: 9.5 MHz (nominal mode)
66                   % 2: 14 MHz (turbo mode 1)
67                   % 3: 18 MHz (turbo mode 2)                   
68
69% Download the WARPLab parameters to the WARP nodes.
70% The nodes store the TxDelay, TxLength, and TxMode parameters in
71% registers defined in the WARPLab sysgen model. The nodes set radio
72% related parameters CarrierChannel, TxGains, and RxGains, using the
73% radio controller functions.
74
75% The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter;
76% the receiver doesn't require knowledge of these parameters (the receiver
77% will always capture 2^14 samples). For this exercise node 1 will be set as
78% the transmitter (this is done later in the code). Since TxDelay, TxLength and
79% TxMode are only required at the transmitter we download the TxDelay, TxLength and
80% TxMode parameters only to the transmitter node (node 1).
81warplab_writeRegister(udp_node1,TX_DELAY,TxDelay);
82warplab_writeRegister(udp_node1,TX_LENGTH,TxLength);
83warplab_writeRegister(udp_node1,TX_MODE,TxMode);
84% The CarrierChannel parameter must be downloaded to all nodes 
85warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel);
86warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel);
87% Node 1 will be set as the transmitter so download Tx gains to node 1.
88warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16));
89% Node 2 will be set as the receiver so download Rx gains to node 2.
90warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16));
91% Node 1 will be set as the transmitter so download desired TX LPF setting.
92warplab_setRadioParameter(udp_node1,TX_LPF_CORN_FREQ,Node1_Tx_LowPassFilt);
93% Node 2 will be set as the receiver so download desired TX LPF setting.
94warplab_setRadioParameter(udp_node2,RX_LPF_CORN_FREQ,Node2_Rx_LowPassFilt); 
95% Set MGC mode in node 2 (receiver)
96warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select);
97
98%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99% 1. Generate a vector of samples to transmit and send the samples to the
100% WARP board (Sample Frequency is 40MHz)
101%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102% Prepare some data to be transmitted
103TxLength = 2^14;
104t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector.
105
106% Create frequency vector for sweep
107fmin = 0;
108fmax = 20e6;
109% Second derivative of phase is slope of linear increase of frequency with
110% time
111d2phase_dt = (fmax-fmin)/t(end); 
112% Integrate twice to get phase as a function of time
113phase_t = (1/2)*d2phase_dt*t.^2 + fmin *t; 
114
115Node1_Radio2_TxData = exp(j*2*pi*phase_t); % chirp starts at DC and ends at 18MHz                                             
116
117% Download the samples to be transmitted
118warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData);
119
120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121% 2. Prepare WARP boards for transmission and reception and send trigger to
122% start transmission and reception (trigger is the SYNC packet)
123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124% The following lines of code set node 1 as transmitter and node 2 as
125% receiver; transmission and capture are triggered by sending the SYNC
126% packet.
127
128% Enable transmitter radio path in radio 2 in node 1 (enable radio 2 in
129% node 1 as transmitter)
130warplab_sendCmd(udp_node1, RADIO2_TXEN, packetNum);
131
132% Enable transmission of node1's radio 2 Tx buffer (enable transmission
133% of samples stored in radio 2 Tx Buffer in node 1)
134warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXEN, packetNum);
135
136% Enable receiver radio path in radio 2 in node 2 (enable radio 2 in
137% node 2 as receiver)
138warplab_sendCmd(udp_node2, RADIO2_RXEN, packetNum);
139
140% Enable capture in node2's radio 2 Rx Buffer (enable radio 2 rx buffer in
141% node 2 for storage of samples)
142warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXEN, packetNum);
143
144% Prime transmitter state machine in node 1. Node 1 will be
145% waiting for the SYNC packet. Transmission from node 1 will be triggered
146% when node 1 receives the SYNC packet.
147warplab_sendCmd(udp_node1, TX_START, packetNum);
148
149% Prime receiver state machine in node 2. Node 2 will be waiting
150% for the SYNC packet. Capture at node 2 will be triggered when node 2
151% receives the SYNC packet.
152warplab_sendCmd(udp_node2, RX_START, packetNum);
153
154% Send the SYNC packet
155warplab_sendSync(udp_Sync);
156
157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158% 3. Read the received samples from the WARP board
159%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
160% Read back the received samples
161[Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay);
162% Process the received samples to obtain meaningful data
163[Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData);
164% Read stored RSSI data
165[Node2_Radio2_RawRSSIData] = warplab_readSMRO(udp_node2, RADIO2_RSSIDATA, ceil((TxLength+TxDelay)/8));
166% Procecss Raw RSSI data to obtain meningful RSSI values
167[Node2_Radio2_RSSIData] = warplab_processRawRSSIData(Node2_Radio2_RawRSSIData);
168% Note: If the two lines of code above (warplab_processRawRSSIData line and
169% warplab_readSMRO(udp_node2, RADIO2_RSSIDATA, (TxLength+TxDelay)/8) line)
170% are deleted, then the code will work when the boards are programmed
171% with the warplab_mimo_4x4_v04.bit bitstream)
172
173%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
174% 4. Reset and disable the boards
175%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176% Set radio 2 Tx buffer in node 1 back to Tx disabled mode
177warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXDIS, packetNum);
178
179% Disable the transmitter radio
180warplab_sendCmd(udp_node1, RADIO2_TXDIS, packetNum);
181
182% Set radio 2 Rx buffer in node 2 back to Rx disabled mode
183warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXDIS, packetNum);
184
185% Disable the receiver radio
186warplab_sendCmd(udp_node2, RADIO2_RXDIS, packetNum);
187
188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189% 5. Plot the transmitted and received data and close sockets
190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191frequency_vector = d2phase_dt*t;
192frequency_vector_RSSI = frequency_vector(1:4:end);
193frequency_vector_RSSI = frequency_vector_RSSI(1:length(frequency_vector_RSSI));
194
195figure;
196subplot(2,2,1);
197plot(real(Node1_Radio2_TxData));
198title('Tx Node 1 Radio 2 I');
199xlabel('n (samples)'); ylabel('Amplitude');
200axis([0 2^14 -1 1]); % Set axis ranges.
201subplot(2,2,2);
202plot(imag(Node1_Radio2_TxData));
203title('Tx Node 1 Radio 2 Q');
204xlabel('n (samples)'); ylabel('Amplitude');
205axis([0 2^14 -1 1]); % Set axis ranges.
206subplot(2,2,3);
207plot(real(Node2_Radio2_RxData));
208title('Rx Node 2 Radio 2 I');
209xlabel('n (samples)'); ylabel('Amplitude');
210axis([0 2^14 -1 1]); % Set axis ranges.
211subplot(2,2,4);
212plot(imag(Node2_Radio2_RxData));
213title('Rx Node 2 Radio 2 Q');
214xlabel('n (samples)'); ylabel('Amplitude');
215axis([0 2^14 -1 1]); % Set axis ranges.
216
217figure;
218subplot(2,2,1);
219plot(frequency_vector,abs(Node2_Radio2_RxData));
220title('Magnitude Rx Node 1 Radio 2');
221xlabel('Frequency'); ylabel('Magnitude');
222axis([0 20e6 -1 1]); % Set axis ranges.
223subplot(2,2,2);
224plot(abs(Node2_Radio2_RxData));
225title('Magnitude Rx Node 1 Radio 2');
226xlabel('n (samples)'); ylabel('Magnitude');
227axis([0 2^14 -1 1]); % Set axis ranges.
228subplot(2,2,3);
229plot(frequency_vector_RSSI,Node2_Radio2_RSSIData);
230title('Magnitude RSSI Node 1 Radio 2');
231xlabel('Frequency'); ylabel('Magnitude');
232axis([0 20e6 0 2^10]); % Set axis ranges.
233subplot(2,2,4);
234plot(Node2_Radio2_RSSIData);
235title('Magnitude RRSSI Node 1 Radio 2');
236xlabel('n (samples)'); ylabel('Magnitude');
237axis([0 2^14 0 2^10]); % Set axis ranges.
238
239% figure;
240% subplot(2,1,1);
241% plot(frequency_vector,abs(Node2_Radio2_RxData));
242% title('Magnitude Rx Node 1 Radio 2');
243% xlabel('Frequency'); ylabel('Magnitude');
244% axis([0 20e6 -1 1]); % Set axis ranges.
245% subplot(2,1,2);
246% plot(abs(Node2_Radio2_RxData));
247% title('Magnitude Rx Node 1 Radio 2');
248% xlabel('n (samples)'); ylabel('Magnitude');
249% axis([0 2^14 -1 1]); % Set axis ranges.
250%
251% figure;
252% subplot(2,1,1);
253% plot(frequency_vector_RSSI,Node2_Radio2_RSSIData);
254% title('Magnitude RSSI Node 1 Radio 2');
255% xlabel('Frequency'); ylabel('Magnitude');
256% axis([0 20e6 -1 1]); % Set axis ranges.
257% subplot(2,1,2);
258% plot(Node2_Radio2_RSSIData);
259% title('Magnitude RSSI Node 1 Radio 2');
260% xlabel('n (samples)'); ylabel('Magnitude');
261% axis([0 2^14 -1 1]); % Set axis ranges.
262
263% figure;
264% subplot(2,2,1);
265% plot(frequency_vector,real(Node1_Radio2_TxData));
266% title('Tx Node 1 Radio 2 I');
267% xlabel('Frequency'); ylabel('Magnitude');
268% axis([0 20e6 -1 1]); % Set axis ranges.
269% subplot(2,2,2);
270% plot(frequency_vector,imag(Node1_Radio2_TxData));
271% title('Tx Node 1 Radio 2 Q');
272% xlabel('Frequency'); ylabel('Magnitude');
273% axis([0 20e6 -1 1]); % Set axis ranges.
274% subplot(2,2,3);
275% plot(frequency_vector,real(Node2_Radio2_RxData));
276% title('Rx Node 2 Radio 2 I');
277% xlabel('Frequency'); ylabel('Magnitude');
278% axis([0 20e6 -1 1]); % Set axis ranges.
279% subplot(2,2,4);
280% plot(frequency_vector,imag(Node2_Radio2_RxData));
281% title('Rx Node 2 Radio 2 Q');
282% xlabel('Frequency'); ylabel('Magnitude');
283% axis([0 20e6 -1 1]); % Set axis ranges.
284
285
286% figure;
287% subplot(2,1,1);
288% plot(frequency_vector,abs(Node1_Radio2_TxData));
289% title('Magnitude Tx Node 1 Radio 2');
290% xlabel('Frequency'); ylabel('Magnitude');
291% axis([0 20e6 -1 1]); % Set axis ranges.
292% subplot(2,1,2);
293% plot(frequency_vector,abs(Node1_Radio2_TxData));
294% title('Magnitude Rx Node 1 Radio 2');
295% xlabel('Frequency'); ylabel('Magnitude');
296% axis([0 20e6 -1 1]); % Set axis ranges.
297
298
299% Close sockets
300pnet('closeall');
Note: See TracBrowser for help on using the repository browser.