root/ResearchApps/PHY/WARPLAB/WARPLAB_SISO/M_code/warplab_readSMRO_temporal.m

Revision 697, 2.0 kB (checked in by MelissaDuarte, 10 months ago)

Adding warplab m files

Line 
1function [rxData_out rxOTR_out rxRSSI_out] = warplab_readSMRO(udpSock, radio, numSamples)
2
3warplab_siso_defines
4
5pktNoTx = 1;
6
7rxCmd = eval(sprintf('RADIO%d_RXDATA', radio));
8rssiCmd = eval(sprintf('RADIO%d_RSSIDATA', radio));
9
10%Read the RxData from the selected radio
11rxData = [];
12for n = 0:256:numSamples-1
13        pktDataTx = [pktNoTx rxCmd n];
14        datarec = warplab_pktSend(udpSock, pktDataTx);
15        pktNoTx = pktNoTx+1;
16
17        rxData = [rxData uint32(datarec(5:end))];
18end
19
20%Read the RSSI data from the selected radio
21rssiData = [];
22for n = 0:256:(numSamples/8)-1
23        pktDataTx = [pktNoTx rssiCmd n];
24        datarec = warplab_pktSend(udpSock, pktDataTx);
25        pktNoTx = pktNoTx+1;
26
27        rssiData = [rssiData uint32(datarec(5:end))];
28end
29
30%Mangle the received data
31%Each received sample is a 32-bit value:
32% [OTR_I 0 RX_I OTR_Q 0 RX_Q]
33% OTR_I/OTR_Q: UFix1_0, incidates ADC overflow
34% 0: UFix1_0, always zero
35% RX_I/RX_Q: Fix14_13, raw ADC samples
36
37rxData_I = uint16(bitshift(rxData, -16));
38rxData_Q = uint16(bitand(rxData, hex2dec('0000FFFF')));
39
40rxOTR_I = bitshift(rxData_I, -15);
41rxOTR_Q = bitshift(rxData_Q, -15);
42
43rxData_I = uint16(bitand(rxData_I, hex2dec('3FFF'))); %mask off top two bits
44rxData_Isigns = uint16(bitshift(bitand(rxData_I, hex2dec('2000')), -13)); %get sign bit
45rxData_I = double(typecast(bitor(rxData_I, rxData_Isigns*hex2dec('C000')),'int16'))./2^13;
46
47rxData_Q = uint16(bitand(rxData_Q, hex2dec('3FFF'))); %mask off top two bits
48rxData_Qsigns = uint16(bitshift(bitand(rxData_Q, hex2dec('2000')), -13)); %get sign bit
49rxData_Q = double(typecast(bitor(rxData_Q, rxData_Qsigns*hex2dec('C000')),'int16'))./2^13;
50
51%Mangle the RSSI data
52%Each received sample is a 32-bit value:
53% [zeros(1,6) RSSI_0 zeros(1,6) RSSI_1]
54% RSSI_0/RSSI_1: Consequtive RSSI samples; RSSI_0 is older
55rssi = [mod(rssiData, 1024);mod(bitshift(rssiData,-16),1024)];
56
57rxData_out = complex(rxData_I, rxData_Q);
58rxOTR_out = complex(rxOTR_I, rxOTR_Q);
59rxRSSI_out = reshape(rssi, 1, length(rssiData)*2);
Note: See TracBrowser for help on using the browser.