root/ResearchApps/PHY/WARPLAB/WARPLab_SISO_MIMO2x2/M_Code/warplab_siso_example_ContinuousTxFS.m
| Revision 839, 7.5 kB (checked in by MelissaDuarte, 5 months ago) |
|---|
| Line | |
|---|---|
| 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 2 | % Generating a Frequency Sweep with Continous Transmission using Warplab |
| 3 | % (SISO COnfiguration) |
| 4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 5 | % To run this code the boards must be programmed with the |
| 6 | % warplab_siso_v02.bit bitstream |
| 7 | |
| 8 | % The specific steps implemented in this script are the following |
| 9 | |
| 10 | % 0. Initializaton and definition of parameters |
| 11 | % 1. Generate a vector of samples to transmit and send the samples to the |
| 12 | % Warp board (Sample Frequency is 40MHz). Vector represents a sinusoid |
| 13 | % with frequency linearly increasing in time. |
| 14 | % 2. Prepare boards for transmission and reception and send trigger to |
| 15 | % start transmission and reception (trigger is the SYNC packet) |
| 16 | % 3. Leave continuous transmitter on for n seconds and then stop continuous |
| 17 | % transmission. |
| 18 | % 4. Read the received samples from the Warp board. |
| 19 | % 5. Reset and disable the boards. |
| 20 | % 6. Plot the transmitted and received data. |
| 21 | |
| 22 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 23 | % 0. Initializaton and definition of parameters |
| 24 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 25 | %Load some global definitions (packet types, etc.) |
| 26 | warplab_defines |
| 27 | |
| 28 | % Create Socket handles and intialize nodes |
| 29 | [socketHandles, packetNum] = warplab_initialize; |
| 30 | |
| 31 | %Separate the socket handles for easier access |
| 32 | % The first socket handle is always the magic SYNC |
| 33 | % The rest can be arranged in any combination of Tx and Rx |
| 34 | udp_Sync = socketHandles(1); |
| 35 | udp_Tx = socketHandles(2); |
| 36 | udp_RxA = socketHandles(3); |
| 37 | |
| 38 | % Define the warplab options (parameters) |
| 39 | CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14] |
| 40 | TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset] |
| 41 | TransMode = 1; %Transmission mode; in [0:1] |
| 42 | % 0: Single Transmission |
| 43 | % 1: Continuous Transmission. Tx board will continue |
| 44 | % transmitting the vector of samples until the user manually |
| 45 | % disables the transmitter. |
| 46 | CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14] |
| 47 | TxGainBB = 3; %Tx Baseband Gain in [0:3] |
| 48 | TxGainRF = 40; %Tx RF Gain in [0:63] |
| 49 | RxGainBB = 15; %Rx Baseband Gain in [0:31] |
| 50 | RxGainRF = 1; %Rx RF Gain in [1:3] |
| 51 | |
| 52 | % Define the options vector; the order of options is set by the FPGA's code |
| 53 | % (C code) |
| 54 | optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)]; |
| 55 | % Send options vector to the nodes |
| 56 | warplab_setOptions(socketHandles,optionsVector); |
| 57 | |
| 58 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 59 | % 1. Generate a vector of samples to transmit and send the samples to the |
| 60 | % Warp board (Sample Frequency is 40MHz). Vector represents a sinusoid |
| 61 | % with complex frequency linearly increasing in time. |
| 62 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 63 | % Prepare some data to be transmitted |
| 64 | t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector. |
| 65 | f = -2e6:(4e6/TxLength):2e6 - 1; % Create frequency vector (Sweeps from |
| 66 | % 1MHz to 5MHz) Time and frequency vectors must have the same length. |
| 67 | TxData = exp(j*2*pi*f.*t); % Create a signal to transmit. Signal must be a |
| 68 | % row vector. The signal can be real or complex, the only constraint is |
| 69 | % that the amplitude of the real part must be in [-1:1] and the amplitude |
| 70 | % of the imaginary part must be in [-1:1] |
| 71 | |
| 72 | % Download the samples to be transmitted |
| 73 | warplab_writeSMWO(udp_Tx, TxData, RADIO2_TXDATA); |
| 74 | |
| 75 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 76 | % 2. Prepare boards for transmission and reception and send trigger to |
| 77 | % start transmission and reception (trigger is the SYNC packet) |
| 78 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 79 | % Enable transmitter radio path in transmitter node |
| 80 | warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum); |
| 81 | |
| 82 | % Enable receiver radio path in receiver node |
| 83 | warplab_sendCmd(udp_RxA, RADIO2_RXEN, packetNum); |
| 84 | |
| 85 | % Prime transmitter state machine in transmitter node. Transmitter will be |
| 86 | % waiting for the SYNC packet. Transmission will be triggered when the |
| 87 | % transmitter node receives the SYNC packet. |
| 88 | warplab_sendCmd(udp_Tx, TX_START, packetNum); |
| 89 | |
| 90 | % Prime receiver state machine in receiver node. Receiver will be waiting |
| 91 | % for the SYNC packet. Capture will be triggered when the receiver |
| 92 | % node receives the SYNC packet. |
| 93 | warplab_sendCmd(udp_RxA, RX_START, packetNum); |
| 94 | |
| 95 | % Send the SYNC packet |
| 96 | warplab_sendSync(udp_Sync); |
| 97 | |
| 98 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 99 | % 3. Leave continuous transmitter on for n seconds and then stop continuous |
| 100 | % transmission and disable transmitter radio |
| 101 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 102 | % Leave continuous transmitter on for nsec seconds |
| 103 | nsec = 5; |
| 104 | pause(nsec); |
| 105 | |
| 106 | % Stop transmission |
| 107 | warplab_sendCmd(udp_Tx, TX_STOP, packetNum); % Resets the output and read |
| 108 | % address of the transmitter buffer without disabling the transmitter radio. |
| 109 | |
| 110 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 111 | % 4. Read the received samples from the Warp board |
| 112 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 113 | % In continuous transmitter mode the receiver stores CaptOffset samples of |
| 114 | % noise and the first TxLength samples transmitted. |
| 115 | |
| 116 | % Read back the received samples |
| 117 | [RawRxData] = warplab_readSMRO(udp_RxA, RADIO2_RXDATA, TxLength+CaptOffset); |
| 118 | % Process the received samples to obtain meaningful data |
| 119 | [RxData,RxOTR] = warplab_processRawRxData(RawRxData); |
| 120 | % Read stored RSSI data |
| 121 | [RawRSSIData] = warplab_readSMRO(udp_RxA, RADIO2_RSSIDATA, (TxLength+CaptOffset)/8); |
| 122 | % Procecss Raw RSSI data to obtain meningful RSSI values |
| 123 | [RxRSSI] = warplab_processRawRSSIData(RawRSSIData); |
| 124 | |
| 125 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 126 | % 5. Reset and disable the boards |
| 127 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 128 | % Reset the receiver |
| 129 | warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum); |
| 130 | |
| 131 | % Disable the receiver radio |
| 132 | warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum); |
| 133 | |
| 134 | % Disable the transmitter radio |
| 135 | warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum); |
| 136 | |
| 137 | % Close sockets |
| 138 | pnet('closeall'); |
| 139 | |
| 140 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 141 | % 6. Plot the transmitted and received data |
| 142 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 143 | %Plot Tx_I and Tx_Q data |
| 144 | figure; |
| 145 | subplot(4,2,1); |
| 146 | plot(real(TxData)); |
| 147 | title('Tx I'); |
| 148 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 149 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 150 | subplot(4,2,3); |
| 151 | plot(imag(TxData)); |
| 152 | title('Tx Q'); |
| 153 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 154 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 155 | |
| 156 | %Plot Tx Spectrogram |
| 157 | subplot(4,2,[2,4]) |
| 158 | specgram(TxData,1024,1); |
| 159 | title('Tx Spectrogram'); |
| 160 | xlabel('n (samples)'); ylabel('Frequency'); |
| 161 | axis([0 2^14 1e6/(40e6/2) 10e6/(40e6/2)]); % Set axis ranges. |
| 162 | |
| 163 | %Plot Rx_I and Rx_Q data |
| 164 | subplot(4,2,5); |
| 165 | plot(real(RxData)); |
| 166 | title('Rx I'); |
| 167 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 168 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 169 | subplot(4,2,7); |
| 170 | plot(imag(RxData)); |
| 171 | title('Rx Q'); |
| 172 | xlabel('n (samples)'); ylabel('Amplitude'); |
| 173 | axis([0 2^14 -1 1]); % Set axis ranges. |
| 174 | |
| 175 | %Plot Rx Spectrogram |
| 176 | subplot(4,2,[6,8]) |
| 177 | specgram(RxData,1024,1); |
| 178 | title('Rx Spectrogram'); |
| 179 | xlabel('n (samples)'); ylabel('Frequency'); |
| 180 | axis([0 2^14 1e6/(40e6/2) 10e6/(40e6/2)]); % Set axis ranges. |
Note: See TracBrowser
for help on using the browser.