root/ResearchApps/PHY/WARPLAB/WARPLAB_SISO/M_code/warplab_example_TxRx.m
| Revision 812, 5.1 kB (checked in by MelissaDuarte, 11 months ago) |
|---|
| 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.) |
| 19 | warplab_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 |
| 27 | udp_Sync = socketHandles(1); |
| 28 | udp_Tx = socketHandles(2); |
| 29 | udp_RxA = socketHandles(3); |
| 30 | |
| 31 | % Define the warplab options (parameters) |
| 32 | CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14] |
| 33 | TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset] |
| 34 | TxGainBB = 3; %Tx Baseband Gain in [0:3] |
| 35 | TxGainRF = 40; %Tx RF Gain in [0:63] |
| 36 | RxGainBB = 10; %Rx Baseband Gain in [0:31] |
| 37 | RxGainRF = 2; %Rx RF Gain in [1:3] |
| 38 | CarrierChannel = 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) |
| 42 | optionsVector = [CaptOffset TxLength-1 (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16) CarrierChannel]; |
| 43 | % Send options vector to the nodes |
| 44 | warplab_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 |
| 51 | t = 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 | |
| 56 | TxData = 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 |
| 62 | warplab_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 |
| 69 | warplab_enableTx(udp_Tx); |
| 70 | |
| 71 | % Enable reception |
| 72 | warplab_enableRx(udp_RxA); |
| 73 | |
| 74 | % Send the SYNC packet |
| 75 | warplab_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 |
| 93 | warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum); |
| 94 | |
| 95 | % Disable the receiver |
| 96 | warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum); |
| 97 | |
| 98 | % Disable the transmitter |
| 99 | warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum); |
| 100 | |
| 101 | % Close sockets |
| 102 | pnet('closeall'); |
| 103 | |
| 104 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 105 | % 5. Plot the transmitted and received data |
| 106 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 107 | figure; |
| 108 | subplot(2,2,1); |
| 109 | plot(real(TxData)); |
| 110 | title('Tx I'); |
| 111 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 112 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 113 | subplot(2,2,2); |
| 114 | plot(imag(TxData)); |
| 115 | title('Tx Q'); |
| 116 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 117 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 118 | subplot(2,2,3); |
| 119 | plot(real(RxData)); |
| 120 | title('Rx I'); |
| 121 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 122 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 123 | subplot(2,2,4); |
| 124 | plot(imag(RxData)); |
| 125 | title('Rx Q'); |
| 126 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 127 | axis([0 2^14 -1 1]); % Set axis ranges. |
Note: See TracBrowser
for help on using the browser.