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

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