root/ResearchApps/PHY/WARPLAB/WARPLAB_SISO/M_code/TxRx_Test_warplab_siso_v1.m
| Revision 780, 4.4 kB (checked in by MelissaDuarte, 9 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 | % Create Socket hanldes and intialize nodes |
| 19 | warplab_initialize |
| 20 | |
| 21 | % Define the warplab options (parameters) |
| 22 | CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14] |
| 23 | TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset] |
| 24 | TxGainBB = 3; %Tx Baseband Gain in [0:3] |
| 25 | TxGainRF = 40; %Tx RF Gain in [0:63] |
| 26 | RxGainBB = 18; %Rx Baseband Gain in [0:31] |
| 27 | RxGainRF = 1; %Rx RF Gain in [1:3] |
| 28 | CarrierChannel = 11; |
| 29 | |
| 30 | % Define the options vector; the order of options is set by the FPGA's code |
| 31 | % (C code) |
| 32 | optionsVector = [CaptOffset TxLength-1 (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16) CarrierChannel]; |
| 33 | % Send options vector to the nodes |
| 34 | warplab_setOptions(socketHandles,optionsVector); |
| 35 | |
| 36 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 37 | % 1. Generate a vector of samples to transmit and send the samples to the |
| 38 | % Warp board (Sample Frequency is 40MHz) |
| 39 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 40 | % Prepare some data to be transmitted |
| 41 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; %Create time vector. |
| 42 | TxData = exp(t*j*2*pi*1e6); % Create a signal to transmit |
| 43 | |
| 44 | % Download the samples to be transmitted |
| 45 | warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA); |
| 46 | |
| 47 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 48 | % 2. Prepare boards for transmission and reception and send trigger to |
| 49 | % start transmission and reception (trigger is the SYNC packet) |
| 50 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 51 | % Enable transmission |
| 52 | warplab_enableTx |
| 53 | |
| 54 | % Enable reception |
| 55 | warplab_enableRx |
| 56 | |
| 57 | % Send the SYNC packet |
| 58 | warplab_sendSync(udp_Sync); |
| 59 | |
| 60 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 61 | % 3. Read the received smaples from the Warp board |
| 62 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 63 | % Read back the received samples |
| 64 | [RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset); |
| 65 | % Process the received samples to obtain meaningful data |
| 66 | [RxData,RxOTR] = warplab_processRawRxData(RawRxData); |
| 67 | % Read stored RSSI data |
| 68 | [RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8); |
| 69 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 70 | [RxRSSI] = warplab_processRawRSSIData(RawRSSIData); |
| 71 | |
| 72 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 73 | % 4. Reset and disable the boards |
| 74 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 75 | % Reset the receiver |
| 76 | warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum); |
| 77 | |
| 78 | % Disable the receiver |
| 79 | warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum); |
| 80 | |
| 81 | % Disable the transmitter |
| 82 | warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum); |
| 83 | |
| 84 | % Close sockets |
| 85 | pnet('closeall'); |
| 86 | |
| 87 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 88 | % 5. Plot the transmitted and received data |
| 89 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 90 | figure; |
| 91 | subplot(2,2,1); |
| 92 | plot(real(TxData)); |
| 93 | title('Tx I'); |
| 94 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 95 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 96 | subplot(2,2,2); |
| 97 | plot(imag(TxData)); |
| 98 | title('Tx Q'); |
| 99 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 100 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 101 | subplot(2,2,3); |
| 102 | plot(real(RxData)); |
| 103 | title('Rx I'); |
| 104 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 105 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 106 | subplot(2,2,4); |
| 107 | plot(imag(RxData)); |
| 108 | title('Rx Q'); |
| 109 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 110 | axis([0 2^14 -1 1]); % Set axis ranges. |
Note: See TracBrowser
for help on using the browser.