root/ResearchApps/PHY/WARPLAB/WARPLab_SISO_MIMO2x2/M_Code/warplab_siso_example_ChannelEstim.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% 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: 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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23% 0. Transmit a narrowband signal using warplab
24%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25% Follow the steps for transmission and reception of data using Warplab.
26% These are the steps in the matlab script warplab_example_TxRx.m
27
28% This example transmits the following narrowband signal
29% t = 0:(1/40e6):TxLength/40e6 - 1/40e6;
30% TxData = exp(t*j*2*pi*1e6);
31
32%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33% 0.0. Initializaton and definition of parameters
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%Load some global definitions (packet types, etc.)
36warplab_defines
37
38% Create Socket handles and intialize nodes
39[socketHandles, packetNum] = warplab_initialize;
40
41%Separate the socket handles for easier access
42% The first socket handle is always the magic SYNC
43% The rest can be arranged in any combination of Tx and Rx
44udp_Sync = socketHandles(1);
45udp_Tx = socketHandles(2);
46udp_RxA = socketHandles(3);
47
48% Define the warplab options (parameters)
49CaptOffset = 1000; %Number of noise samples per Rx capture. In [0:2^14]
50TxLength = 2^14-1000; %Length of transmission. In [0:2^14-CaptOffset]
51TransMode = 0; %Transmission mode. In [0:1]
52               % 0: Single Transmission
53               % 1: Continuous Transmission. Tx board will continue
54               % transmitting the vector of samples until the user manually
55               % disables the transmitter.
56CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14]
57TxGainBB = 3; %Tx Baseband Gain. In [0:3]
58TxGainRF = 40; %Tx RF Gain. In [0:63]
59RxGainBB = 15; %Rx Baseband Gain. In [0:31]
60RxGainRF = 1; %Rx RF Gain. In [1:3]
61
62% Define the options vector; the order of options is set by the FPGA's code
63% (C code)
64optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)];
65% Send options vector to the nodes
66warplab_setOptions(socketHandles,optionsVector);
67
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% 0.1. Generate a vector of samples to transmit and send the samples to the
70% Warp board (Sample Frequency is 40MHz)
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% Prepare some data to be transmitted
73t = 0:(1/40e6):TxLength/40e6 - 1/40e6; %Create time vector.
74TxData = exp(t*j*2*pi*1e6); % Create a signal to transmit. Signal must be a
75% row vector. The signal can be real or complex, the only constraint is
76% that the amplitude of the real part must be in [-1:1] and the amplitude
77% of the imaginary part must be in [-1:1]
78
79% Download the samples to be transmitted
80warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA);
81
82%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83% 0.2. Prepare boards for transmission and reception and send trigger to
84% start transmission and reception (trigger is the SYNC packet)
85%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86% Enable transmitter radio path in transmitter node
87warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum);
88
89% Enable receiver radio path in receiver node
90warplab_sendCmd(udp_RxA, RADIO2_RXEN, packetNum);
91
92% Prime transmitter state machine in transmitter node. Transmitter will be
93% waiting for the SYNC packet. Transmission will be triggered when the
94% transmitter node receives the SYNC packet.
95warplab_sendCmd(udp_Tx, TX_START, packetNum);
96
97% Prime receiver state machine in receiver node. Receiver will be waiting
98% for the SYNC packet. Capture will be triggered when the receiver
99% node receives the SYNC packet.
100warplab_sendCmd(udp_RxA, RX_START, packetNum);
101
102% Send the SYNC packet
103warplab_sendSync(udp_Sync);
104
105%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106% 0.3. Read the received smaples from the Warp board
107%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108% Read back the received samples
109[RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset);
110% Process the received samples to obtain meaningful data
111[RxData,RxOTR] = warplab_processRawRxData(RawRxData);
112% Read stored RSSI data
113[RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
114% Procecss Raw RSSI data to obtain meningful RSSI values
115[RxRSSI] = warplab_processRawRSSIData(RawRSSIData);
116
117%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
118% 0.4. Reset and disable the boards
119%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
120% Reset the receiver
121warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
122
123% Disable the receiver radio
124warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum);
125
126% Disable the transmitter radio
127warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum);
128
129% Close sockets
130pnet('closeall');
131
132%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
133% 0.5. Plot the transmitted and received data
134%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135figure;
136subplot(2,2,1);
137plot(real(TxData));
138title('Tx I');
139xlabel('n (samples)'); ylabel('Amplitude');
140axis([0 2^14 -1 1]); % Set axis ranges.
141subplot(2,2,2);
142plot(imag(TxData));
143title('Tx Q');
144xlabel('n (samples)'); ylabel('Amplitude');
145axis([0 2^14 -1 1]); % Set axis ranges.
146subplot(2,2,3);
147plot(real(RxData));
148title('Rx I');
149xlabel('n (samples)'); ylabel('Amplitude');
150axis([0 2^14 -1 1]); % Set axis ranges.
151subplot(2,2,4);
152plot(imag(RxData));
153title('Rx Q');
154xlabel('n (samples)'); ylabel('Amplitude');
155axis([0 2^14 -1 1]); % Set axis ranges.
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% Compute the magnitude per sample of the transmitted and received
171% data
172mag_TxData = abs(TxData);
173mag_RxData = abs(RxData);
174
175% Compute the phase per sample of the transmitted and received data
176phase_TxData = angle(TxData);
177phase_TxData_unw = unwrap(phase_TxData);
178phase_TxData = phase_TxData *180/pi; %Convert to degrees
179phase_TxData_unw = phase_TxData_unw *180/pi; %Convert to degrees
180phase_RxData = angle(RxData);
181phase_RxData_unw = unwrap(phase_RxData);
182phase_RxData = phase_RxData *180/pi; %Convert to degrees
183phase_RxData_unw = phase_RxData_unw *180/pi; %Convert to degrees
184
185% Plot magnitude and phase of transmitted and received samples
186figure;
187subplot(2,3,1);
188plot(mag_TxData);
189title('Tx Magnitude');
190xlabel('n (samples)'); ylabel('Amplitude');
191subplot(2,3,2);
192plot(phase_TxData);
193title('Tx Phase');
194xlabel('n (samples)'); ylabel('Degrees');
195subplot(2,3,3);
196plot(phase_TxData_unw);
197title('Tx Phase unwrapped');
198xlabel('n (samples)'); ylabel('Degrees');
199subplot(2,3,4);
200plot(mag_RxData);
201title('Rx Magnitude');
202xlabel('n (samples)'); ylabel('Amplitude');
203subplot(2,3,5);
204plot(phase_RxData);
205title('Rx Phase');
206xlabel('n (samples)'); ylabel('Degrees');
207subplot(2,3,6);
208plot(phase_RxData_unw);
209title('Rx Phase unwrapped');
210xlabel('n (samples)'); ylabel('Degrees');
211
212
213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
214% 3. Compute the channel amplitude and channel phase per sample
215%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216% Compute the channel amplitude
217channel_amplitude = mag_RxData./mag_TxData;
218
219% Compute the channel phase
220channel_phase = phase_RxData_unw - phase_TxData_unw;
221
222% Plot channel amplitude and phase
223figure
224subplot(2,1,1)
225plot(channel_amplitude)
226title('Channel Amplitude per sample');
227xlabel('n (samples)'); ylabel('Amplitude');
228subplot(2,1,2)
229plot(channel_phase)
230title('Channel Phase per sample');
231xlabel('n (samples)'); ylabel('Degrees');
Note: See TracBrowser for help on using the browser.