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

Revision 839, 6.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% Transmitting and Receiving 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% 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]
43TxGainBB = 3; %Tx Baseband Gain. In [0:3]
44TxGainRF = 40; %Tx RF Gain. In [0:63]
45RxGainBB = 15; %Rx Baseband Gain. In [0:31]
46RxGainRF = 1; %Rx RF Gain. In [1:3]
47
48% Define the options vector; the order of options is set by the FPGA's code
49% (C code)
50optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)];
51% Send options vector to the nodes
52warplab_setOptions(socketHandles,optionsVector);
53
54%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55% 1. Generate a vector of samples to transmit and send the samples to the
56% Warp board (Sample Frequency is 40MHz)
57%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58% Prepare some data to be transmitted
59t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector.
60TxData = exp(t*j*2*pi*1e6); % Create a signal to transmit. Signal must be a
61% row vector. The signal can be real or complex, the only constraint is
62% that the amplitude of the real part must be in [-1:1] and the amplitude
63% of the imaginary part must be in [-1:1]
64
65% Download the samples to be transmitted
66warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA);
67
68%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69% 2. Prepare boards for transmission and reception and send trigger to
70% start transmission and reception (trigger is the SYNC packet)
71%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72% Enable transmitter radio path in transmitter node
73warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum);
74
75% Enable receiver radio path in receiver node
76warplab_sendCmd(udp_RxA, RADIO2_RXEN, packetNum);
77
78% Prime transmitter state machine in transmitter node. Transmitter will be
79% waiting for the SYNC packet. Transmission will be triggered when the
80% transmitter node receives the SYNC packet.
81warplab_sendCmd(udp_Tx, TX_START, packetNum);
82
83% Prime receiver state machine in receiver node. Receiver will be waiting
84% for the SYNC packet. Capture will be triggered when the receiver
85% node receives the SYNC packet.
86warplab_sendCmd(udp_RxA, RX_START, packetNum);
87
88% Send the SYNC packet
89warplab_sendSync(udp_Sync);
90
91%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92% 3. Read the received samples from the Warp board
93%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94% Read back the received samples
95[RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset);
96% Process the received samples to obtain meaningful data
97[RxData,RxOTR] = warplab_processRawRxData(RawRxData);
98% Read stored RSSI data
99[RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
100% Procecss Raw RSSI data to obtain meningful RSSI values
101[RxRSSI] = warplab_processRawRSSIData(RawRSSIData);
102
103%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104% 4. Reset and disable the boards
105%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106% Reset the receiver
107warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
108
109% Disable the receiver radio
110warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum);
111
112% Disable the transmitter radio
113warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum);
114
115% Close sockets
116pnet('closeall');
117
118%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
119% 5. Plot the transmitted and received data
120%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
121figure;
122subplot(2,2,1);
123plot(real(TxData));
124title('Tx I');
125xlabel('n (samples)'); ylabel('Amplitude');
126axis([0 2^14 -1 1]); % Set axis ranges.
127subplot(2,2,2);
128plot(imag(TxData));
129title('Tx Q');
130xlabel('n (samples)'); ylabel('Amplitude');
131axis([0 2^14 -1 1]); % Set axis ranges.
132subplot(2,2,3);
133plot(real(RxData));
134title('Rx I');
135xlabel('n (samples)'); ylabel('Amplitude');
136axis([0 2^14 -1 1]); % Set axis ranges.
137subplot(2,2,4);
138plot(imag(RxData));
139title('Rx Q');
140xlabel('n (samples)'); ylabel('Amplitude');
141axis([0 2^14 -1 1]); % Set axis ranges.
Note: See TracBrowser for help on using the browser.