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

Revision 839, 8.1 kB (checked in by MelissaDuarte, 5 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 (2x2 MIMO configuration)
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4% To run this code the boards must be programmed with the
5% warplab_mimo_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%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19% 0. Initializaton and definition of parameters
20%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21%Load some global definitions (packet types, etc.)
22warplab_defines
23
24% Create Socket handles and intialize nodes
25[socketHandles, packetNum] = warplab_initialize;
26
27%Separate the socket handles for easier access
28% The first socket handle is always the magic SYNC
29% The rest can be arranged in any combination of Tx and Rx
30udp_Sync = socketHandles(1);
31udp_Tx = socketHandles(2);
32udp_RxA = socketHandles(3);
33
34% Define the warplab options (parameters)
35CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14]
36TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset]
37TransMode = 0; %Transmission mode; in [0:1]
38               % 0: Single Transmission
39               % 1: Continuous Transmission. Tx board will continue
40               % transmitting the vector of samples until the user manually
41               % disables the transmitter.
42CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14]
43Tx2GainBB = 3; %Tx Baseband Gain in [0:3]
44Tx2GainRF = 40; %Tx RF Gain in [0:63]
45Rx2GainBB = 15; %Rx Baseband Gain in [0:31]
46Rx2GainRF = 1; %Rx RF Gain in [1:3]
47Tx3GainBB = 3; %Tx Baseband Gain in [0:3]
48Tx3GainRF = 40; %Tx RF Gain in [0:63]
49Rx3GainBB = 15; %Rx Baseband Gain in [0:31]
50Rx3GainRF = 1; %Rx RF Gain in [1:3]
51TxSelect = 2; % Select transmitter radio [0:2] 0:Radio2, 1:Radio3, 2: Both
52RxSelect = 2; % Select transmitter radio [0:2] 0:Radio2, 1:Radio3, 2: Both
53
54% Define the options vector; the order of options is set by the FPGA's code
55% (C code)
56optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (Rx2GainBB + Rx2GainRF*2^16) (Tx2GainRF + Tx2GainBB*2^16) (Rx3GainBB + Rx3GainRF*2^16) (Tx3GainRF + Tx3GainBB*2^16) TxSelect RxSelect];
57% Send options vector to the nodes
58warplab_setOptions(socketHandles,optionsVector);
59
60%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61% 1. Generate a vector of samples to transmit and send the samples to the
62% Warp board (Sample Frequency is 40MHz)
63%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64% Prepare some data to be transmitted
65t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector
66
67% Create a signal to transmit from radio 2
68TxData_2 = exp(t*j*2*pi*1e6); %Signal must be a row vector. The signal can
69% be real or complex, the only constraint is that the amplitude of the real
70% part must be in [-1:1] and the amplitude of the imaginary part must be
71% in [-1:1]
72
73% Download the samples to be transmitted
74warplab_writeSMWO(udp_Tx, TxData_2, RADIO2_TXDATA); % Download samples to
75% radio 2 Tx Buffer
76
77% Create a signal to transmit from radio 3
78TxData_3 = linspace(0,1,TxLength).*exp(t*j*2*pi*5e6);
79% Signal must be a row vector. The signal can be real or complex,
80% the only constraint is that the amplitude of the real part must be in
81% [-1:1] and the amplitude of the imaginary part must be in [-1:1]
82
83warplab_writeSMWO(udp_Tx, TxData_3, RADIO3_TXDATA); % Download samples to
84% radio 3 Tx Buffer
85
86%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87% 2. Prepare boards for transmission and reception and send trigger to
88% start transmission and reception (trigger is the SYNC packet)
89%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90% Enable transmitter radio path in transmitter node (enable radio 2 and
91% radio 3 in transmitter node as transmitters)
92warplab_sendCmd(udp_Tx, [RADIO2_TXEN RADIO3_TXEN], packetNum);
93
94% Enable receiver radio path in receiver node (enable radio 2 and
95% radio 3 in receiver node as receivers)
96warplab_sendCmd(udp_RxA, [RADIO2_RXEN RADIO3_RXEN], packetNum);
97
98% Prime transmitter state machine in transmitter node. Transmitter will be
99% waiting for the SYNC packet. Transmission will be triggered when the
100% transmitter node receives the SYNC packet.
101warplab_sendCmd(udp_Tx, TX_START, packetNum);
102
103% Prime receiver state machine in receiver node. Receiver will be waiting
104% for the SYNC packet. Capture will be triggered when the receiver
105% node receives the SYNC packet.
106warplab_sendCmd(udp_RxA, RX_START, packetNum);
107
108% Send the SYNC packet
109warplab_sendSync(udp_Sync);
110
111%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112% 3. Read the received samples from the Warp board
113%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114% Read back the received samples from radio 2
115[RawRxData_2] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset);
116% Read back the received samples from radio 3
117[RawRxData_3] = warplab_readSMRO(udp_RxA, RADIO3_RXDATA, TxLength+CaptOffset);
118% Process the received samples to obtain meaningful data
119[RxData_2,RxOTR_2] = warplab_processRawRxData(RawRxData_2);
120[RxData_3,RxOTR_3] = warplab_processRawRxData(RawRxData_3);
121% Read stored RSSI data from radio 2
122[RawRSSIData_2] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
123% Read stored RSSI data from radio 3
124[RawRSSIData_3] = warplab_readSMRO(udp_RxA, RADIO3_RSSIDATA, (TxLength+CaptOffset)/8);
125% Procecss Raw RSSI data to obtain meningful RSSI values
126[RxRSSI_2] = warplab_processRawRSSIData(RawRSSIData_2);
127[RxRSSI_3] = warplab_processRawRSSIData(RawRSSIData_3);
128
129%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130% 4. Reset and disable the boards
131%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
132% Reset the receiver
133warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
134
135% Disable the receiver radio 2 radio 3
136warplab_sendCmd(udp_RxA, [RADIO2_RXDIS RADIO3_RXDIS], packetNum);
137
138% Disable the transmitter radio 2 and radio 3
139warplab_sendCmd(udp_Tx, [RADIO2_TXDIS RADIO3_TXDIS], packetNum);
140
141% Close sockets
142pnet('closeall');
143
144%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145% 5. Plot the transmitted and received data
146%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147figure;
148subplot(4,2,1);
149plot(real(TxData_2));
150title('Tx Radio 2 I');
151xlabel('n (samples)'); ylabel('Amplitude');
152axis([0 2^14 -1 1]); % Set axis ranges.
153subplot(4,2,2);
154plot(imag(TxData_2));
155title('Tx Radio 2 Q');
156xlabel('n (samples)'); ylabel('Amplitude');
157axis([0 2^14 -1 1]); % Set axis ranges.
158subplot(4,2,3);
159plot(real(TxData_3));
160title('Tx Radio 3 I');
161xlabel('n (samples)'); ylabel('Amplitude');
162axis([0 2^14 -1 1]); % Set axis ranges.
163subplot(4,2,4);
164plot(imag(TxData_3));
165title('Tx Radio 3 Q');
166xlabel('n (samples)'); ylabel('Amplitude');
167axis([0 2^14 -1 1]); % Set axis ranges.
168subplot(4,2,5);
169plot(real(RxData_2));
170title('Rx Radio 2 I');
171xlabel('n (samples)'); ylabel('Amplitude');
172axis([0 2^14 -1 1]); % Set axis ranges.
173subplot(4,2,6);
174plot(imag(RxData_2));
175title('Rx Radio 2 Q');
176xlabel('n (samples)'); ylabel('Amplitude');
177axis([0 2^14 -1 1]); % Set axis ranges.
178subplot(4,2,7);
179plot(real(RxData_3));
180title('Rx Radio 3 I');
181xlabel('n (samples)'); ylabel('Amplitude');
182axis([0 2^14 -1 1]); % Set axis ranges.
183subplot(4,2,8);
184plot(imag(RxData_3));
185title('Rx Radio 3 Q');
186xlabel('n (samples)'); ylabel('Amplitude');
187axis([0 2^14 -1 1]); % Set axis ranges.
Note: See TracBrowser for help on using the browser.