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)

WARPLab Release 02 April 09 2008. Release for 2x2 MIMO and improved SISO. Matlab code is modified to support MIMO. SISO now supports continuous transmission. There is one bitstream for MIMO and one bitstream for SISO. The xps project for MIMO and SISO is different but the M code is the same (The 'warplab_' functions are the same, the argument input to the functions is the only thing that changes from SISO to MIMO).

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.)
26warplab_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
34udp_Sync = socketHandles(1);
35udp_Tx = socketHandles(2);
36udp_RxA = socketHandles(3);
37
38% Define the warplab options (parameters)
39CaptOffset = 1000; %Number of noise samples per Rx capture; in [0:2^14]
40TxLength = 2^14-1000; %Length of transmission; in [0:2^14-CaptOffset]
41TransMode = 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.
46CarrierChannel = 8; % Channel in the 2.4 GHz band. In [1:14]
47TxGainBB = 3; %Tx Baseband Gain in [0:3]
48TxGainRF = 40; %Tx RF Gain in [0:63]
49RxGainBB = 15; %Rx Baseband Gain in [0:31]
50RxGainRF = 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)
54optionsVector = [CaptOffset TxLength-1 TransMode CarrierChannel (RxGainBB + RxGainRF*2^16) (TxGainRF + TxGainBB*2^16)];
55% Send options vector to the nodes
56warplab_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
64t = 0:(1/40e6):TxLength/40e6 - 1/40e6; % Create time vector.
65f = -2e6:(4e6/TxLength):2e6 - 1; % Create frequency vector (Sweeps from
66% 1MHz to 5MHz)  Time and frequency vectors must have the same length.
67TxData = 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
73warplab_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
80warplab_sendCmd(udp_Tx, RADIO2_TXEN, packetNum);
81
82% Enable receiver radio path in receiver node
83warplab_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.
88warplab_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.
93warplab_sendCmd(udp_RxA, RX_START, packetNum);
94
95% Send the SYNC packet
96warplab_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
103nsec = 5;
104pause(nsec);
105
106% Stop transmission
107warplab_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
129warplab_sendCmd(udp_RxA, RX_DONEREADING, packetNum);
130
131% Disable the receiver radio
132warplab_sendCmd(udp_RxA, RADIO2_RXDIS, packetNum);
133
134% Disable the transmitter radio
135warplab_sendCmd(udp_Tx, RADIO2_TXDIS, packetNum);
136
137% Close sockets
138pnet('closeall');
139
140%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
141% 6. Plot the transmitted and received data
142%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
143%Plot Tx_I and Tx_Q data
144figure;
145subplot(4,2,1);
146plot(real(TxData));
147title('Tx I');
148xlabel('n (samples)'); ylabel('Amplitude');
149axis([0 2^14 -1 1]); % Set axis ranges.
150subplot(4,2,3);
151plot(imag(TxData));
152title('Tx Q');
153xlabel('n (samples)'); ylabel('Amplitude');
154axis([0 2^14 -1 1]); % Set axis ranges.
155
156%Plot Tx Spectrogram
157subplot(4,2,[2,4])
158specgram(TxData,1024,1);
159title('Tx Spectrogram');
160xlabel('n (samples)'); ylabel('Frequency');
161axis([0 2^14 1e6/(40e6/2) 10e6/(40e6/2)]); % Set axis ranges.
162
163%Plot Rx_I and Rx_Q data
164subplot(4,2,5);
165plot(real(RxData));
166title('Rx I');
167xlabel('n (samples)'); ylabel('Amplitude');
168axis([0 2^14 -1 1]); % Set axis ranges.
169subplot(4,2,7);
170plot(imag(RxData));
171title('Rx Q');
172xlabel('n (samples)'); ylabel('Amplitude');
173axis([0 2^14 -1 1]); % Set axis ranges.
174
175%Plot Rx Spectrogram
176subplot(4,2,[6,8])
177specgram(RxData,1024,1);
178title('Rx Spectrogram');
179xlabel('n (samples)'); ylabel('Frequency');
180axis([0 2^14 1e6/(40e6/2) 10e6/(40e6/2)]); % Set axis ranges.
Note: See TracBrowser for help on using the browser.