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

Last change on this file was 1311, checked in by mduarte, 15 years ago

Adding files for WARPLab release 05

File size: 11.8 KB
Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% Generating a Frequency Sweep with Continous Transmission using WARPLab
3% (2x2 MIMO configuration)
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). Each transmitter radio transmits
10% a sinusoid with different frequency.
11% 2. Prepare WARP boards for transmission and reception and send trigger to
12% start transmission and reception (trigger is the SYNC packet)
13% 3. Leave continuous transmitter on for n seconds and then stop continuous
14% transmission.
15% 4. Read the received samples from the WARP board.
16% 5. Reset and disable the boards.
17% 6. Plot the transmitted and received data.
18
19
20%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21% 0. Initializaton and definition of parameters
22%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23%Load some global definitions (packet types, etc.)
24warplab_defines
25
26% Create Socket handles and intialize nodes
27[socketHandles, packetNum] = warplab_initialize;
28
29% Separate the socket handles for easier access
30% The first socket handle is always the magic SYNC
31% The rest of the handles are the handles to the WARP nodes
32udp_Sync = socketHandles(1);
33udp_node1 = socketHandles(2);
34udp_node2 = socketHandles(3);
35
36% Define WARPLab parameters.
37TxDelay = 1000; % Number of noise samples per Rx capture. In [0:2^14]
38TxLength = 2^14-1-1000; % Length of transmission. In [0:2^14-1-TxDelay]
39TxMode = 1; % Transmission mode. In [0:1]
40            % 0: Single Transmission
41            % 1: Continuous Transmission. Tx board will continue
42            % transmitting the vector of samples until the user manually
43            % disables the transmitter.
44CarrierChannel = 12; % Channel in the 2.4 GHz band. In [1:14]
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]
49Node2_Radio2_RxGain_BB = 13; % Rx Baseband Gain. In [0:31]
50Node2_Radio2_RxGain_RF = 1; % Rx RF Gain. In [1:3] 
51Node2_Radio3_RxGain_BB = 13; % Rx Baseband Gain. In [0:31]
52Node2_Radio3_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,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16));
80warplab_setRadioParameter(udp_node1,RADIO3_TXGAINS,(Node1_Radio3_TxGain_RF + Node1_Radio3_TxGain_BB*2^16));
81% Node 2 will be set as the receiver so download Rx gains to node 2.
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));
84% Set MGC mode in node 2 (receiver)
85warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select);
86
87%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88% 1. Generate a vector of samples to transmit and send the samples to the
89% Warp board (Sample Frequency is 40MHz).  Vector represents a sinusoid
90% with complex frequency linearly increasing in time.
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 2, 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
103f1 = 1e6;
104Node1_Radio2_TxData = exp(t*j*2*pi*f1);
105
106% Download the samples to be transmitted
107warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData); % Download samples to
108% radio 2 Tx Buffer
109
110% Create a signal to transmit from radio 3, the signal can be real or complex.
111% The signal must meet the following requirements:
112% - Signal to transmit must be a row vector.
113% - The amplitude of the real part must be in [-1:1] and the amplitude
114% of the imaginary part must be in [-1:1].
115% - Highest frequency component is limited to 9.5 MHz (signal bandwidth
116% is limited to 19 MHz)
117% - Lowest frequency component is limited to 30 kHz
118f2 = 6e6;
119Node1_Radio3_TxData = exp(t*j*2*pi*f2); 
120
121warplab_writeSMWO(udp_node1, RADIO3_TXDATA, Node1_Radio3_TxData); % Download samples to
122% radio 3 Tx Buffer
123
124%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
125% 2. Prepare boards for transmission and reception and send trigger to
126% start transmission and reception (trigger is the SYNC packet)
127%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128% The following lines of code set node 1 as transmitter and node 2 as
129% receiver; transmission and capture are triggered by sending the SYNC
130% packet.
131
132% Enable transmitter radio path in radios 2 and 3 in node 1 (enable radio 2
133% and radio 3 in node 1 as transmitters)
134warplab_sendCmd(udp_node1, [RADIO2_TXEN, RADIO3_TXEN], packetNum);
135
136% Enable transmission of node1's radio 2 and radio 3 Tx buffer (enable
137% transmission of samples stored in radio 2 Tx Buffer and in radio 3 Tx
138% Buffer in node 1)
139warplab_sendCmd(udp_node1, [RADIO2TXBUFF_TXEN, RADIO3TXBUFF_TXEN], packetNum);
140
141% Enable receiver radio path in radios 2 and 3 in node 2 (enable radios 2
142% and 3 in node 2 as receivers)
143warplab_sendCmd(udp_node2, [RADIO2_RXEN, RADIO3_RXEN], packetNum);
144
145% Enable capture in node2's radio 2 and radio 3 Rx Buffer (enable radio 2
146% Rx buffer and radio 3 Rx buffer in node 2 for storage of samples)
147warplab_sendCmd(udp_node2, [RADIO2RXBUFF_RXEN, RADIO3RXBUFF_RXEN], packetNum);
148
149% Prime transmitter state machine in node 1. Node 1 will be
150% waiting for the SYNC packet. Transmission from node 1 will be triggered
151% when node 1 receives the SYNC packet.
152warplab_sendCmd(udp_node1, TX_START, packetNum);
153
154% Prime receiver state machine in node 2. Node 2 will be waiting
155% for the SYNC packet. Capture at node 2 will be triggered when node 2
156% receives the SYNC packet.
157warplab_sendCmd(udp_node2, RX_START, packetNum);
158
159% Send the SYNC packet
160warplab_sendSync(udp_Sync);
161
162%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163% 3. Leave continuous transmitter on for n seconds and then stop continuous
164% transmission and disable transmitter radio
165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166% Leave continuous transmitter on for nsec seconds
167nsec = 5;
168pause(nsec);
169
170% Stop transmission
171warplab_sendCmd(udp_node1, TX_STOP, packetNum); % Resets the output and read
172% address of the transmitter buffer without disabling the transmitter radio.
173
174%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175% 4. Read the received samples from the Warp board
176%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177% In continuous transmitter mode the receiver stores TxDelay samples of
178% noise and the first 2^14-TxDelay samples transmitted.
179
180% Read back the received samples from radio 2
181[Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay);
182% Read back the received samples from radio 3
183[Node2_Radio3_RawRxData] = warplab_readSMRO(udp_node2, RADIO3_RXDATA, TxLength+TxDelay);
184% Process the received samples to obtain meaningful data
185[Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData);
186[Node2_Radio3_RxData,Node2_Radio3_RxOTR] = warplab_processRawRxData(Node2_Radio3_RawRxData);
187
188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189% 5. Reset and disable the boards
190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191% Set radios 2 and 3 Tx buffer in node 1 back to Tx disabled mode
192warplab_sendCmd(udp_node1, [RADIO2TXBUFF_TXDIS RADIO3TXBUFF_TXDIS], packetNum);
193
194% Disable the transmitter radios
195warplab_sendCmd(udp_node1, [RADIO2_TXDIS, RADIO3_TXDIS], packetNum);
196
197% Set radios 2 and 3 Rx buffer in node 2 back to Rx disabled mode
198warplab_sendCmd(udp_node2, [RADIO2RXBUFF_RXDIS, RADIO3RXBUFF_RXDIS], packetNum);
199
200% Disable the receiver radios
201warplab_sendCmd(udp_node2, [RADIO2_RXDIS,RADIO3_RXDIS], packetNum);
202
203% Close sockets
204pnet('closeall');
205
206%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
207% 6. Plot the transmitted and received data
208%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209figure;
210subplot(4,2,1);
211plot(real(Node1_Radio2_TxData));
212title('Tx Node 1 Radio 2 I');
213xlabel('n (samples)'); ylabel('Amplitude');
214axis([0 2^14 -1 1]); % Set axis ranges.
215subplot(4,2,2);
216plot(imag(Node1_Radio2_TxData));
217title('Tx Node 1 Radio 2 Q');
218xlabel('n (samples)'); ylabel('Amplitude');
219axis([0 2^14 -1 1]); % Set axis ranges.
220subplot(4,2,3);
221plot(real(Node1_Radio3_TxData));
222title('Tx Node 1 Radio 3 I');
223xlabel('n (samples)'); ylabel('Amplitude');
224axis([0 2^14 -1 1]); % Set axis ranges.
225subplot(4,2,4);
226plot(imag(Node1_Radio3_TxData));
227title('Tx Node 1 Radio 3 Q');
228xlabel('n (samples)'); ylabel('Amplitude');
229axis([0 2^14 -1 1]); % Set axis ranges.
230subplot(4,2,5);
231plot(real(Node2_Radio2_RxData));
232title('Rx Node 2 Radio 2 I');
233xlabel('n (samples)'); ylabel('Amplitude');
234axis([0 2^14 -1 1]); % Set axis ranges.
235subplot(4,2,6);
236plot(imag(Node2_Radio2_RxData));
237title('Rx Node 2 Radio 2 Q');
238xlabel('n (samples)'); ylabel('Amplitude');
239axis([0 2^14 -1 1]); % Set axis ranges.
240subplot(4,2,7);
241plot(real(Node2_Radio3_RxData));
242title('Rx Node 2 Radio 3 I');
243xlabel('n (samples)'); ylabel('Amplitude');
244axis([0 2^14 -1 1]); % Set axis ranges.
245subplot(4,2,8);
246plot(imag(Node2_Radio2_RxData));
247title('Rx Node 2 Radio 3 Q');
248xlabel('n (samples)'); ylabel('Amplitude');
249axis([0 2^14 -1 1]); % Set axis ranges.
Note: See TracBrowser for help on using the repository browser.