root/ResearchApps/PHY/WARPLAB/WARPLAB_SISO/M_code/warplab_example_TxRx.m

Revision 812, 5.1 kB (checked in by MelissaDuarte, 11 months ago)

Adding arp entry for magic sync in the warplab_initialize.m and warplab_siso_GUIinitialize.m functions. Modifying Guis: Commented out the parts of code that were included just for the workshop (to avoid conflict between groups)

Line 
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2% Transmitting and Receiving Data using Warplab
3%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4% The specific steps implemented in this script are the following
5
6% 0. Initializaton and definition of parameters
7% 1. Generate a vector of samples to transmit and send the samples to the
8% Warp board (Sample Frequency is 40MHz)
9% 2. Prepare boards for transmission and reception and send trigger to
10% start transmission and reception (trigger is the SYNC packet)
11% 3. Read the received samples from the Warp board
12% 4. Reset and disable the boards
13% 5. Plot the transmitted and received data
14
15%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16% 0. Initializaton and definition of parameters
17%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18%Load some global definitions (packet types, etc.)
19warplab_siso_defines
20
21% Create Socket handles and intialize nodes
22[socketHandles, packetNum] = warplab_initialize;
23
24%Separate the socket handles for easier access
25% The first socket handle is always the magic SYNC
26% The rest can be arranged in any combination of Tx and Rx
27udp_Sync = socketHandles(1);
28udp_Tx = socketHandles(2);
29udp_RxA = socketHandles(3);
30
31% Define the warplab options (parameters)
32CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14]
33TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset]
34TxGainBB = 3; %Tx Baseband Gain in [0:3]
35TxGainRF = 40; %Tx RF Gain in [0:63]
36RxGainBB = 10; %Rx Baseband Gain in [0:31]
37RxGainRF = 2; %Rx RF Gain in [1:3]
38CarrierChannel = 11; % Channel in the 2.4 GHz band. In [1:14]
39
40% Define the options vector; the order of options is set by the FPGA's code
41% (C code)
42optionsVector = [CaptOffset TxLength-1 (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16) CarrierChannel];
43% Send options vector to the nodes
44warplab_setOptions(socketHandles,optionsVector);
45
46%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47% 1. Generate a vector of samples to transmit and send the samples to the
48% Warp board
49%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50% Prepare some data to be transmitted
51t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector(Sample Frequency is 40MHz)
52% If the WARP boards you are using have a sampling frequency of 50MHz then
53% uncomment the following line
54% t = 0:(1/50e6):TxLength/50e6 - 1/50e6;
55
56TxData = exp(t*j*2*pi*1e6); % Create a signal to transmit. Signal must be a
57% row vector. The signal can be real or complex, the only constraint is
58% that the amplitude of the real part must be in [-1:1] and the amplitude
59% of the imaginary part must be in [-1:1]
60
61% Download the samples to be transmitted
62warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA);
63
64%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65% 2. Prepare boards for transmission and reception and send trigger to
66% start transmission and reception (trigger is the SYNC packet)
67%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68% Enable transmission
69warplab_enableTx(udp_Tx);
70
71% Enable reception
72warplab_enableRx(udp_RxA);
73
74% Send the SYNC packet
75warplab_sendSync(udp_Sync);
76
77%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
78% 3. Read the received samples from the Warp board
79%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80% Read back the received samples
81[RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset);
82% Process the received samples to obtain meaningful data
83[RxData,RxOTR] = warplab_processRawRxData(RawRxData);
84% Read stored RSSI data
85[RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8);
86% Procecss Raw RSSI data to obtain meningful RSSI values
87[RxRSSI] = warplab_processRawRSSIData(RawRSSIData);
88
89%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90% 4. Reset and disable the boards
91%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92% Reset the receiver
93warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
94
95% Disable the receiver
96warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum);
97
98% Disable the transmitter
99warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum);
100
101% Close sockets
102pnet('closeall');
103
104%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105% 5. Plot the transmitted and received data
106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107figure;
108subplot(2,2,1);
109plot(real(TxData));
110title('Tx I');
111xlabel('n (samples)'); ylabel('Amplitude');
112axis([0 2^14 -1 1]); % Set axis ranges.
113subplot(2,2,2);
114plot(imag(TxData));
115title('Tx Q');
116xlabel('n (samples)'); ylabel('Amplitude');
117axis([0 2^14 -1 1]); % Set axis ranges.
118subplot(2,2,3);
119plot(real(RxData));
120title('Rx I');
121xlabel('n (samples)'); ylabel('Amplitude');
122axis([0 2^14 -1 1]); % Set axis ranges.
123subplot(2,2,4);
124plot(imag(RxData));
125title('Rx Q');
126xlabel('n (samples)'); ylabel('Amplitude');
127axis([0 2^14 -1 1]); % Set axis ranges.
Note: See TracBrowser for help on using the browser.