root/ResearchApps/PHY/WARPLAB/WARPLab_SISO_MIMO2x2/M_Code/warplab_siso_example_ChannelEstim_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% Using Warplab (SISO configuration) to Estimate the Amplitude and Phase of
3% a Narrowband Flat Fading Wireless Channel
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. Transmit a narrowband signal using Warplab
11% 1. Remove from the received vector the samples that do not correspond to
12% transmitted data.
13% 2. Compute the amplitude and the phase of the transmitted and received
14% sammples
15% 3. Compute the channel amplitude and channel phase per sample
16
17% NOTE 1: The amplitude and phase computed in this exercise correspond to the
18% amplitude and phase of the channel together with the amplitude and phase
19% of the hardware. In other words, the effect of the radios (like gains and
20% carrier frequency offset)is also part of the channel.
21
22% You will write a matlab script that implements the four steps above.
23% Part of the code is provided, some part of the code you will write. Read
24% the code below and fill in with your code wherever you are asked to do
25% so.
26
27% NOTE 2 : To avoid conflict with other groups using the boards, please
28% test the code you write in this script in any of the following three
29% ways:
30%
31% Option 1. Run this script from matlab's Command Window by entering the
32% name of the script (enter warplab_example_ChannelEstimation_WorkshopExercise
33% in 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 transmit a narrowband signal using Warplab
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. Transmit a narrowband signal using warplab
60%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61% Follow the steps for transmission and reception of data using Warplab.
62% These are the steps implemented in the previous lab exercise, the
63% following sections (0.0 to 0.5) guide you through the steps.
64
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66% 0.0. Initializaton and definition of parameters
67%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68%-------------------------------------------------------------------------%
69% USER CODE HERE
70
71% Follow the steps for Initializaton and definition of parameters.
72% You can copy the code corresponding to step 0 in the previous lab
73% exercise and then paste it here.
74
75% IMPORTANT NOTE: For this exercise set TransMode = 0;
76
77% Remember to set TxGainBB, TxGainRF, RxGainBB, and RxGainRF to the
78% same values you used in the warplab_siso_GUI.
79
80
81%-------------------------------------------------------------------------%
82
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84% 0.1. Generate a vector of samples to transmit and send the samples to the
85% Warp board (Sample Frequency is 40MHz)
86%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87
88%-------------------------------------------------------------------------%
89% USER CODE HERE
90
91% Follow the steps to Generate a vector of samples to transmit and send
92% the samples to the Warp board.
93% You can copy the code corresponding to step 1 in the previous lab
94% exercise and then paste it here.
95% You can use the following two lines of code to generate the narrowband
96% signal:
97% t = 0:(1/40e6):TxLength/40e6 - 1/40e6;
98% TxData = exp(t*j*2*pi*1e6);
99
100% For the rest of the code to work, make sure the transmit vector is
101% stored in a variable called 'TxData'.
102
103%-------------------------------------------------------------------------%
104
105%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106% 0.2. Prepare boards for transmission and reception and send trigger to
107% start transmission and reception (trigger is the SYNC packet)
108%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109%-------------------------------------------------------------------------%
110% USER CODE HERE
111% Follow the steps to prepare boards for transmission and reception and
112% send trigger to start transmission and reception.
113% You can copy the code corresponding to step 2 in the previous lab
114% exercise and then paste it here.
115
116%-------------------------------------------------------------------------%
117
118%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119% 0.3. Read the received smaples from the Warp board
120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121
122%-------------------------------------------------------------------------%
123% USER CODE HERE
124% Follow the steps to read the received samples from the Warp board.
125% You can copy the code corresponding to step 3 in the previous lab
126% exercise and then paste it here. There is no need to read the RSSI, but
127% you can do so.
128
129% For the rest of the code to work, make sure the received vector is
130% stored in a variable called 'RxData'.
131
132%-------------------------------------------------------------------------%
133
134%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135% 0.4. Reset and disable the boards
136%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137%-------------------------------------------------------------------------%
138% USER CODE HERE
139% Follow the steps to reset and disable the boards.
140% You can copy the code corresponding to step 4 in the previous lab
141% exercise and then paste it here.
142
143%-------------------------------------------------------------------------%
144
145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146% 0.5. Plot the transmitted and received data
147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148
149%-------------------------------------------------------------------------%
150% USER CODE HERE
151% If you are interested in looking at the received and transmitted data you
152% can copy the code corresponding to step 5 in the previous lab exercise
153% and paste it here
154
155%-------------------------------------------------------------------------%
156
157
158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159% 1. Remove from the received vector the samples that do not correspond to
160% transmitted data. In other words, remove from the received vector samples
161% 1 to CaptOffset. This step will remove samples that correspond to measured
162% noise and make the RxData vector the same length as the TxData vector
163%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
164RxData = RxData(CaptOffset+1:end);
165
166%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167% 2. Compute the amplitude and the phase of the transmitted and received
168% sammples
169%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170
171%-------------------------------------------------------------------------%
172% USER CODE HERE
173% Compute the magnitude per sample of the transmitted and received
174% data. Store the magnitude of the transmitted data in a variable named
175% 'mag_TxData'. Store the magnitude of the received data in a variable
176% named 'mag_RxData'.
177% Hint: You can use Matlab's 'abs' function
178
179%-------------------------------------------------------------------------%
180
181%-------------------------------------------------------------------------%
182% USER CODE HERE
183% Compute the phase per sample of the transmitted and received
184% data. Store the phase (in radians) of the transmitted data in a variable
185% named 'phase_TxData'. Store the phase (in radians) of the received data
186% in a variable named 'phase_RxData'.
187% Hint: You can use Matlab's 'angle' function
188
189%-------------------------------------------------------------------------%
190
191phase_TxData_unw = unwrap(phase_TxData);
192phase_TxData = phase_TxData *180/pi; %Convert to degrees
193phase_TxData_unw = phase_TxData_unw *180/pi; %Convert to degrees
194phase_RxData_unw = unwrap(phase_RxData);
195phase_RxData = phase_RxData *180/pi; %Convert to degrees
196phase_RxData_unw = phase_RxData_unw *180/pi; %Convert to degrees
197
198
199% Plot magnitude and phase of transmitted and received samples
200figure;
201subplot(2,3,1);
202plot(mag_TxData);
203title('Tx Magnitude');
204xlabel('n (samples)'); ylabel('Amplitude');
205subplot(2,3,2);
206plot(phase_TxData);
207title('Tx Phase');
208xlabel('n (samples)'); ylabel('Degrees');
209subplot(2,3,3);
210plot(phase_TxData_unw);
211title('Tx Phase unwrapped');
212xlabel('n (samples)'); ylabel('Degrees');
213subplot(2,3,4);
214plot(mag_RxData);
215title('Rx Magnitude');
216xlabel('n (samples)'); ylabel('Amplitude');
217subplot(2,3,5);
218plot(phase_RxData);
219title('Rx Phase');
220xlabel('n (samples)'); ylabel('Degrees');
221subplot(2,3,6);
222plot(phase_RxData_unw);
223title('Rx Phase unwrapped');
224xlabel('n (samples)'); ylabel('Degrees');
225
226
227%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
228% 3. Compute the channel amplitude and channel phase per sample
229%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
230
231%-------------------------------------------------------------------------%
232% USER CODE HERE
233% Compute the channel amplitude per sample. Store the result in a variable
234% named 'channel_amplitude'
235% Hint 1:
236% Channel amplitude = Magnitude of received samples / Magnitude of transmited samples
237% Hint 2:
238% You can use Matlab's './' function to implement division of vetors entry
239% by entry. To learn more about this function enter 'help ./' in the Matlab
240% command window
241
242%-------------------------------------------------------------------------%
243
244%-------------------------------------------------------------------------%
245% USER CODE HERE
246% Compute the channel phase per sample. Store the result in a variable
247% named 'channel_phase'
248% Hint:
249% Channel Phase = Phase of received samples - Phase of transmitted samples
250
251%-------------------------------------------------------------------------%
252
253% Plot channel amplitude and phase
254figure
255subplot(2,1,1)
256plot(channel_amplitude)
257title('Channel Amplitude per sample');
258xlabel('n (samples)'); ylabel('Amplitude');
259subplot(2,1,2)
260plot(channel_phase)
261title('Channel Phase per sample');
262xlabel('n (samples)'); ylabel('Degrees');
263
264%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265% Code to avoid conflict between users, only needed for the workshop
266%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267pnet('closeall');
268!del c:\boards_lock.txt
269catch,
270% Close sockets
271pnet('closeall');
272!del c:\boards_lock.txt
273lasterr
274end
Note: See TracBrowser for help on using the browser.