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

Revision 839, 11.4 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% (SISO configuration)
4%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5% To run this code the boards must be programmed with the
6% warplab_siso_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). 
13% 2. Prepare boards for transmission and reception and send trigger to
14% start transmission and reception (trigger is the SYNC packet)
15% 3. Leave continuous transmitter on for n seconds and then stop continuous
16% transmission.
17% 4. Read the received samples from the Warp board.
18% 5. Reset and disable the boards.
19% 6. Plot the first 2^14 received samples.
20
21% You can observe the transmitted signal on the spectrum analyzer in the
22% lab
23
24% In this lab exercise you will write a matlab script that implements the
25% seven steps above. Part of the code is provided, some part of the code you
26% will write. Read the code below and fill in with your code wherever you
27% are asked to do so.
28
29% NOTE: To avoid conflict with other groups using the boards, please test
30% the code you write in this script in any of the following three ways:
31%
32% Option 1. Run this script from matlab's Command Window by entering the
33% name of the script (enter warplab_example_TxRx_WorkshopExercise in
34% matlab's Command Window).
35% Option 2. In the menu bar go to Debug and select Run. If there
36% are errors in the code, error messages will appear in the Command Window.
37% Option 3. Press F5. If the are errors in the code, error messages will
38% appear in the Command Window.
39%
40% DO NOT USE the Evaluate selection option and DO NOT run the script by
41% sections. To test any change, always run the whole script by following
42% any of the three options above.
43
44try,
45%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46% Code to avoid conflict between users, only needed for the workshop, go to
47% step 0 below to start the initialization and definition of parameters
48%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49fid = fopen('c:\boards_lock.txt');
50
51if(fid > -1)
52    fclose('all');
53        errordlg('Boards already in use - Please try again!');
54        return;
55end
56
57!echo > c:\boards_lock.txt
58
59%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60% 0. Initializaton and definition of parameters
61%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62%Load some global definitions (packet types, etc.)
63warplab_defines
64
65% Create Socket handles and intialize nodes
66[socketHandles, packetNum] = warplab_initialize;
67
68%Separate the socket handles for easier access
69% The first socket handle is always the magic SYNC
70% The rest can be arranged in any combination of Tx and Rx
71udp_Sync = socketHandles(1);
72udp_Tx = socketHandles(2);
73udp_RxA = socketHandles(3);
74
75%-------------------------------------------------------------------------%
76% USER CODE HERE
77
78% Create the following variables and assign them valid values:
79
80% CaptOffset: Number of noise samples per Rx capture. In [0:2^14]
81% TxLength : Length of transmission. In [0:2^14-CaptOffset]         
82% CarrierChannel : Channel in the 2.4 GHz band. In [1:14]
83% TransMode : Transmission mode; in [0:1]
84                % 0: Single Transmission
85                % 1: Continuous Transmission. Tx board will continue
86                % transmitting the vector of samples until the user manually
87                % disables the transmitter.
88            % For this exercise set TransMode = 1;
89% TxGainBB : Tx Baseband Gain. In [0:3]
90% TxGainRF : Tx RF Gain. In [0:63]
91% RxGainBB : Rx Baseband Gain. In [0:31]
92% RxGainRF : Rx RF Gain. In [1:3]
93
94% Note: Set TxGainBB, TxGainRF, RxGainBB, and RxGainRF to the same values
95% you used in the warplab_siso_GUI.
96
97%-------------------------------------------------------------------------%
98
99% Define the options vector; the order of options is set by the FPGA's code
100% (C code)
101optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)];
102% Send options vector to the nodes
103warplab_setOptions(socketHandles,optionsVector);
104%-------------------------------------------------------------------------%
105
106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107% 1. Generate a vector of samples to transmit and send the samples to the
108% Warp board (Sample Frequency is 40MHz). 
109%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110% Prepare some data to be transmitted
111t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector.
112
113%-------------------------------------------------------------------------%
114% USER CODE HERE
115
116% Create a signal to transmit (a vector of samples to transmit).
117% The signal must be a row vector. The Signal is a function of the time
118% vector 't'. The signal can be real or complex, the only constraint is
119% that the amplitude of the real part must be in [-1:1] and the amplitude
120% of the imaginary part must be in [-1:1]. Store the signal to transmit in
121% a variable called TxData (TxData = your signal)
122
123% You will be able to observe the transmitted signal on the spectrum
124% analyzer in the lab.
125
126% As a suggestion, you can transmit the sum of two sinusoids separated by
127% 5MHz. You can use the following lines of code to generate the signal
128
129% f1 = 1e6;
130% f2 = 6e6;
131% TxData = exp(t*j*2*pi*f1)+exp(t*j*2*pi*f2);
132% scale = 1 / max( [ max(real(TxData)) , max(imag(TxData)) ] );
133% TxData = scale*TxData;
134
135% TxData is scaled so that amplitude of the real and  imaginary part is
136% in [-1:1]. We want the signal to span [-1,1] range so it uses the full
137% range of the DAC at the tranmitter.
138
139%-------------------------------------------------------------------------%
140
141% Download the samples to be transmitted
142warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA);
143
144%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145% 2. Prepare boards for transmission and reception and send trigger to
146% start transmission and reception (trigger is the SYNC packet)
147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148% Enable transmitter radio path in transmitter node
149warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum);
150
151% Enable receiver radio path in receiver node
152warplab_sendCmd(udp_RxA, RADIO2_RXEN, packetNum);
153
154% Prime transmitter state machine in transmitter node. Transmitter will be
155% waiting for the SYNC packet. Transmission will be triggered when the
156% transmitter node receives the SYNC packet.
157warplab_sendCmd(udp_Tx, TX_START, packetNum);
158
159% Prime receiver state machine in receiver node. Receiver will be waiting
160% for the SYNC packet. Capture will be triggered when the receiver
161% node receives the SYNC packet.
162warplab_sendCmd(udp_RxA, RX_START, packetNum);
163
164% Send the SYNC packet
165warplab_sendSync(udp_Sync);
166
167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168% 3. Leave continuous transmitter on for n seconds and then stop continuous
169% transmission
170%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171
172%-------------------------------------------------------------------------%
173% USER CODE HERE
174
175% Use matlab's pause command to pause execution for n seconds. Because you
176% are sharing the boards with other users, please pause for only less than 5
177% seconds: n < 5
178
179% To learn more about the pause function enter 'help pause' in the Matlab
180% command window.
181
182% USE pause(n) (with an argument). If you just use pause it will pause
183% until you press a key, since you are sharing the boards with other users
184% it is better to use pause(n) to avoid one user retaining the boards for
185% too long.
186
187%-------------------------------------------------------------------------%
188
189%-------------------------------------------------------------------------%
190% USER CODE HERE
191
192% Stop transmission by sending the TX_STOP command using the
193% 'warplab_sendCmd' function. This function has been used in all the
194% previous exercises.
195
196% Hints:
197
198% 1. The first argument of the 'warplab_sendCmd' function identifies the
199% node to which the command will be sent. The TX_STOP command must be sent
200% to the transmitter node so use udp_Tx as the first argument.
201
202% 2. The second argument of the 'warplab_sendCmd' function identifies the
203% instruction or command to be sent. In this case, the command to send is
204% the TX_STOP command defined in 'warplab_defines'.
205
206% 3. The third argument of the 'warplab_sendCmd' command is a field that is
207% not used at the moment, it may be used in future versions of WARPLab to
208% keep track of packets. Use 'packetNum' as the third argument of the
209% 'warplab_sendCmd' command.
210
211%-------------------------------------------------------------------------%
212
213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214% 4. Read the received samples from the Warp board
215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216% In continuous transmitter mode the receiver stores CaptOffset samples of
217% noise and the first TxLength samples transmitted.
218
219% Read back the received samples
220[RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset);
221% Process the received samples to obtain meaningful data
222[RxData,RxOTR] = warplab_processRawRxData(RawRxData);
223% Read stored RSSI data
224[RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
225% Procecss Raw RSSI data to obtain meningful RSSI values
226[RxRSSI] = warplab_processRawRSSIData(RawRSSIData);
227
228%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
229% 5. Reset and disable the boards
230%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231% Reset the receiver
232warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
233
234% Disable the receiver radio
235warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum);
236
237% Disable the transmitter radio
238warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum);
239
240% Close sockets
241pnet('closeall');
242
243%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244% 6. Plot the transmitted and received data
245%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246figure;
247subplot(2,2,1);
248plot(real(TxData));
249title('Tx I');
250xlabel('n (samples)'); ylabel('Amplitude');
251axis([0 2^14 -1 1]); % Set axis ranges.
252subplot(2,2,2);
253plot(imag(TxData));
254title('Tx Q');
255xlabel('n (samples)'); ylabel('Amplitude');
256axis([0 2^14 -1 1]); % Set axis ranges.
257subplot(2,2,3);
258plot(real(RxData));
259title('Rx I first 2^14 received samples');
260xlabel('n (samples)'); ylabel('Amplitude');
261axis([0 2^14 -1 1]); % Set axis ranges.
262subplot(2,2,4);
263plot(imag(RxData));
264title('Rx Q first 2^14 received samples');
265xlabel('n (samples)'); ylabel('Amplitude');
266axis([0 2^14 -1 1]); % Set axis ranges.
267
268%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269% Code to avoid conflict between users, only needed for the workshop
270%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271pnet('closeall');
272!del c:\boards_lock.txt
273catch,
274% Close sockets
275pnet('closeall');
276!del c:\boards_lock.txt
277lasterr
278end
Note: See TracBrowser for help on using the browser.