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

Revision 839, 8.3 kB (checked in by MelissaDuarte, 6 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%-------------------------------------------------------------------------%
83
84TransMode = 0; %Transmission mode; in [0:1]
85               % 0: Single Transmission
86               % 1: Continuous Transmission. Tx board will continue
87               % transmitting the vector of samples until the user manually
88               % disables the transmitter.
89
90% Define the options vector; the order of options is set by the FPGA's code
91% (C code)
92optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)];
93% Send options vector to the nodes
94warplab_setOptions(socketHandles,optionsVector);
95
96%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97% 1. Generate a vector of samples to transmit and send the samples to the
98% Warp board (Sample Frequency is 40MHz)
99%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100% Prepare some data to be transmitted
101t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector.
102
103%-------------------------------------------------------------------------%
104% USER CODE HERE
105
106% Create a signal to transmit (a vector of samples to transmit).
107% The signal must be a row vector. The Signal is a function of the time
108% vector 't'. The signal can be real or complex, the only constraint is
109% that the amplitude of the real part must be in [-1:1] and the amplitude
110% of the imaginary part must be in [-1:1]. Store the signal to transmit in
111% a variable called TxData (TxData = your signal)
112
113%-------------------------------------------------------------------------%
114
115% Download the samples to be transmitted
116warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA);
117
118%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119% 2. Prepare boards for transmission and reception and send trigger to
120% start transmission and reception (trigger is the SYNC packet)
121%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122% Enable transmitter radio path in transmitter node
123warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum);
124
125% Enable receiver radio path in receiver node
126warplab_sendCmd(udp_RxA, RADIO2_RXEN, packetNum);
127
128% Prime transmitter state machine in transmitter node. Transmitter will be
129% waiting for the SYNC packet. Transmission will be triggered when the
130% transmitter node receives the SYNC packet.
131warplab_sendCmd(udp_Tx, TX_START, packetNum);
132
133% Prime receiver state machine in receiver node. Receiver will be waiting
134% for the SYNC packet. Capture will be triggered when the receiver
135% node receives the SYNC packet.
136warplab_sendCmd(udp_RxA, RX_START, packetNum);
137
138% Send the SYNC packet
139warplab_sendSync(udp_Sync);
140
141%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142% 3. Read the received samples from the Warp board
143%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
144% Read back the received samples
145[RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset);
146% Process the received samples to obtain meaningful data
147[RxData,RxOTR] = warplab_processRawRxData(RawRxData);
148% Read stored RSSI data
149[RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
150% Procecss Raw RSSI data to obtain meningful RSSI values
151[RxRSSI] = warplab_processRawRSSIData(RawRSSIData);
152
153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154% 4. Reset and disable the boards
155%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
156% Reset the receiver
157warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
158
159% Disable the receiver radio
160warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum);
161
162% Disable the transmitter radio
163warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum);
164
165% Close sockets
166pnet('closeall');
167
168%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169% 5. Plot the transmitted and received data
170%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
171figure;
172subplot(2,2,1);
173plot(real(TxData));
174title('Tx I');
175xlabel('n (samples)'); ylabel('Amplitude');
176axis([0 2^14 -1 1]); % Set axis ranges.
177subplot(2,2,2);
178plot(imag(TxData));
179title('Tx Q');
180xlabel('n (samples)'); ylabel('Amplitude');
181axis([0 2^14 -1 1]); % Set axis ranges.
182subplot(2,2,3);
183plot(real(RxData));
184title('Rx I');
185xlabel('n (samples)'); ylabel('Amplitude');
186axis([0 2^14 -1 1]); % Set axis ranges.
187subplot(2,2,4);
188plot(imag(RxData));
189title('Rx Q');
190xlabel('n (samples)'); ylabel('Amplitude');
191axis([0 2^14 -1 1]); % Set axis ranges.
192
193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194% Code to avoid conflict between users, only needed for the workshop
195%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
196pnet('closeall');
197!del c:\boards_lock.txt
198catch,
199% Close sockets
200pnet('closeall');
201!del c:\boards_lock.txt
202lasterr
203end
Note: See TracBrowser for help on using the browser.