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

Revision 839, 9.8 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% Two-Way transmission and reception of 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% Use Warplab for two-way communication between two nodes. First node A
8% will transmit to node B and then node B will transmit to node A.
9
10% The specific steps implemented in this script are the following
11
12% 0. Initializaton and definition of parameters
13% 1. Generate the vector of samples that node A will transmit to node B and
14% the vector of samples that node B will transmit to node A, then download
15% the samples to the Warp boards (Sample Frequency is 40MHz)
16% 2. Prepare boards for transmission and reception from node A to node B
17% and send trigger to start transmission and reception (trigger is the SYNC
18% packet)
19% 3. Disable the radios
20% 4. Prepare boards for transmission and reception from node B to node A
21% and send trigger to start transmission and reception (trigger is the SYNC
22% packet)
23% 5. Disable the radios
24% 6. Read the received samples from the Warp boards
25% 7. Reset the boards and close sockets
26% 8. Plot the transmitted and received data
27
28
29%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30% 0. Initializaton and definition of parameters
31%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32%Load some global definitions (packet types, etc.)
33warplab_defines
34
35% Create Socket handles and intialize nodes
36[socketHandles, packetNum] = warplab_initialize;
37
38%Separate the socket handles for easier access
39% The first socket handle is always the magic SYNC
40% The rest can be arranged in any combination of Tx and Rx
41udp_Sync = socketHandles(1);
42udp_nodeA = socketHandles(2);
43udp_nodeB = socketHandles(3);
44
45% Define the warplab options (parameters)
46CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14]
47TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset]
48TransMode = 0; %Transmission mode; in [0:1]
49               % 0: Single Transmission
50               % 1: Continuous Transmission. Tx board will continue
51               % transmitting the vector of samples until the user manually
52               % disables the transmitter.
53CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14]
54TxGainBB = 3; %Tx Baseband Gain in [0:3]
55TxGainRF = 40; %Tx RF Gain in [0:63]
56RxGainBB = 15; %Rx Baseband Gain in [0:31]
57RxGainRF = 1; %Rx RF Gain in [1:3]
58
59% Define the options vector; the order of options is set by the FPGA's code
60% (C code)
61optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)];
62% Send options vector to the nodes
63warplab_setOptions(socketHandles,optionsVector);
64
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66% 1. Generate the vector of samples that node A will transmit to node B and
67% the vector of samples that node B will transmit to node A, then download
68% the samples to the Warp boards (Sample Frequency is 40MHz)
69%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70% Create time vector.
71t = 0:(1/40e6):TxLength/40e6 - 1/40e6;
72
73% Create a signal to transmit from node A to node B
74TxDataAB = exp(t*j*2*pi*1e6); %Signal must be a row vector. The signal can
75% be real or complex, the only constraint is that the amplitude of the real
76% part must be in [-1:1] and the amplitude of the imaginary part must be
77% in [-1:1]
78
79% Download the samples to be transmitted
80warplab_writeSMWO(udp_nodeA, TxDataAB, RADIO2_TXDATA); % Download samples to node A
81
82% Create a signal to transmit from node B to node A
83TxDataBA = linspace(0,1,TxLength).*exp(t*j*2*pi*5e6);
84% Signal must be a row vector. The signal can be real or complex,
85% the only constraint is that the amplitude of the real part must be in
86% [-1:1] and the amplitude of the imaginary part must be in [-1:1]
87
88warplab_writeSMWO(udp_nodeB, TxDataBA, RADIO2_TXDATA); % Download samples to node B
89
90%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91% 2. Prepare boards for transmission and reception from node A to node B
92% and send trigger to start transmission and reception (trigger is the SYNC
93% packet)
94%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95% Enable transmitter radio path in node A
96warplab_sendCmd(udp_nodeA, RADIO2_TXEN, packetNum);
97
98% Enable receiver radio path in node B
99warplab_sendCmd(udp_nodeB, RADIO2_RXEN, packetNum);
100
101% Prime transmitter state machine in node A. Node A will be waiting for
102% the SYNC packet. Transmission will be triggered when node A receives
103% the SYNC packet.
104warplab_sendCmd(udp_nodeA, TX_START, packetNum);
105
106% Prime receiver state machine in node B. Node B will be waiting for
107% the SYNC packet. Capture will be triggered when node B receives
108% the SYNC packet.
109warplab_sendCmd(udp_nodeB, RX_START, packetNum);
110
111% Send the SYNC packet
112warplab_sendSync(udp_Sync)
113
114%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115% 3. Disable the radios
116%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117% Disable the receiver
118warplab_sendCmd(udp_nodeB, RADIO2_RXDIS, packetNum);
119
120% Disable the transmitter
121warplab_sendCmd(udp_nodeA, RADIO2_TXDIS, packetNum);
122
123%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124% 4. Prepare boards for transmission and reception from node B to node A
125% and send trigger to start transmission and reception (trigger is the SYNC
126% packet)
127%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128% Enable transmitter radio path in node B
129warplab_sendCmd(udp_nodeB, RADIO2_TXEN, packetNum);
130
131% Enable receiver radio path in node A
132warplab_sendCmd(udp_nodeA, RADIO2_RXEN, packetNum);
133
134% Prime transmitter state machine in node B. Node B will be waiting for
135% the SYNC packet. Transmission will be triggered when node B receives
136% the SYNC packet.
137warplab_sendCmd(udp_nodeB, TX_START, packetNum);
138
139% Prime receiver state machine in node A. Node A will be waiting for
140% the SYNC packet. Capture will be triggered when node A receives
141% the SYNC packet.
142warplab_sendCmd(udp_nodeA, RX_START, packetNum);
143
144% Send the SYNC packet
145warplab_sendSync(udp_Sync)
146
147%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
148% 5. Disable the radios
149%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150% Disable the receiver
151warplab_sendCmd(udp_nodeA, RADIO2_RXDIS, packetNum);
152
153% Disable the transmitter
154warplab_sendCmd(udp_nodeB, RADIO2_TXDIS, packetNum);
155
156%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
157% 6. Read the received samples from the Warp boards
158%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159% Read back the received samples sent from A to B
160[RawRxDataAB] = warplab_readSMRO(udp_nodeB, RADIO2_RXDATA, TxLength+CaptOffset);
161% Process the received samples to obtain meaningful data
162[RxDataAB,RxOTRAB] = warplab_processRawRxData(RawRxDataAB);
163% Read stored RSSI data corresponding to A to B transmission
164[RawRSSIDataAB] = warplab_readSMRO(udp_nodeB, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
165% Procecss Raw RSSI data to obtain meningful RSSI values
166[RxRSSIAB] = warplab_processRawRSSIData(RawRSSIDataAB);
167
168% Read back the received samples sent from B to A
169[RawRxDataBA] = warplab_readSMRO(udp_nodeA, RADIO2_RXDATA, TxLength+CaptOffset);
170% Process the received samples to obtain meaningful data
171[RxDataBA,RxOTRBA] = warplab_processRawRxData(RawRxDataBA);
172% Read stored RSSI data corresponding to B to A transmission
173[RawRSSIDataBA] = warplab_readSMRO(udp_nodeA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
174% Procecss Raw RSSI data to obtain meningful RSSI values
175[RxRSSIBA] = warplab_processRawRSSIData(RawRSSIDataBA);
176
177%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178% 7. Reset the boards and close sockets
179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180% Reset node A
181warplab_sendCmd(udp_nodeA, RX_DONEREADING, packetNum);
182
183% Reset node B
184warplab_sendCmd(udp_nodeB, RX_DONEREADING, packetNum);
185
186% Close sockets
187pnet('closeall');
188
189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190% 5. Plot the transmitted and received data
191%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192% Plot data from A to B transmissio
193figure;
194subplot(2,2,1);
195plot(real(TxDataAB));
196title('Tx I A to B');
197xlabel('n (samples)'); ylabel('Amplitude');
198axis([0 2^14 -1 1]); % Set axis ranges.
199subplot(2,2,2);
200plot(imag(TxDataAB));
201title('Tx Q A to B');
202xlabel('n (samples)'); ylabel('Amplitude');
203axis([0 2^14 -1 1]); % Set axis ranges.
204subplot(2,2,3);
205plot(real(RxDataAB));
206title('Rx I A to B');
207xlabel('n (samples)'); ylabel('Amplitude');
208axis([0 2^14 -1 1]); % Set axis ranges.
209subplot(2,2,4);
210plot(imag(RxDataAB));
211title('Rx Q A to B');
212xlabel('n (samples)'); ylabel('Amplitude');
213axis([0 2^14 -1 1]); % Set axis ranges.
214
215% Plot data from B to A transmission
216figure;
217subplot(2,2,1);
218plot(real(TxDataBA));
219title('Tx I B to A');
220xlabel('n (samples)'); ylabel('Amplitude');
221axis([0 2^14 -1 1]); % Set axis ranges.
222subplot(2,2,2);
223plot(imag(TxDataBA));
224title('Tx Q B to A');
225xlabel('n (samples)'); ylabel('Amplitude');
226axis([0 2^14 -1 1]); % Set axis ranges.
227subplot(2,2,3);
228plot(real(RxDataBA));
229title('Rx I B to A');
230xlabel('n (samples)'); ylabel('Amplitude');
231axis([0 2^14 -1 1]); % Set axis ranges.
232subplot(2,2,4);
233plot(imag(RxDataBA));
234title('Rx Q B to A');
235xlabel('n (samples)'); ylabel('Amplitude');
236axis([0 2^14 -1 1]); % Set axis ranges.
Note: See TracBrowser for help on using the browser.