1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
2 | % Transmit sum of two sinusoids in Continous Transmission mode using WARPLab |
---|
3 | % (SISO configuration) |
---|
4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
5 | % The specific steps implemented in this script are the following |
---|
6 | |
---|
7 | % 0. Initializaton and definition of parameters |
---|
8 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
9 | % WARP board (Sample Frequency is 40MHz). Vector represents a sum of two |
---|
10 | % sinusoids with different frequency. |
---|
11 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
12 | % start transmission and reception (trigger is the SYNC packet) |
---|
13 | % 3. Leave continuous transmitter on for n seconds and then stop continuous |
---|
14 | % transmission. |
---|
15 | % 4. Read the received samples from the WARP board. |
---|
16 | % 5. Reset and disable the boards. |
---|
17 | % 6. Plot the first 2^14 received samples and close sockets |
---|
18 | |
---|
19 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
20 | % 0. Initializaton and definition of parameters |
---|
21 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
22 | %Load some global definitions (packet types, etc.) |
---|
23 | warplab_defines |
---|
24 | |
---|
25 | % Create Socket handles and intialize nodes |
---|
26 | [socketHandles, packetNum] = warplab_initialize; |
---|
27 | |
---|
28 | % Separate the socket handles for easier access |
---|
29 | % The first socket handle is always the magic SYNC |
---|
30 | % The rest of the handles are the handles to the WARP nodes |
---|
31 | udp_Sync = socketHandles(1); |
---|
32 | udp_node1 = socketHandles(2); |
---|
33 | udp_node2 = socketHandles(3); |
---|
34 | |
---|
35 | % Define WARPLab parameters. |
---|
36 | % Note: For this experiment node 1 will be set as the transmitter and node |
---|
37 | % 2 will be set as the receiver (this is done later in the code), hence, |
---|
38 | % there is no need to define receive gains for node 1 and there is no |
---|
39 | % need to define transmitter gains for node 2. |
---|
40 | TxDelay = 1000; % Number of noise samples per Rx capture. In [0:2^14] |
---|
41 | TxLength = 2^14-1-1000; % Length of transmission vector. In [0:2^14-1-TxDelay] |
---|
42 | TxMode = 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. |
---|
47 | CarrierChannel = 12; % Channel in the 2.4 GHz band. In [1:14] |
---|
48 | Node1_Radio2_TxGain_BB = 3; % Tx Baseband Gain. In [0:3] |
---|
49 | Node1_Radio2_TxGain_RF = 40; % Tx RF Gain. In [0:63] |
---|
50 | Node2_Radio2_RxGain_BB = 15; % Rx Baseband Gain. In [0:31] |
---|
51 | Node2_Radio2_RxGain_RF = 1; % Rx RF Gain. In [1:3] |
---|
52 | Node2_MGC_AGC_Select = 0; % Set MGC_AGC_Select=1 to enable Automatic Gain Control (AGC). |
---|
53 | % Set MGC_AGC_Select=0 to enable Manual Gain Control (MGC). |
---|
54 | % By default, the nodes are set to MGC. |
---|
55 | |
---|
56 | % Download the WARPLab parameters to the WARP nodes. |
---|
57 | % The nodes store the TxDelay, TxLength, and TxMode parameters in |
---|
58 | % registers defined in the WARPLab sysgen model. The nodes set radio |
---|
59 | % related parameters CarrierChannel, TxGains, and RxGains, using the |
---|
60 | % radio controller functions. |
---|
61 | % The TxDelay, TxLength, and TxMode parameters need to be known at the transmitter; |
---|
62 | % the receiver doesn't require knowledge of these parameters (the receiver |
---|
63 | % will always capture 2^14 samples). For this exercise node 1 will be set as |
---|
64 | % the transmitter (this is done later in the code). Since TxDelay, TxLength and |
---|
65 | % TxMode are only required at the transmitter download the TxDelay, TxLength and |
---|
66 | % TxMode parameters only to the transmitter node (node 1). |
---|
67 | % Hints: |
---|
68 | % 1. The first argument of the 'warplab_writeRegister' function identifies |
---|
69 | % the node to which the parameter will be downloaded to. The id or handle |
---|
70 | % to node 1 is 'udp_node1'. |
---|
71 | % 2. The second argument of the 'warplab_writeRegister' function identifies |
---|
72 | % the parameter that will be downloaded. The id for the TxDelay |
---|
73 | % parameter is 'TX_DELAY, the id for the TxLength parameter is 'TX_LENGTH' |
---|
74 | % and the id for the TxMode parameter is 'TX_MODE'. |
---|
75 | % 3. The third argument of the 'warplab_writeRegister' function is the |
---|
76 | % value the parameter must be set to. The values to download have been |
---|
77 | % stored in the 'TxDelay', 'TxLength', and 'TxMode' variables. |
---|
78 | % 4. Call the 'warplab_writeRegister' three times. One time to download the |
---|
79 | % TxDelay, one time to download the TxLength, and one time to download the |
---|
80 | % TxMode. The 'warplab_writeRegister' function can only set one register (parameter) per node at a time |
---|
81 | |
---|
82 | warplab_writeRegister(udp_node1,TX_DELAY,TxDelay); |
---|
83 | warplab_writeRegister(udp_node1,TX_LENGTH,TxLength); |
---|
84 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
85 | |
---|
86 | % Download the CarrierChannel parameter to both nodes using the |
---|
87 | % 'warplab_setRadioParameter' function. |
---|
88 | % The CarrierChannel parameter must be downloaded to all nodes |
---|
89 | % Hints: |
---|
90 | % 1. The first argument of the 'warplab_setRadioParameter' function |
---|
91 | % identifies the node to which the parameter will be downloaded to. |
---|
92 | % The id or handle to node 1 is 'udp_node1' and the id or handle to node 2 |
---|
93 | % is 'udp_node2' |
---|
94 | % 2. The second argument of the 'warplab_setRadioParameter' function |
---|
95 | % identifies the parameter that will be downloaded. The id for the |
---|
96 | % CarrierChannel parameter is 'CARRIER_CHANNEL' |
---|
97 | % 3. The third argument of the 'warplab_setRadioParameter' function is the |
---|
98 | % value the parameter must be set to. This value has been stored in the |
---|
99 | % CarrierChannel variable. |
---|
100 | % 4. Call the 'warplab_setRadioParameter' twice. One time to download the |
---|
101 | % CarrierChannel to node 1 and one time to download the CarrierChannel to |
---|
102 | % node 2. The 'warplab_setRadioParameter' function can only set one |
---|
103 | % radio parameter per node at a time |
---|
104 | warplab_setRadioParameter(udp_node1,CARRIER_CHANNEL,CarrierChannel); |
---|
105 | warplab_setRadioParameter(udp_node2,CARRIER_CHANNEL,CarrierChannel); |
---|
106 | |
---|
107 | % Node 1 will be set as the transmitter so download Tx gains to node 1. |
---|
108 | warplab_setRadioParameter(udp_node1,RADIO2_TXGAINS,(Node1_Radio2_TxGain_RF + Node1_Radio2_TxGain_BB*2^16)); |
---|
109 | % Node 2 will be set as the receiver so download Rx gains to node 2. |
---|
110 | warplab_setRadioParameter(udp_node2,RADIO2_RXGAINS,(Node2_Radio2_RxGain_BB + Node2_Radio2_RxGain_RF*2^16)); |
---|
111 | % Set MGC mode in node 2 (receiver) |
---|
112 | warplab_setAGCParameter(udp_node2,MGC_AGC_SEL, Node2_MGC_AGC_Select); |
---|
113 | |
---|
114 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
115 | % 1. Generate a vector of samples to transmit and send the samples to the |
---|
116 | % WARP board (Sample Frequency is 40MHz). Vector represents a sum of two |
---|
117 | % sinusoids with different frequency. |
---|
118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
119 | % Prepare some data to be transmitted |
---|
120 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector. |
---|
121 | |
---|
122 | % Create a signal to transmit, the signal can be real or complex. |
---|
123 | % The signal must meet the following requirements: |
---|
124 | % - Signal to transmit must be a row vector. |
---|
125 | % - The amplitude of the real part must be in [-1:1] and the amplitude |
---|
126 | % of the imaginary part must be in [-1:1]. |
---|
127 | % - Highest frequency component is limited to 9.5 MHz (signal bandwidth |
---|
128 | % is limited to 19 MHz) |
---|
129 | % - Lowest frequency component is limited to 30 kHz |
---|
130 | f1 = 1e6; |
---|
131 | f2 = 6e6; |
---|
132 | Node1_Radio2_TxData = exp(t*j*2*pi*f1)+exp(t*j*2*pi*f2); % Create a signal to transmit. |
---|
133 | % Signal is the sum of two sinusoids with frequencies f1 and f2. |
---|
134 | |
---|
135 | % Scale signal so that amplitude of the real and |
---|
136 | % imaginary part is in [-1:1]. We want the signal to span [-1,1] range |
---|
137 | % so it uses the full range of the DAC at the tranmitter. |
---|
138 | scale = 1 / max( [ max(real(Node1_Radio2_TxData)) , max(imag(Node1_Radio2_TxData)) ] ); |
---|
139 | Node1_Radio2_TxData = scale*Node1_Radio2_TxData; |
---|
140 | |
---|
141 | % Download the samples to be transmitted |
---|
142 | warplab_writeSMWO(udp_node1, RADIO2_TXDATA, Node1_Radio2_TxData); |
---|
143 | |
---|
144 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
145 | % 2. Prepare WARP boards for transmission and reception and send trigger to |
---|
146 | % start transmission and reception (trigger is the SYNC packet) |
---|
147 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
148 | % The following lines of code set node 1 as transmitter and node 2 as |
---|
149 | % receiver; transmission and capture are triggered by sending the SYNC |
---|
150 | % packet. |
---|
151 | |
---|
152 | % Enable transmitter radio path in radio 2 in node 1 (enable radio 2 in |
---|
153 | % node 1 as transmitter) |
---|
154 | warplab_sendCmd(udp_node1, RADIO2_TXEN, packetNum); |
---|
155 | |
---|
156 | % Enable transmission of node1's radio 2 Tx buffer (enable transmission |
---|
157 | % of samples stored in radio 2 Tx Buffer in node 1) |
---|
158 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXEN, packetNum); |
---|
159 | |
---|
160 | % Enable receiver radio path in radio 2 in node 2 (enable radio 2 in |
---|
161 | % node 2 as receiver) |
---|
162 | warplab_sendCmd(udp_node2, RADIO2_RXEN, packetNum); |
---|
163 | |
---|
164 | % Enable capture in node2's radio 2 Rx Buffer (enable radio 2 rx buffer in |
---|
165 | % node 2 for storage of samples) |
---|
166 | warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXEN, packetNum); |
---|
167 | |
---|
168 | % Prime transmitter state machine in node 1. Node 1 will be |
---|
169 | % waiting for the SYNC packet. Transmission from node 1 will be triggered |
---|
170 | % when node 1 receives the SYNC packet. |
---|
171 | warplab_sendCmd(udp_node1, TX_START, packetNum); |
---|
172 | |
---|
173 | % Prime receiver state machine in node 2. Node 2 will be waiting |
---|
174 | % for the SYNC packet. Capture at node 2 will be triggered when node 2 |
---|
175 | % receives the SYNC packet. |
---|
176 | warplab_sendCmd(udp_node2, RX_START, packetNum); |
---|
177 | |
---|
178 | % Send the SYNC packet |
---|
179 | warplab_sendSync(udp_Sync); |
---|
180 | |
---|
181 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
182 | % 3. Leave continuous transmitter on for n seconds and then stop continuous |
---|
183 | % transmission |
---|
184 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
185 | % Leave continuous transmitter on for nsec seconds |
---|
186 | nsec = 5; |
---|
187 | pause(nsec); |
---|
188 | |
---|
189 | % Stop transmission by sending the TX_STOP command using the |
---|
190 | % 'warplab_sendCmd' function. |
---|
191 | % Hints: |
---|
192 | % 1. The first argument of the 'warplab_sendCmd' function identifies the |
---|
193 | % node to which the command will be sent. The TX_STOP command must be sent |
---|
194 | % to the transmitter node so use 'udp_node1' as the first argument. |
---|
195 | % 2. The second argument of the 'warplab_sendCmd' function identifies the |
---|
196 | % instruction or command to be sent. In this case, the command to send is |
---|
197 | % the TX_STOP command. |
---|
198 | % 3. The third argument of the 'warplab_sendCmd' command is a field that is |
---|
199 | % not used at the moment, it may be used in future versions of WARPLab to |
---|
200 | % keep track of packets. Use 'packetNum' as the third argument of the |
---|
201 | % 'warplab_sendCmd' command. |
---|
202 | % Stop transmission |
---|
203 | warplab_sendCmd(udp_node1, TX_STOP, packetNum); % Resets the output and read |
---|
204 | % address of the transmitter buffer without disabling the transmitter radio. |
---|
205 | |
---|
206 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
207 | % 4. Read the received samples from the WARP board |
---|
208 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
209 | % In continuous transmitter mode the receiver stores CaptOffset samples of |
---|
210 | % noise and the first 2^14-CaptOffset samples transmitted. |
---|
211 | |
---|
212 | % Read back the received samples |
---|
213 | [Node2_Radio2_RawRxData] = warplab_readSMRO(udp_node2, RADIO2_RXDATA, 2^14); |
---|
214 | % Process the received samples to obtain meaningful data |
---|
215 | [Node2_Radio2_RxData,Node2_Radio2_RxOTR] = warplab_processRawRxData(Node2_Radio2_RawRxData); |
---|
216 | |
---|
217 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
218 | % 5. Reset and disable the boards |
---|
219 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
220 | % Set radio 2 Tx buffer in node 1 back to Tx disabled mode |
---|
221 | warplab_sendCmd(udp_node1, RADIO2TXBUFF_TXDIS, packetNum); |
---|
222 | |
---|
223 | % Disable the transmitter radio |
---|
224 | warplab_sendCmd(udp_node1, RADIO2_TXDIS, packetNum); |
---|
225 | |
---|
226 | % Set radio 2 Rx buffer in node 2 back to Rx disabled mode |
---|
227 | warplab_sendCmd(udp_node2, RADIO2RXBUFF_RXDIS, packetNum); |
---|
228 | |
---|
229 | % Disable the receiver radio |
---|
230 | warplab_sendCmd(udp_node2, RADIO2_RXDIS, packetNum); |
---|
231 | |
---|
232 | % Disable continous tranmsission mode |
---|
233 | TxMode = 0; |
---|
234 | warplab_writeRegister(udp_node1,TX_MODE,TxMode); |
---|
235 | |
---|
236 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
237 | % 6. Plot the transmitted and received data and close sockets |
---|
238 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
---|
239 | figure; |
---|
240 | subplot(2,2,1); |
---|
241 | plot(real(Node1_Radio2_TxData)); |
---|
242 | title('Tx Node 1 Radio 2 I'); |
---|
243 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
244 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
245 | subplot(2,2,2); |
---|
246 | plot(imag(Node1_Radio2_TxData)); |
---|
247 | title('Tx Node 1 Radio 2 Q'); |
---|
248 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
249 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
250 | subplot(2,2,3); |
---|
251 | plot(real(Node2_Radio2_RxData)); |
---|
252 | title('Rx Node 2 Radio 2 I'); |
---|
253 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
254 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
255 | subplot(2,2,4); |
---|
256 | plot(imag(Node2_Radio2_RxData)); |
---|
257 | title('Rx Node 2 Radio 2 Q'); |
---|
258 | xlabel('n (samples)'); ylabel('Amplitude'); |
---|
259 | axis([0 2^14 -1 1]); % Set axis ranges. |
---|
260 | |
---|
261 | % Close sockets |
---|
262 | pnet('closeall'); |
---|
263 | |
---|
264 | |
---|