1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | % Transmitting and Receiving Data using WARPLab (SISO Configuration) |
---|
3 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
4 | % To run this M-code the boards must be programmed with the |
---|
5 | % 2x2 MIMO 5.x version of WARPLab bitstream (because this bitstream provides |
---|
6 | % storage of RSSI values and this M-code reads RSSI values). This M-code |
---|
7 | % will work with the warplab_mimo_4x4_v05.bit bitstream when reading of |
---|
8 | % RSSI values is deleted from the M-code. |
---|
9 | |
---|
10 | % The specific steps implemented in this script are the following |
---|
11 | |
---|
12 | % 0. Initializaton and definition of parameters |
---|
13 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
14 | % WARP board (Sample Frequency is 40MHz) |
---|
15 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
16 | % start transmission and reception (trigger is the SYNC packet) |
---|
17 | % 3. Read the received samples from the WARP board |
---|
18 | % 4. Reset and disable the boards |
---|
19 | % 5. Plot the transmitted and received data and close sockets |
---|
20 | |
---|
21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
22 | % 0. Initializaton and definition of parameters |
---|
23 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
24 | %Load some global definitions (packet types, etc.) |
---|
25 | warplab_defines |
---|
26 | |
---|
27 | % Create Socket handles and intialize nodes |
---|
28 | [socketHandles, packetNum] = warplab_initialize; |
---|
29 | |
---|
30 | % Separate the socket handles for easier access |
---|
31 | % The first socket handle is always the magic SYNC |
---|
32 | % The rest of the handles are the handles to the WARP nodes |
---|
33 | udp_Sync = socketHandles(1); |
---|
34 | udp_node1 = socketHandles(2); |
---|
35 | udp_node2 = socketHandles(3); |
---|
36 | |
---|
37 | % Define WARPLab parameters. |
---|
38 | % For this experiment node 1 will be set as the transmitter and node |
---|
39 | % 2 will be set as the receiver (this is done later in the code), hence, |
---|
40 | % there is no need to define receive gains for node 1 and there is no |
---|
41 | % need to define transmitter gains for node 2. |
---|
42 | TxDelay = 2000; % Number of noise samples per Rx capture. In [0:2^14] |
---|
43 | TxLength = 2^14-1-1000; % Length of transmission. In [0:2^14-1-TxDelay] |
---|
44 | CarrierChannel = 12; % Channel in the 2.4 GHz band. In [1:14] |
---|
45 | Node1_Radio2_TxGain_BB = 3; % Tx Baseband Gain. In [0:3] |
---|
46 | Node1_Radio2_TxGain_RF = 40; % Tx RF Gain. In [0:63] |
---|
47 | Node2_Radio2_RxGain_BB = 13; % Rx Baseband Gain. In [0:31] |
---|
48 | Node2_Radio2_RxGain_RF = 1; % Rx RF Gain. In [1:3] |
---|
49 | TxMode = 0; % Transmission mode. In [0:1] |
---|
50 | % 0: Single Transmission |
---|
51 | % 1: Continuous Transmission. Tx board will continue |
---|
52 | % transmitting the vector of samples until the user manually |
---|
53 | % disables the transmitter. |
---|
54 | Node2_MGC_AGC_Select = 0; % Set MGC_AGC_Select=1 to enable Automatic Gain Control (AGC). |
---|
55 | % Set MGC_AGC_Select=0 to enable Manual Gain Control (MGC). |
---|
56 | % By default, the nodes are set to MGC. |
---|
57 | |
---|
58 | % Download the WARPLab parameters to the WARP nodes. |
---|
59 | % The nodes store the TxDelay, TxLength, and TxMode parameters in |
---|
60 | % registers defined in the WARPLab sysgen model. The nodes set radio |
---|
61 | % related parameters CarrierChannel, TxGains, and RxGains, using the |
---|
62 | % radio controller functions. |
---|
63 | |
---|
64 | % The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter; |
---|
65 | % the receiver doesn't require knowledge of these parameters (the receiver |
---|
66 | % will always capture 2^14 samples). For this exercise node 1 will be set as |
---|
67 | % the transmitter (this is done later in the code). Since TxDelay, TxLength and |
---|
68 | % TxMode are only required at the transmitter we download the TxDelay, TxLength and |
---|
69 | % TxMode parameters only to the transmitter node (node 1). |
---|
70 | warplab_writeRegister(udp_node1,TX_DELAY,TxDelay); |
---|
71 | warplab_writeRegister(udp_node1,TX_LENGTH,TxLength); |
---|
72 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
73 | % The CarrierChannel parameter must be downloaded to all nodes |
---|
74 | warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel); |
---|
75 | warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel); |
---|
76 | % Node 1 will be set as the transmitter so download Tx gains to node 1. |
---|
77 | warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16)); |
---|
78 | % Node 2 will be set as the receiver so download Rx gains to node 2. |
---|
79 | warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16)); |
---|
80 | % Set MGC mode in node 2 (receiver) |
---|
81 | warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select); |
---|
82 | |
---|
83 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
84 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
85 | % WARP board (Sample Frequency is 40MHz) |
---|
86 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
87 | % Prepare some data to be transmitted |
---|
88 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector. |
---|
89 | |
---|
90 | % Create a signal to transmit, the signal is a function of the time vector |
---|
91 | % 't' the signal can be real or complex. |
---|
92 | |
---|
93 | % The signal must meet the following requirements: |
---|
94 | % - Signal to transmit must be a row vector. |
---|
95 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
96 | % of the imaginary part must be in [-1:1]. |
---|
97 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
98 | % is limited to 19 MHz) |
---|
99 | % - Lowest frequency component is limited to 30 kHz |
---|
100 | |
---|
101 | Node1_Radio2_TxData = exp(t*j*2*pi*1e6); |
---|
102 | |
---|
103 | % Download the samples to be transmitted |
---|
104 | warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData); |
---|
105 | |
---|
106 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
107 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
108 | % start transmission and reception (trigger is the SYNC packet) |
---|
109 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
110 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
111 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
112 | % packet. |
---|
113 | |
---|
114 | % Enable transmitter radio path in radio 2 in node 1 (enable radio 2 in |
---|
115 | % node 1 as transmitter) |
---|
116 | warplab_sendCmd(udp_node1, RADIO2_TXEN, packetNum); |
---|
117 | |
---|
118 | % Enable transmission of node1's radio 2 Tx buffer (enable transmission |
---|
119 | % of samples stored in radio 2 Tx Buffer in node 1) |
---|
120 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXEN, packetNum); |
---|
121 | |
---|
122 | % Enable receiver radio path in radio 2 in node 2 (enable radio 2 in |
---|
123 | % node 2 as receiver) |
---|
124 | warplab_sendCmd(udp_node2, RADIO2_RXEN, packetNum); |
---|
125 | |
---|
126 | % Enable capture in node2's radio 2 Rx Buffer (enable radio 2 rx buffer in |
---|
127 | % node 2 for storage of samples) |
---|
128 | warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXEN, packetNum); |
---|
129 | |
---|
130 | % Prime transmitter state machine in node 1. Node 1 will be |
---|
131 | % waiting for the SYNC packet. Transmission from node 1 will be triggered |
---|
132 | % when node 1 receives the SYNC packet. |
---|
133 | warplab_sendCmd(udp_node1, TX_START, packetNum); |
---|
134 | |
---|
135 | % Prime receiver state machine in node 2. Node 2 will be waiting |
---|
136 | % for the SYNC packet. Capture at node 2 will be triggered when node 2 |
---|
137 | % receives the SYNC packet. |
---|
138 | warplab_sendCmd(udp_node2, RX_START, packetNum); |
---|
139 | |
---|
140 | % Send the SYNC packet |
---|
141 | warplab_sendSync(udp_Sync); |
---|
142 | |
---|
143 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
144 | % 3. Read the received samples from the WARP board |
---|
145 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
146 | % Read back the received samples |
---|
147 | [Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, TxLength+TxDelay); |
---|
148 | % Process the received samples to obtain meaningful data |
---|
149 | [Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData); |
---|
150 | % Read stored RSSI data |
---|
151 | [Node2_Radio2_RawRSSIData] = warplab_readSMRO(udp_node2, RADIO2_RSSIDATA, ceil((TxLength+TxDelay)/8)); |
---|
152 | % Procecss Raw RSSI data to obtain meningful RSSI values |
---|
153 | [Node2_Radio2_RSSIData] = warplab_processRawRSSIData(Node2_Radio2_RawRSSIData); |
---|
154 | % Note: If the two lines of code above (warplab_processRawRSSIData line and |
---|
155 | % warplab_readSMRO(udp_node2, RADIO2_RSSIDATA, (TxLength+TxDelay)/8) line) |
---|
156 | % are deleted, then the code will work when the boards are programmed |
---|
157 | % with the warplab_mimo_4x4_v04.bit bitstream) |
---|
158 | |
---|
159 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
160 | % 4. Reset and disable the boards |
---|
161 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
162 | % Set radio 2 Tx buffer in node 1 back to Tx disabled mode |
---|
163 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXDIS, packetNum); |
---|
164 | |
---|
165 | % Disable the transmitter radio |
---|
166 | warplab_sendCmd(udp_node1, RADIO2_TXDIS, packetNum); |
---|
167 | |
---|
168 | % Set radio 2 Rx buffer in node 2 back to Rx disabled mode |
---|
169 | warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXDIS, packetNum); |
---|
170 | |
---|
171 | % Disable the receiver radio |
---|
172 | warplab_sendCmd(udp_node2, RADIO2_RXDIS, packetNum); |
---|
173 | |
---|
174 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
175 | % 5. Plot the transmitted and received data and close sockets |
---|
176 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
177 | figure; |
---|
178 | subplot(2,2,1); |
---|
179 | plot(real(Node1_Radio2_TxData)); |
---|
180 | title('Tx Node 1 Radio 2 I'); |
---|
181 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
182 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
183 | subplot(2,2,2); |
---|
184 | plot(imag(Node1_Radio2_TxData)); |
---|
185 | title('Tx Node 1 Radio 2 Q'); |
---|
186 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
187 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
188 | subplot(2,2,3); |
---|
189 | plot(real(Node2_Radio2_RxData)); |
---|
190 | title('Rx Node 2 Radio 2 I'); |
---|
191 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
192 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
193 | subplot(2,2,4); |
---|
194 | plot(imag(Node2_Radio2_RxData)); |
---|
195 | title('Rx Node 2 Radio 2 Q'); |
---|
196 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
197 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
198 | |
---|
199 | % Close sockets |
---|
200 | pnet('closeall'); |
---|