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) |
|---|
| 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.) |
| 22 | warplab_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 |
| 30 | udp_Sync = socketHandles(1); |
| 31 | udp_Tx = socketHandles(2); |
| 32 | udp_RxA = socketHandles(3); |
| 33 | |
| 34 | % Define the warplab options (parameters) |
| 35 | CaptOffset = 1000; %Number of noise samples per Rx capture. In [0:2^14] |
| 36 | TxLength = 2^14-1000; %Length of transmission. In [0:2^14-CaptOffset] |
| 37 | TransMode = 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. |
| 42 | CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14] |
| 43 | TxGainBB = 3; %Tx Baseband Gain. In [0:3] |
| 44 | TxGainRF = 40; %Tx RF Gain. In [0:63] |
| 45 | RxGainBB = 15; %Rx Baseband Gain. In [0:31] |
| 46 | RxGainRF = 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) |
| 50 | optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)]; |
| 51 | % Send options vector to the nodes |
| 52 | warplab_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 |
| 59 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector. |
| 60 | TxData = 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 |
| 66 | warplab_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 |
| 73 | warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum); |
| 74 | |
| 75 | % Enable receiver radio path in receiver node |
| 76 | warplab_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. |
| 81 | warplab_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. |
| 86 | warplab_sendCmd(udp_RxA, RX_START, packetNum); |
| 87 | |
| 88 | % Send the SYNC packet |
| 89 | warplab_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 |
| 107 | warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum); |
| 108 | |
| 109 | % Disable the receiver radio |
| 110 | warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum); |
| 111 | |
| 112 | % Disable the transmitter radio |
| 113 | warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum); |
| 114 | |
| 115 | % Close sockets |
| 116 | pnet('closeall'); |
| 117 | |
| 118 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 119 | % 5. Plot the transmitted and received data |
| 120 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 121 | figure; |
| 122 | subplot(2,2,1); |
| 123 | plot(real(TxData)); |
| 124 | title('Tx I'); |
| 125 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 126 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 127 | subplot(2,2,2); |
| 128 | plot(imag(TxData)); |
| 129 | title('Tx Q'); |
| 130 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 131 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 132 | subplot(2,2,3); |
| 133 | plot(real(RxData)); |
| 134 | title('Rx I'); |
| 135 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 136 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 137 | subplot(2,2,4); |
| 138 | plot(imag(RxData)); |
| 139 | title('Rx Q'); |
| 140 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 141 | axis([0 2^14 -1 1]); % Set axis ranges. |
Note: See TracBrowser
for help on using the browser.