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

Revision 839, 8.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 (SISO Configuration)
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4% To run this code the boards must be programmed with the
5% warplab_siso_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%-------------------------------------------------------------------------%
70% USER CODE HERE
71
72% Create the following variables and assign them valid values:
73
74% CaptOffset: Number of noise samples per Rx capture. In [0:2^14]
75% TxLength : Length of transmission. In [0:2^14-CaptOffset]
76% CarrierChannel : Channel in the 2.4 GHz band. In [1:14]
77% TxGainBB : Tx Baseband Gain. In [0:3]
78% TxGainRF : Tx RF Gain. In [0:63]
79% RxGainBB : Rx Baseband Gain. In [0:31]
80% RxGainRF : Rx RF Gain. In [1:3]
81
82% Define the warplab options (parameters)
83CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14]
84TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset]
85CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14]
86TxGainBB = 3; %Tx Baseband Gain in [0:3]
87TxGainRF = 40; %Tx RF Gain in [0:63]
88RxGainBB = 15; %Rx Baseband Gain in [0:31]
89RxGainRF = 1; %Rx RF Gain in [1:3]
90%-------------------------------------------------------------------------%
91
92TransMode = 0; %Transmission mode; in [0:1]
93               % 0: Single Transmission
94               % 1: Continuous Transmission. Tx board will continue
95               % transmitting the vector of samples until the user manually
96               % disables the transmitter.
97
98% Define the options vector; the order of options is set by the FPGA's code
99% (C code)
100optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)];
101% Send options vector to the nodes
102warplab_setOptions(socketHandles,optionsVector);
103
104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105% 1. Generate a vector of samples to transmit and send the samples to the
106% Warp board (Sample Frequency is 40MHz)
107%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108% Prepare some data to be transmitted
109t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector.
110
111%-------------------------------------------------------------------------%
112% USER CODE HERE
113
114% Create a signal to transmit (a vector of samples to transmit).
115% The signal must be a row vector. The Signal is a function of the time
116% vector 't'. The signal can be real or complex, the only constraint is
117% that the amplitude of the real part must be in [-1:1] and the amplitude
118% of the imaginary part must be in [-1:1]. Store the signal to transmit in
119% a variable called TxData (TxData = your signal)
120
121TxData = exp(t*j*2*pi*1e6); % Create a signal to transmit. Signal must be a
122% row vector. The signal can be real or complex, the only constraint is
123% that the amplitude of the real part must be in [-1:1] and the amplitude
124% of the imaginary part must be in [-1:1]
125%-------------------------------------------------------------------------%
126
127% Download the samples to be transmitted
128warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA);
129
130%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131% 2. Prepare boards for transmission and reception and send trigger to
132% start transmission and reception (trigger is the SYNC packet)
133%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134% Enable transmitter radio path in transmitter node
135warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum);
136
137% Enable receiver radio path in receiver node
138warplab_sendCmd(udp_RxA, RADIO2_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. Read the received samples from the Warp board
155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156% Read back the received samples
157[RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset);
158% Process the received samples to obtain meaningful data
159[RxData,RxOTR] = warplab_processRawRxData(RawRxData);
160% Read stored RSSI data
161[RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
162% Procecss Raw RSSI data to obtain meningful RSSI values
163[RxRSSI] = warplab_processRawRSSIData(RawRSSIData);
164
165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166% 4. Reset and disable the boards
167%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
168% Reset the receiver
169warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
170
171% Disable the receiver radio
172warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum);
173
174% Disable the transmitter radio
175warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum);
176
177% Close sockets
178pnet('closeall');
179
180%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181% 5. Plot the transmitted and received data
182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183figure;
184subplot(2,2,1);
185plot(real(TxData));
186title('Tx I');
187xlabel('n (samples)'); ylabel('Amplitude');
188axis([0 2^14 -1 1]); % Set axis ranges.
189subplot(2,2,2);
190plot(imag(TxData));
191title('Tx Q');
192xlabel('n (samples)'); ylabel('Amplitude');
193axis([0 2^14 -1 1]); % Set axis ranges.
194subplot(2,2,3);
195plot(real(RxData));
196title('Rx I');
197xlabel('n (samples)'); ylabel('Amplitude');
198axis([0 2^14 -1 1]); % Set axis ranges.
199subplot(2,2,4);
200plot(imag(RxData));
201title('Rx Q');
202xlabel('n (samples)'); ylabel('Amplitude');
203axis([0 2^14 -1 1]); % Set axis ranges.
204
205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206% Code to avoid conflict between users, only needed for the workshop
207%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208pnet('closeall');
209!del c:\boards_lock.txt
210catch,
211% Close sockets
212pnet('closeall');
213!del c:\boards_lock.txt
214lasterr
215end
Note: See TracBrowser for help on using the browser.