root/ResearchApps/PHY/WARPLAB/WARPLab_SISO_MIMO2x2/M_Code/warplab_mimo_example_ContinuousTx_WorkshopExercise_Solution.m

Revision 839, 10.8 kB (checked in by MelissaDuarte, 4 months ago)

WARPLab Release 02 April 09 2008. Release for 2x2 MIMO and improved SISO. Matlab code is modified to support MIMO. SISO now supports continuous transmission. There is one bitstream for MIMO and one bitstream for SISO. The xps project for MIMO and SISO is different but the M code is the same (The 'warplab_' functions are the same, the argument input to the functions is the only thing that changes from SISO to MIMO).

Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% Generating a Frequency Sweep with Continous Transmission using Warplab
3% (2x2 MIMO configuration)
4%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5% To run this code the boards must be programmed with the
6% warplab_mimo_v02.bit bitstream
7
8% The specific steps implemented in this script are the following
9
10% 0. Initializaton and definition of parameters
11% 1. Generate a vector of samples to transmit and send the samples to the
12% Warp board (Sample Frequency is 40MHz). Each transmitter radio transmits
13% a sinusoid with different frequency.
14% 2. Prepare boards for transmission and reception and send trigger to
15% start transmission and reception (trigger is the SYNC packet)
16% 3. Leave continuous transmitter on for n seconds and then stop continuous
17% transmission.
18% 4. Read the received samples from the Warp board.
19% 5. Reset and disable the boards.
20% 6. Plot the transmitted and received data.
21
22% In this lab exercise you will write a matlab script that implements the
23% seven steps above. Part of the code is provided, some part of the code you
24% will write. Read the code below and fill in with your code wherever you
25% are asked to do so.
26
27% NOTE: To avoid conflict with other groups using the boards, please test
28% the code you write in this script in any of the following three ways:
29%
30% Option 1. Run this script from matlab's Command Window by entering the
31% name of the script (enter warplab_example_TxRx_WorkshopExercise in
32% matlab's Command Window).
33% Option 2. In the menu bar go to Debug and select Run. If there
34% are errors in the code, error messages will appear in the Command Window.
35% Option 3. Press F5. If the are errors in the code, error messages will
36% appear in the Command Window.
37%
38% DO NOT USE the Evaluate selection option and DO NOT run the script by
39% sections. To test any change, always run the whole script by following
40% any of the three options above.
41
42try,
43%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44% Code to avoid conflict between users, only needed for the workshop, go to
45% step 0 below to start the initialization and definition of parameters
46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47fid = fopen('c:\boards_lock.txt');
48
49if(fid > -1)
50    fclose('all');
51        errordlg('Boards already in use - Please try again!');
52        return;
53end
54
55!echo > c:\boards_lock.txt
56
57%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58% 0. Initializaton and definition of parameters
59%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60%Load some global definitions (packet types, etc.)
61warplab_defines
62
63% Create Socket handles and intialize nodes
64[socketHandles, packetNum] = warplab_initialize;
65
66%Separate the socket handles for easier access
67% The first socket handle is always the magic SYNC
68% The rest can be arranged in any combination of Tx and Rx
69udp_Sync = socketHandles(1);
70udp_Tx = socketHandles(2);
71udp_RxA = socketHandles(3);
72
73% Define the warplab options (parameters)
74CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14]
75TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset]
76TransMode = 1; %Transmission mode; in [0:1]
77               % 0: Single Transmission
78               % 1: Continuous Transmission. Tx board will continue
79               % transmitting the vector of samples until the user manually
80               % disables the transmitter.
81CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14]
82Tx2GainBB = 3; %Tx Baseband Gain in [0:3]
83Tx2GainRF = 40; %Tx RF Gain in [0:63]
84Rx2GainBB = 15; %Rx Baseband Gain in [0:31]
85Rx2GainRF = 1; %Rx RF Gain in [1:3]
86Tx3GainBB = 3; %Tx Baseband Gain in [0:3]
87Tx3GainRF = 40; %Tx RF Gain in [0:63]
88Rx3GainBB = 15; %Rx Baseband Gain in [0:31]
89Rx3GainRF = 1; %Rx RF Gain in [1:3]
90TxSelect = 2; % Select transmitter radio [0:2] 0:Radio2, 1:Radio3, 2: Both
91RxSelect = 2; % Select transmitter radio [0:2] 0:Radio2, 1:Radio3, 2: Both
92
93% Define the options vector; the order of options is set by the FPGA's code
94% (C code)
95optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (Rx2GainBB + Rx2GainRF*2^16) (Tx2GainRF + Tx2GainBB*2^16) (Rx3GainBB + Rx3GainRF*2^16) (Tx3GainRF + Tx3GainBB*2^16) TxSelect RxSelect];
96% Send options vector to the nodes
97warplab_setOptions(socketHandles,optionsVector);
98
99%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100% 1. Generate a vector of samples to transmit and send the samples to the
101% Warp board (Sample Frequency is 40MHz).  Vector represents a sinusoid
102% with complex frequency linearly increasing in time.
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104% Prepare some data to be transmitted
105t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector
106
107% Create a signal to transmit from radio 2
108f1 = 1e6;
109TxData_2 = exp(t*j*2*pi*f1); %Signal must be a row vector. The signal can
110% be real or complex, the only constraint is that the amplitude of the real
111% part must be in [-1:1] and the amplitude of the imaginary part must be
112% in [-1:1]
113
114% Download the samples to be transmitted
115warplab_writeSMWO(udp_Tx, TxData_2, RADIO2_TXDATA); % Download samples to
116% radio 2 Tx Buffer
117
118% Create a signal to transmit from radio 3
119f2 = 6e6;
120TxData_3 = linspace(0,1,TxLength).*exp(t*j*2*pi*f2);
121% Signal must be a row vector. The signal can be real or complex,
122% the only constraint is that the amplitude of the real part must be in
123% [-1:1] and the amplitude of the imaginary part must be in [-1:1]
124
125warplab_writeSMWO(udp_Tx, TxData_3, RADIO3_TXDATA); % Download samples to
126% radio 3 Tx Buffer
127
128%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129% 2. Prepare boards for transmission and reception and send trigger to
130% start transmission and reception (trigger is the SYNC packet)
131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132% Enable transmitter radio path in transmitter node (enable radio 2 and
133% radio 3 in transmitter node as transmitters)
134warplab_sendCmd(udp_Tx, [RADIO2_TXEN RADIO3_TXEN], packetNum);
135
136% Enable receiver radio path in receiver node (enable radio 2 and
137% radio 3 in receiver node as receivers)
138warplab_sendCmd(udp_RxA, [RADIO2_RXEN RADIO3_RXEN], packetNum);
139
140% Prime transmitter state machine in transmitter node. Transmitter will be
141% waiting for the SYNC packet. Transmission will be triggered when the
142% transmitter node receives the SYNC packet.
143warplab_sendCmd(udp_Tx, TX_START, packetNum);
144
145% Prime receiver state machine in receiver node. Receiver will be waiting
146% for the SYNC packet. Capture will be triggered when the receiver
147% node receives the SYNC packet.
148warplab_sendCmd(udp_RxA, RX_START, packetNum);
149
150% Send the SYNC packet
151warplab_sendSync(udp_Sync);
152
153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154% 3. Leave continuous transmitter on for n seconds and then stop continuous
155% transmission and disable transmitter radio
156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157% Leave continuous transmitter on for nsec seconds
158nsec = 5;
159pause(nsec);
160
161% Stop transmission
162warplab_sendCmd(udp_Tx, TX_STOP, packetNum); % Resets the output and read
163% address of the transmitter buffer without disabling the transmitter radio.
164
165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166% 4. Read the received samples from the Warp board
167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168% In continuous transmitter mode the receiver stores CaptOffset samples of
169% noise and the first TxLength samples transmitted.
170
171% Read back the received samples from radio 2
172[RawRxData_2] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset);
173% Read back the received samples from radio 3
174[RawRxData_3] = warplab_readSMRO(udp_RxA, RADIO3_RXDATA, TxLength+CaptOffset);
175% Process the received samples to obtain meaningful data
176[RxData_2,RxOTR_2] = warplab_processRawRxData(RawRxData_2);
177[RxData_3,RxOTR_3] = warplab_processRawRxData(RawRxData_3);
178% Read stored RSSI data from radio 2
179[RawRSSIData_2] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
180% Read stored RSSI data from radio 3
181[RawRSSIData_3] = warplab_readSMRO(udp_RxA, RADIO3_RSSIDATA, (TxLength+CaptOffset)/8);
182% Procecss Raw RSSI data to obtain meningful RSSI values
183[RxRSSI_2] = warplab_processRawRSSIData(RawRSSIData_2);
184[RxRSSI_3] = warplab_processRawRSSIData(RawRSSIData_3);
185
186%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187% 5. Reset and disable the boards
188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189% Reset the receiver
190warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
191
192% Disable the receiver radio 2 radio 3
193warplab_sendCmd(udp_RxA, [RADIO2_RXDIS RADIO3_RXDIS], packetNum);
194
195% Disable the transmitter radio 2 and radio 3
196warplab_sendCmd(udp_Tx, [RADIO2_TXDIS RADIO3_TXDIS], packetNum);
197
198% Close sockets
199pnet('closeall');
200
201%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202% 6. Plot the transmitted and received data
203%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
204figure;
205subplot(4,2,1);
206plot(real(TxData_2));
207title('Tx Radio 2 I');
208xlabel('n (samples)'); ylabel('Amplitude');
209axis([0 2^14 -1 1]); % Set axis ranges.
210subplot(4,2,2);
211plot(imag(TxData_2));
212title('Tx Radio 2 Q');
213xlabel('n (samples)'); ylabel('Amplitude');
214axis([0 2^14 -1 1]); % Set axis ranges.
215subplot(4,2,3);
216plot(real(TxData_3));
217title('Tx Radio 3 I');
218xlabel('n (samples)'); ylabel('Amplitude');
219axis([0 2^14 -1 1]); % Set axis ranges.
220subplot(4,2,4);
221plot(imag(TxData_3));
222title('Tx Radio 3 Q');
223xlabel('n (samples)'); ylabel('Amplitude');
224axis([0 2^14 -1 1]); % Set axis ranges.
225subplot(4,2,5);
226plot(real(RxData_2));
227title('Rx Radio 2 I');
228xlabel('n (samples)'); ylabel('Amplitude');
229axis([0 2^14 -1 1]); % Set axis ranges.
230subplot(4,2,6);
231plot(imag(RxData_2));
232title('Rx Radio 2 Q');
233xlabel('n (samples)'); ylabel('Amplitude');
234axis([0 2^14 -1 1]); % Set axis ranges.
235subplot(4,2,7);
236plot(real(RxData_3));
237title('Rx Radio 3 I');
238xlabel('n (samples)'); ylabel('Amplitude');
239axis([0 2^14 -1 1]); % Set axis ranges.
240subplot(4,2,8);
241plot(imag(RxData_3));
242title('Rx Radio 3 Q');
243xlabel('n (samples)'); ylabel('Amplitude');
244axis([0 2^14 -1 1]); % Set axis ranges.
245
246%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247% Code to avoid conflict between users, only needed for the workshop
248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249pnet('closeall');
250!del c:\boards_lock.txt
251catch,
252% Close sockets
253pnet('closeall');
254!del c:\boards_lock.txt
255lasterr
256end
Note: See TracBrowser for help on using the browser.