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

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