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

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