Commit 84fb51d8 authored by guibene's avatar guibene

WHERE2 measurements

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4306 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent e52c28aa
CC = gcc
CFLAGS = -DUSER_MODE
XTRA_CFLAGS = -msse -msse2 -mssse3
#ifndef OPENAIR0_DIR
# $(error Environment variable OPENAIR0_DIR must be set!)
#else
# CFLAGS += -I$(OPENAIR0_DIR)/express-mimo/software/pcie
#endif
GCCVERSION = $(shell gcc --version | grep ^gcc | sed 's/^.* //g')
ifeq "$(GCCVERSION)" "4.4.3"
CFLAGS += -Wno-packed-bitfield-compat
endif
ifeq "$(GCCVERSION)" "4.5.2"
CFLAGS += -Wno-packed-bitfield-compat
endif
ifeq "$(GCCVERSION)" "4.6.1"
CFLAGS += -Wno-packed-bitfield-compat
endif
OPENAIRTARGETS_DIR ?=../../../..
OPENAIROBJS += $(OPENAIRTARGETS_DIR)/ARCH/EXMIMO/USERSPACE/LIB/openair0_lib.o
CFLAGS += -I$(OPENAIRTARGETS_DIR)/ARCH/EXMIMO/USERSPACE/LIB -I$(OPENAIRTARGETS_DIR)/ARCH/EXMIMO/DEFS
#OPENAIROBJS = $(OPENAIR1_DIR)/PHY/CONFIG/openair_readconfigfile.o $(OPENAIR1_DIR)/PHY/CONFIG/openair_configure.o
OCTAVEOBJS = oarf_config_exmimo.oct oarf_get_frame.oct oarf_stop.oct oarf_send_frame.oct oarf_get_num_detected_cards.oct
all: $(OCTAVEOBJS) gpib_send.oct
oarf: $(OCTAVEOBJS)
$(OPENAIROBJS) : %.o : %.c
gcc -c $(CFLAGS) $(XTRA_CFLAGS) -o $@ $<
test:
echo $(OPENAIROBJS)
$(OCTAVEOBJS) : %.oct : %.cc $(OPENAIROBJS)
mkoctfile -o $@ $(CFLAGS) -lm $(OPENAIROBJS) $<
gpib_send.oct: gpib_send.cc
mkoctfile -I/usr/include/gpib -I/usr/local/include/gpib -lgpib gpib_send.cc
clean:
rm -f gpib_send.oct $(OCTAVEOBJS) $(OPENAIROBJS) *.o octave-core
function [sig,sig_length] = OFDM_TX(num_carriers,num_zeros,prefix_length,input)
% OFDM Transmitter - DC removed
% sig is the output signal
% length is the length of the output signal
% num_carriers - number of sub-carriers (power of 2)
% num_zeros - number of zeros minus 1 (DC) in output spectrum (odd)
% prefix_length - length of cyclic prefix
% input - input dimensions (length = number_carriers - num_zeros - 1)
if (length(input) + num_zeros + 1 ~= num_carriers)
fprintf('error in lengths\n');
return;
end
ext_input = [0 input(1:length(input)/2) zeros(1,num_zeros) input((1+length(input)/2) : length(input))];
output_1 = ifft(ext_input);
sig = [output_1((num_carriers - prefix_length + 1) : num_carriers) output_1];
sig_length = length(sig);
function sig = OFDM_TX_FRAME(num_carriers,num_zeros,prefix_length,num_symbols_frame,preamble_length)
% sig - output signal
% sig_length - output signal length
% num_carriers - number of sub-carriers
% num_zeros - number of zero carriers minus 1 (DC)
% prefix_length - length of cyclic prefix
% num_symbols_frame - number of symbols per OFDM frame
% preamble_length - length of 4-QAM preamble
num_useful_carriers = num_carriers - num_zeros -1;
sig = [];
for k=1:preamble_length
QAM4_preamble = QAM_MOD(4,floor(256*abs(rand(1,num_useful_carriers/4))));
sig = [sig OFDM_TX(num_carriers,num_zeros,prefix_length,QAM4_preamble)];
end
for k=1:(num_symbols_frame - preamble_length)
QAM_data = QAM_MOD(256,floor(256*abs(rand(1,num_useful_carriers))));
sig = [sig OFDM_TX(num_carriers,num_zeros,prefix_length,QAM_data)];
end
function [sig,sig_length] = QAM_MOD(size,input)
% sig - output symbols
% size - modulation size (4,16,256)
% input - vector of bytes to be modulated
AM2 = [-1 1];
AM4 = [-3 -1 1 3]; AM4 = 2*AM4/sqrt(AM4*AM4');
AM16 = [-15 -13 -11 -9 -7 -5 -3 -1 1 3 5 7 9 11 13 15]; AM16 = 4*AM16/sqrt(AM16*AM16');
sig = zeros(1,length(input)*8/log2(size));
sig_length = length(input)*8/log2(size);
for l=1:length(input)
if (size == 256)
sig(l) = (AM16(1+ floor((input(l)/16))) +sqrt(-1)*AM16(1+rem(input(l),16)))/sqrt(2);
elseif (size == 16)
sig(1 + 2*(l-1)) = (AM4(1+floor((input(l)/64))) + sqrt(-1)*AM4(1+rem(floor(input(l)/16) , 4)))/sqrt(2);
sig(2 + 2*(l-1)) = (AM4(1+rem(floor(input(l)/4) , 4)) + sqrt(-1)*AM4(1+rem(input(l) , 4)))/sqrt(2);
elseif (size == 4)
sig(1+ 4*(l-1)) = (AM2(1+(floor(input(l)/128))) + sqrt(-1)*AM2(1+rem(floor(input(l)/64) , 2)))/sqrt(2);
sig(2+ 4*(l-1)) = (AM2(1+rem(floor(input(l)/32) ,2)) + sqrt(-1)*AM2(1+rem(floor(input(l)/16) , 2)))/sqrt(2);
sig(3+ 4*(l-1)) = (AM2(1+rem(floor(input(l)/8) , 2)) + sqrt(-1)*AM2(1+rem(floor(input(l)/4) , 2)))/sqrt(2);
sig(4+ 4*(l-1)) = (AM2(1+rem(floor(input(l)/2) , 2)) + sqrt(-1)*AM2(1+rem(input(l) , 2)))/sqrt(2);
end
end
chan=1;
hold off ;
card=0;
s=oarf_get_frame(card);
s2=zeros(76800*2,1);
s2(1:2:end) = s(:,chan);
s2(2:2:end) = s(:,chan);
plot(real(s2),'b',"markersize",1);
hold on; plot(imag(s2),'r',"markersize",1);
bit11_I = rem(floor(real(2048+s(:,chan))/2048),2);
bit11_Q = rem(floor(imag((2048*j)+s(:,chan))/2048),2);
bit11_IQ = zeros(1,2*length(bit11_I));
bit11_IQ(1:2:end) = bit11_I;
bit11_IQ(2:2:end) = bit11_Q;
plot(500*bit11_IQ,'k')
axis([0 76800 -1000 1000])
vlen=76800
chan=2
gainimb_rx = -0.0020; phaseimb_rx = -2.38; % ExMIMO1 / lime1, VGAgain2 = 0, 1.9 GHz
gainimb_rx = 0.55; phaseimb_rx = 24.3; % ExMIMO1 / lime1, VGAgain2 = 0, 1.9 GHz
phaseimb_rx = phaseimb_rx/180*pi; % phaser imb in radians
beta_rx = (1/2)*(1 + (1+ gainimb_rx) * exp(1i*phaseimb_rx));
alpha_rx = (1/2)*(1 - (1+ gainimb_rx) * exp(-1i*phaseimb_rx));
den=abs(beta_rx)^2-abs(alpha_rx)^2;
beta_rx=beta_rx/den;
alpha_rx=alpha_rx/den;
s2 = beta_rx.*s + alpha_rx.*conj(s);
hold off ; plot(20*log10(abs(fftshift(fft(s2(:,chan)))))); grid on;
dual_tx=0;
eNBflag = 0;
card=0;
limeparms;
%% acquisition
%rf_mode = ( RXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM + RXOUTSW )*[1 1 0 0];
rf_mode = ( RXEN + TXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM )*[1 1 1 1];
% internal loopback test
%rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1)*[1 1 0 0];
%rf_mode = (RXEN+ TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1)*[1 1 1 1];
%rf_mode = [0 0 0 0];
%% Select DMA directions
rf_mode = rf_mode + (DMAMODE_RX + DMAMODE_TX)*[1 0 0 0];
freq_rx = (1907600000 - 0*9000)*[1 1 1 1];
%rf_local= [rfl(56,56,31,31) rfl(16,12,31,31) rfl(36,48,31,31) rfl(32,20,31,31)]; % 1.9 GHz, Exmimo2-No1, lime_cal_exmimo
%rf_local= [rfl(34,40,31,31) rfl(20,25,38,21) rfl(12,38,21,14) rfl(31,19,36, 6)]; % 1.9 GHz, Exmimo2-No1, LIME GUI
rf_local= [rfl(32,36,26,25) rfl(20,25,37,21) rfl(12,38,21,14) rfl(31,19,36, 6)];
rf_vcocal=(( 0xE)*(2^6)) + ( 0xE)*[1 1 1 1]; % 1.907 GHz, (OLD)
freq_tx = freq_rx + 000000; % 1kHz offset: @30 MSPS: 2.5 sines, @15 MSPS: 5 sines, @7 MSPS: 10 sines
rf_rxdc = rf_rxdc*[1 1 1 1];
tx_gain = 13*[1 1 1 1]; rx_gain = 25*[1 1 1 1]; amp=32000;
%tx_gain = 25*[1 1 1 1]; rx_gain = 0*[1 1 1 1]; amp=32000;
oarf_config_exmimo(card,freq_rx,freq_tx,0,dual_tx,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal);
sleep(1);
% create_testvector
vlen=76800
chan=1
v=0000*exp(-i*(3*[0:vlen-1]/vlen)*2*pi); v=[v;v]'; oarf_send_frame(card,v,16); sleep(0.2);
s = oarf_get_frame(card); figure ; plot(real(s(:,chan)),'b-.',"markersize",2) ; hold on ; plot(imag(s(:,chan)),'r-.',"markersize",2);
s = s(:,chan) - mean(s(:,chan)); % remove DC
e_s0 = sum( s' * s )
v=amp*exp(-i*(10000*[0:vlen-1]/vlen)*2*pi); e_v=sum(v*v'); v=[v;v]'; oarf_send_frame(card,v,16); sleep(0.2);
s = oarf_get_frame(card); figure ; plot(real(s(:,chan)),'b-.',"markersize",2) ; hold on ; plot(imag(s(:,chan)),'r-.',"markersize",2);
s = s(:,chan) - mean(s(:,chan)); % remove DC
figure; plot(20*log10(fftshift(abs(fft(s))))); grid on;
e_v
e_s = sum( s' * s )
s_over_s0_db = 10*log10( e_s / e_s0 )
dual_tx=0;
eNBflag = 0;
card=0;
limeparms;
%% acquisition
%rf_mode = ( RXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM + RXOUTSW )*[1 1 0 0];
rf_mode = ( TXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM )*[1 1 0 0];
% internal loopback test
%rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1)*[1 1 0 0];
%rf_mode = (RXEN+ TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1)*[1 1 1 1];
%rf_mode = [0 0 0 0];
%% Select DMA directions
rf_mode = rf_mode + (DMAMODE_TX)*[0 1 0 0];
freq_rx = (1907600000 - 0*9000)*[1 1 1 1];
%rf_local= [rfl(56,56,31,31) rfl(16,12,31,31) rfl(36,48,31,31) rfl(32,20,31,31)]; % 1.9 GHz, Exmimo2-No1, lime_cal_exmimo
%rf_local= [rfl(34,40,31,31) rfl(20,25,38,21) rfl(12,38,21,14) rfl(31,19,36, 6)]; % 1.9 GHz, Exmimo2-No1, LIME GUI
%rf_local= [rfl(32,36,26,25) rfl(20,25,37,21) rfl(12,38,21,14) rfl(31,19,36, 6)];
rf_local= [rfl(33,36,26,25) rfl(20,24,37,21) rfl(12,38,21,14) rfl(31,19,36, 6)];
rf_vcocal=(( 0xE)*(2^6)) + ( 0xE)*[1 1 1 1]; % 1.907 GHz, (OLD)
freq_tx = freq_rx + 000000; % 1kHz offset: @30 MSPS: 2.5 sines, @15 MSPS: 5 sines, @7 MSPS: 10 sines
rf_rxdc = rf_rxdc*[1 1 1 1];
tx_gain = 20*[1 1 1 1]; rx_gain = 25*[1 1 1 1]; amp=10000;
%tx_gain = 25*[1 1 1 1]; rx_gain = 0*[1 1 1 1]; amp=32000;
oarf_config_exmimo(card, freq_rx,freq_tx,0,dual_tx,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal);
sleep(1);
% create_testvector
vlen=76800
chan=1
%v=0000*exp(-i*(3*[0:vlen-1]/vlen)*2*pi); v=[v;v]'; oarf_send_frame(card,v,16); sleep(0.2);
%s = oarf_get_frame(card); figure ; plot(real(s(:,chan)),'b-.',"markersize",2) ; hold on ; plot(imag(s(:,chan)),'r-.',"markersize",2);
% create_testvector
vlen=76800
chan=1
amp=10000
%v=0000*exp(-i*(3*[0:vlen-1]/vlen)*2*pi); v=[v;v]'; oarf_send_frame(card,v,16); sleep(0.2);
%s = oarf_get_frame(card); figure ; plot(real(s(:,chan)),'b-.',"markersize",2) ; hold on ; plot(imag(s(:,chan)),'r-.',"markersize",2);
v=amp*exp(-i*(10000*[0:vlen-1]/vlen)*2*pi); v=[v;v]';
%for gainimb_tx = -0.05:0.01:0.05
%for phaseimb_tx= -5:1:5
gainimb_tx = -0.028; % gain imabalance of modulator in linear scale
phaseimb_tx = 3.0; % phase imbalance of modulator in degrees
gainimb_tx = -0.028; phaseimb_tx = 3.0; % for exmimo2-1 lime1
phaseimb_tx = phaseimb_tx/180*pi; % phaser imb in radians
beta_tx = (1/2)*(1 + (1+ gainimb_tx) * exp(1i*phaseimb_tx));
alpha_tx = (1/2)*(1 - (1+ gainimb_tx) * exp(-1i*phaseimb_tx));
den=abs(beta_tx)^2-abs(alpha_tx)^2;
beta_tx=beta_tx/den;
alpha_tx=alpha_tx/den;
v = beta_tx.*v + alpha_tx.*conj(v);
sleep(0.5); oarf_send_frame(card,v,16);
% Basic configuration script for ExpressMIMO-1 and ExpressMIMO-2
% Some functions are only available on ExpressMIMO-2!
limeparms;
eNBflag = 0;
card=0;
tdd_config = TXRXSWITCH_LSB;
%tdd_config = TXRXSWITCH_TESTTX;
syncmode = SYNCMODE_FREE;
%% acquisition
%rf_mode = ( RXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM + RXOUTSW )*[1 1 0 0];
rf_mode = ( RXEN + TXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM )*[ 1 0 0 0 ];
%rf_mode = rf_mode + (RXEN+TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM )*[ 0 1 0 0 ];
% internal loopback test
%rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1)*[1 1 0 0];
%rf_mode = (RXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA.1ON+LNAByp+RFBBLNA1)*[1 1 1 1];
%rf_mode = [0 0 0 0];
%% Select DMA directions
%rf_mode = rf_mode + (DMAMODE_RX)*[0 1 0 0];
%rf_mode = rf_mode + (DMAMODE_RX)*[0 0 1 1];
%rf_mode = rf_mode + (DMAMODE_TX)*[1 1 0 0];
rf_mode = rf_mode + (DMAMODE_RX + DMAMODE_TX)*[ 1 0 0 0 ];
%rf_mode = rf_mode + (DMAMODE_RX )*[0 1 0 0];
%rf_mode = rf_mode + (DMAMODE_TX)*[1 0 0 0]; rf_mode = rf_mode + (DMAMODE_RX)*[0 1 0 0];
%freq_rx = 749600000*[1 1 1 1];
%rf_local= [8255004 8253440 8257340 8257340]; % 700 MHz
%rf_vcocal=((0x24)*(2^6)) + (0x24)*[1 1 1 1]; % 700 MHz
freq_rx = (1907600000 - 0*9000)*[1 1 1 1];
%rf_local= [rfl( 0, 0,31,31) rfl(28,44,31,31) rfl(60,60,31,31) rfl(60,60,31,31)]; % 1.9 GHz, OLD
%rf_local= [rfl(56,56,31,31) rfl(16,12,31,31) rfl(36,48,31,31) rfl(32,20,31,31)]; % 1.9 GHz, Exmimo2-No1, lime_cal_exmimo
%rf_local= [rfl(34,40,31,31) rfl(20,25,38,21) rfl(12,38,21,14) rfl(31,19,36, 6)]; % 1.9 GHz, Exmimo2-No1, LIME GUI
rf_local= [rfl(20,25,26,04) rfl(20,25,26,04) 0 0]; % 1.9 GHz & 860 MHz, VGA2Gain=0
%rf_local= [0 rfl(20,25,38,21) 0 0 ]; % 1.9 GHz, VGA2Gain=30
rf_vcocal=(( 0xE)*(2^6)) + ( 0xE)*[1 1 1 1]; % 1.907 GHz, (OLD)
%rf_vcocal=((0x14)*(2^6)) + (0x13)*[1 1 1 1]; % 1.907 GHz, RX(msbs)+ TX(lsbs), RX:0xC..0x14, TX:0xB..0x13 (ExMIMO2-No1)
%rf_vcocal=((0x12)*(2^6)) + (0x10)*[1 1 1 1]; % 1.917 GHz, RX(msbs)+ TX(lsbs), RX:0xD..0x16, TX:0xC..0x14 (ExMIMO2-No1)
%freq_rx = ( 860000000 - 0*9000)*[1 1 1 1];
%rf_vcocal=((0x1d)*(2^6)) + (0x1d)*[1 1 1 1]; % 860 MHz
freq_tx = freq_rx + 0000000; % 1kHz offset: @30 MSPS: 2.5 sines, @15 MSPS: 5 sines, @7 MSPS: 10 sines
tx_gain = 13*[1 1 1 1];
rx_gain = 20*[1 1 1 1];
rf_rxdc = rf_rxdc*[1 1 1 1];
rffe_rxg_low = 63*[1 1 1 1];
rffe_rxg_final = 63*[1 1 1 1];
rffe_band = TVWS_TDD*[1 1 1 1];
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band)
%sleep(0.2)
% stuff for I/Q imbalance correction on RX
%gainimb_rx = -0.0020; phaseimb_rx = -2.38; % RX IQ imbal. ExMIMO1 / lime1, VGAgain2 = 0, 1.9 GHz
gainimb_rx = -0.0030; phaseimb_rx = -2.38; % RX IQ imbal. ExMIMO1 / lime1, VGAgain2 = 30, 1.9 GHz
phaseimb_rx = phaseimb_rx/180*pi; % phaser imb in radians
beta_rx = (1/2)*(1 + (1+ gainimb_rx) * exp(1i*phaseimb_rx));
alpha_rx = (1/2)*(1 - (1+ gainimb_rx) * exp(-1i*phaseimb_rx));
den=abs(beta_rx)^2-abs(alpha_rx)^2;
beta_rx=beta_rx/den;
alpha_rx=alpha_rx/den;
% create_testvector
vlen=76800
%v=10000*exp(-i*2*pi*1/7.68*[0:vlen-1]); v=[v;v]'; oarf_send_frame(card,v,16);
%v=([2:1+vlen; 10002:10001+vlen] - i*[3:2+vlen; 10003:10002+vlen])';
%v=32767*(1+i)*ones(vlen,2); oarf_send_frame(card,v,16);
%v = floor(( [640:639+vlen ; 640:639+vlen] / 5 ))'; oarf_send_frame(card,v,16);
%v = floor(( [75000:-1:75001-vlen ; 75000:-1:75001-vlen] / 5 ))'; oarf_send_frame(card,v,16);
%v=i*2^11*ones(vlen,2)+2^11*ones(vlen,2); oarf_send_frame(card,v,16);
%v=15000*exp(-i*2*pi*1/7.68*[0:vlen-1]); v=[v;v]'; oarf_send_frame(card,v,16);
%v=10000*exp(-i*(3000*[0:vlen-1]/vlen)*2*pi); v=[v;v]'; oarf_send_frame(card,v,16);
%v=20000*exp(-i*pi*(0:vlen-1)/2); v=[v;v]'; oarf_send_frame(card,v,16);
% Set LSB to RX (,1) or to TX(,0)
%v=10000*m'.*exp(-i*(50*[0:vlen-1]/vlen)*2*pi); v=bitset(real(v),1,0) + i*bitset(imag(v),1,0); v=[v;v]'; oarf_send_frame(card,v,16);
v2=15000*sin((1:vlen)/vlen*2*pi); v2=[v2;v2]';
v=15000*exp(i*2*pi*1/7.68*[1:vlen]); v=[v;v]';
%oarf_send_frame(card,v,16);
%len=1000;off=0; chan=2; s=oarf_get_frame(card); hold off ; plot(real(s(off+1:off+len,chan)),'-o',"markersize",2) ; hold on ; plot(imag(s(off+1:off+len,chan)),'r-o',"markersize",2)
%chan=1; s = oarf_get_frame(card); hold off ; plot(real(s(:,chan)),'b-o',"markersize",2) ; hold on ; plot(imag(s(:,chan)),'r-o',"markersize",2)
%while 1;len=5000;off=0; chan=1; s = oarf_get_frame(card); hold off ; plot(real(s(off+1:off+len,chan)),'-o',"markersize",2) ; hold on ; plot(imag(s(off+1:off+len,chan)),'r-o',"markersize",3); sleep(0.3);endwhile
%chan=2; s=oarf_get_frame(card); s=s-0.99999*mean(s(:,chan)); s = beta_rx.*s + alpha_rx.*conj(s); hold off ; plot(20*log10(abs(fftshift(fft(s(:,chan)))))); grid on; min_r=min(real(s(:,chan))); min_i=min(imag(s(:,chan))); max_r=max(real(s(:,chan))); max_i=max(imag(s(:,chan))); disp("Min-I/Q Max-I/Q"); disp([min_r min_i max_r max_i]);
%chan=2; s=oarf_get_frame(card); s=s-0.99999*mean(s(:,chan)); s = beta_rx.*s + alpha_rx.*conj(s); hold off ; plot(20*log10(abs(fftshift(fft(hamming(vlen).*s(:,chan)))))); grid on; min_r=min(real(s(:,chan))); min_i=min(imag(s(:,chan))); max_r=max(real(s(:,chan))); max_i=max(imag(s(:,chan))); disp("Min-I/Q Max-I/Q"); disp([min_r min_i max_r max_i]);
% Switch off limes
limeparms;
eNBflag = 0;
card=-1;
tdd_config = TXRXSWITCH_LSB;
%tdd_config = TXRXSWITCH_TESTTX;
syncmode = SYNCMODE_FREE;
rf_mode = [0 0 0 0];
%% Select DMA directions
rf_mode = rf_mode + (DMAMODE_RX + DMAMODE_TX)*[ 1 0 0 0 ];
rf_mode = rf_mode + (DMAMODE_RX )*[0 1 0 0];
freq_rx = (1907593260)*[1 1 1 1];
rf_local= [0 0 0 0 ];
rf_vcocal=(( 0xE)*(2^6)) + ( 0xE)*[1 1 1 1]; % 1.907 GHz, (OLD)
freq_tx = freq_rx + 0000000; % 1kHz offset: @30 MSPS: 2.5 sines, @15 MSPS: 5 sines, @7 MSPS: 10 sines
tx_gain = 13*[1 1 1 1];
rx_gain = 10*[1 1 1 1];
rf_rxdc = (1 + 1*(2^8))*[1 1 1 1]; % I:LSB, Q:MSB
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal)
oarf_stop(-1);
%sleep(0.2)
% Basic configuration script for ExpressMIMO-1 and ExpressMIMO-2
% Some functions are only available on ExpressMIMO-2!
limeparms;
eNBflag = 0;
card=0;
tdd_config = TXRXSWITCH_LSB;
%tdd_config = TXRXSWITCH_TESTTX;
tdd_config += TEST_ADACLOOP_EN;
syncmode = SYNCMODE_FREE;
%% acquisition
%rf_mode = ( RXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM + RXOUTSW )*[1 1 0 0];
rf_mode = ( RXEN + TXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM )*[ 1 1 0 0 ];
%% Select DMA directions
rf_mode = rf_mode + (DMAMODE_RX + DMAMODE_TX)*[ 1 0 0 0 ];
rf_mode = rf_mode + (DMAMODE_TX )*[0 1 0 0];
freq_rx = (1907600000)*[1 1 1 1];
rf_local= [rfl(20,25,26,04) rfl(20,25,26,04) 0 0]; % 1.9 GHz & 860 MHz, VGA2Gain=0
rf_vcocal=(( 0xE)*(2^6)) + ( 0xE)*[1 1 1 1]; % 1.907 GHz, (OLD)
freq_tx = freq_rx + 0000000; % 1kHz offset: @30 MSPS: 2.5 sines, @15 MSPS: 5 sines, @7 MSPS: 10 sines
tx_gain = 13*[1 1 1 1];
rx_gain = 20*[1 1 1 1];
rf_rxdc = (1 + 1*(2^8))*[1 1 1 1]; % I:LSB, Q:MSB
rffe_rxg_low = 61*[1 1 1 1];
rffe_rxg_final = 61*[1 1 1 1];
rffe_band = B19G_TDD*[1 1 1 1];
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band)
% create_testvector
vlen=76800
v = floor(( [ (201:200+60000) - i*(101:100+60000) ] ))' - (30000+i*30000);
v = [v; floor(( [ (201:200+vlen-60000) - i*(101:100+vlen-60000) ] ))' - (30000+i*30000) ];
%v=([11:10+vlen] - i*[101:100+vlen])'; % attention, doesn't wrap!
%v=15000*exp(-i*2*pi*1/7.68*[0:vlen-1])';
v2=30000*(1+i)*ones(vlen,2);
oarf_send_frame(card,[v v2],16);
sleep(2); % need this, otherwise, get_frame will return garbage sometimes
%len=1000;off=0; chan=2; hold off ; plot(real(s(off+1:off+len,chan)),'-o',"markersize",2) ; hold on ; plot(imag(s(off+1:off+len,chan)),'r-o',"markersize",2)
chan=1; s = oarf_get_frame(card); hold off ; grid on; plot(real(s(:,chan)),'b-o',"markersize",2) ; hold on ; plot(imag(s(:,chan)),'r-o',"markersize",2)
% Try out multicard setup
limeparms;
eNBflag = 0;
tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB;
rf_mode = ( RXEN + TXEN + TXLPFNORM + TXLPFEN + TXLPF25 + RXLPFNORM + RXLPFEN + RXLPF25 + LNA1ON +LNAMax + RFBBNORM )*[1 0 0 0];
rf_mode = rf_mode + (DMAMODE_RX + DMAMODE_TX)*[1 0 0 0];
freq_rx = (1908600000 - 0*9000)*[1 1 1 1];
freq_tx = freq_rx + 0000000; % 1kHz offset: @30 MSPS: 2.5 sines, @15 MSPS: 5 sines, @7 MSPS: 10 sines
rf_local= [ rfl(20,25,26,04) 0 0 0 ]; % 1.9 GHz & 860 MHz, VGA2Gain=0
rf_vcocal=(( 0xE)*(2^6)) + ( 0xE)*[1 1 1 1]; % 1.907 GHz, (OLD)
tx_gain = 13*[1 1 1 1];
rx_gain = 20*[1 1 1 1];
rf_rxdc = rf_rxdc*[1 1 1 1];
% set first card to slave mode
card=1; % -1 for all cards
syncmode = SYNCMODE_SLAVE;
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal)
sleep(1)
% set second card to master mode
card=0; % -1 for all cards
syncmode = SYNCMODE_MASTER;
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal)
sleep(1)
% create_testvector
vlen=76800
%v=5000*exp(-i*(300*[0:vlen-1]/vlen)*2*pi); v=[v;v;v;v]'; oarf_send_frame(0,v,16);
%v=5000*exp(-i*( 30*[0:vlen-1]/vlen)*2*pi); v=[v;v;v;v]'; oarf_send_frame(1,v,16);
%len=1000;off=0; chan=2; s=oarf_get_frame(card); hold off ; plot(real(s(off+1:off+len,chan)),'-o',"markersize",2) ; hold on ; plot(imag(s(off+1:off+len,chan)),'r-o',"markersize",2)
%while 1;len=5000;off=0; chan=1; s = oarf_get_frame(card); hold off ; plot(real(s(off+1:off+len,chan)),'-o',"markersize",2) ; hold on ; plot(imag(s(off+1:off+len,chan)),'r-o',"markersize",3); sleep(0.3);endwhile
%while 1;len=vlen;off=0; chan=[1 5]; s = oarf_get_frame(-1); hold off ; plot(real(s(off+1:off+len,chan)),'-o',"markersize",2) ; hold on ; plot(imag(s(off+1:off+len,chan)),'r-o',"markersize",3); sleep(0.5);endwhile
v = 5000* [ zeros(1,1000) ones(1,500) zeros(1,500) ones(1,1) zeros(1,vlen-1000-1000-1)]; v=[v;v;v;v]'; oarf_send_frame(1,v,16);
sleep(1)
len=2500;off=0; chan=[1 5]; s = oarf_get_frame(-1); hold off ; plot(real(s(off+1:off+len,chan)),'-o',"markersize",2) ; hold on ; plot(imag(s(off+1:off+len,chan)),'r-o',"markersize",2);
dual_tx=0;
eNBflag = 0;
card=0;
limeparms;
% internal loopback test
rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF5+RXLPFNORM+RXLPFEN+RXLPF5+LNA1ON+LNAByp+RFBBLNA1)*[1 1 0 0];
%rf_mode = [0 0 0 0];
%% Select DMA directions
%rf_mode = rf_mode + (DMAMODE_RX)*[1 0 0 0 ];
%rf_mode = rf_mode + (DMAMODE_RX)*[1 1 0 0];
%rf_mode = rf_mode + (DMAMODE_TX)*[1 1 0 0];
%rf_mode = rf_mode + (DMAMODE_RX + DMAMODE_TX)*[1 0 0 0];
rf_mode = rf_mode + (DMAMODE_RX + DMAMODE_TX)*[1 0 0 0];
freq_rx = 1907600000*[1 1 1 1];
rf_local= [8254744 8255063 8257340 8257340]; % 1.9 GHz
rf_vcocal=((0xE)*(2^6)) + (0xE)*[1 1 1 1]; % 1.9 GHz
freq_tx = freq_rx + 1;
tx_gain = 25*[1 1 1 1];
rx_gain = 20*[1 1 1 1];
rf_rxdc = rf_rxdc*[1 1 1 1];
oarf_config_exmimo(card, freq_rx,freq_tx,0,dual_tx,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal)
% create_testvector
vlen=76800
%v=([2:1+vlen; 10002:10001+vlen] - i*[3:2+vlen; 10003:10002+vlen])'; % achtung, wrapped nicht!
v = floor(( [640:639+vlen ; 640:639+vlen] / 5 ))';
break
sleep(5)
oarf_send_frame(card,v,16);
%len=1000;off=0; chan=2; hold off ; plot(real(s(off+1:off+len,chan)),'-o',"markersize",2) ; hold on ; plot(imag(s(off+1:off+len,chan)),'r-o',"markersize",2)
chan=1; s = oarf_get_frame(card); hold off ; plot(real(s(:,chan)),'b',"markersize",1) ; % hold on ; plot(imag(s(:,chan)),'r',"markersize",1)
This diff is collapsed.
close all
clear all
hold off
card = 0;
% Maxime Guillaud - created Wed May 10 18:08:04 CEST 2006
gpib_card=0; % first GPIB PCI card in the computer
gpib_device=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu
cables_loss_dB = 6; % we need to account for the power loss between the signal generator and the card input (splitter, cables)
dual_tx = 0;
tdd = 1;
fc = 1907600e3; % this has to be the same as in the config file
fs = 7680e3;
%fs = 6500e3;
fref = fc+fs/4;
power_dBm=-70;
f_off_min = 1e6;
limeparms;
%rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM)*[1 1 1 1];
rf_mode = (RXEN+0+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM+DMAMODE_RX+0)*[1 0 0 0];
freq_rx = fc*[1 0 0 0];
freq_tx = freq_rx+1920000;
rx_gain = 30*[1 1 1 1];
tx_gain = 25*[1 1 1 1];
%rf_local=rf_local*[1 1 1 1];
rf_local = [8254813 8255016 8254813 8254813]; %exmimo2_2
%rf_rxdc =rf_rxdc*[1 1 1 1];
rf_rxdc = [37059 35459 36300 36999]; %exmimo2_2
rf_vcocal=rf_vcocal_19G*[1 1 1 1];
tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB;
syncmode = SYNCMODE_FREE;
rffe_rxg_low = 63*[1 1 1 1];
rffe_rxg_final = 63*[1 1 1 1];
rffe_band = B19G_TDD*[1 1 1 1];
%gpib_send(gpib_card,gpib_device,'*RST;*CLS'); % reset and configure the signal generator
%gpib_send(gpib_card,gpib_device,['POW ' int2str(power_dBm+cables_loss_dB) 'dBm']);
%gpib_send(gpib_card,gpib_device,['FREQ 1.91860 Ghz']); % set the frequency
%gpib_send(gpib_card,gpib_device,['FREQ ' int2str(fref/1e3) 'khz']); % set the frequency
%gpib_send(gpib_card,gpib_device,'OUTP:STAT ON'); % activate output
%keyboard;
sleep(2)
step = 4096;
i=0;
do
format long
fc
freq_rx = fc*[1 0 0 0];
freq_tx = freq_rx+1920000;
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,0,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
i=i+1;
sleep(1);
s=oarf_get_frame(card); %oarf_get_frame
nb_rx = 1; %size(s,2);
% find the DC component
m = mean(s);
s_phase = unwrap(angle(s(10000:4:length(s),1).'));
s_phase = s_phase - s_phase(1,1);
f_off = mean(s_phase(2:length(s_phase))*fs/4./(1:(length(s_phase)-1))/2/pi)
plot(1:length(s_phase),s_phase,'r');
if (nb_rx>1)
s_phase2 = unwrap(angle(s(10000:4:length(s),2).'));
s_phase2 = s_phase2 - s_phase2(1,1);
f_off2 = mean(s_phase2(2:length(s_phase2))*fs/4./(1:(length(s_phase2)-1))/2/pi)
hold on
plot(1:length(s_phase2),s_phase2,'g');
drawnow;
hold off
end
if (abs(f_off) < f_off_min)
f_off_min = abs((f_off));
end
if ((f_off) > 0)
fc = fc + step;
else
fc = fc - step;
endif
step = step/2;
until (step < 50)
%gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
cd openair1
cd PHY
cd LTE_ESTIMATION/
ls
pwd
cd ..
cd LTE_REFSIG/
ls
primary_synch
primary_synch0_time
pss0_up = upsample(primary_synch0_time,4);
size(pss_up)
size(pss0_up)
pss0_up_cp = [pss0_up(512-128:end) pss0_up];
size(pss0_up_cp)
pss0_up_cp = [pss0_up(512-127:end) pss0_up];
size(pss0_up_cp)
plot(real(pss0_up_cp))
pss0_up = interp(primary_synch0_time,4);
pss0_up_cp = [pss0_up(512-127:end) pss0_up];
plot(real(pss0_up_cp))
pss0_up_cp = [pss0_up(512-127:end) pss0_up]*1024;
plot(real(pss0_up_cp))
s2 = s;
s2(1:640,1) = pss0_up_cp;
plot(real(s))
plot(real(s2))
// Maxime Guillaud - created Wed May 10 19:23:30 CEST 2006
// see http://www.gnu.org/software/octave/doc/interpreter/Dynamically-Linked-Functions.html#Dynamically-Linked-Functions
// and http://octave.sourceforge.net/coda/c58.html
// compile with: mkoctfile -I/usr/local/include/gpib -lgpib gpib_send.cc
#include <octave/oct.h>
#include "ib.h"
static bool any_bad_argument(const octave_value_list &args)
{
if (args.length()!=3)
{
error("gpib_send: syntax: gpib_send(gpib_board,gpib_device,gpib_str).");
return true;
}
if (!args(0).is_real_scalar())
{
error("gpib_send: GPIB board number must be a positive integer.");
return true;
}
if (args(0).scalar_value() < 0.0)
{
error("gpib_send: GPIB board number must be a positive integer.");
return true;
}
if (floor(args(0).scalar_value()) != args(0).scalar_value())
{
error("gpib_send: GPIB board number must be a positive integer.");
return true;
}
if (!args(1).is_real_scalar())
{
error("gpib_send: GPIB device number must be a positive integer.");
return true;
}
if (args(1).scalar_value() < 0.0)
{
error("gpib_send: GPIB device number must be a positive integer.");
return true;
}
if (floor(args(1).scalar_value()) != args(1).scalar_value())
{
error("gpib_send: GPIB device number must be a positive integer.");
return true;
}
if (!args(2).is_string())
{
error("gpib_send: third parameter must be a char string.");
return true;
}
return false;
}
DEFUN_DLD (gpib_send, args, nargout,"sends commands to the GPIB bus")
{
if (any_bad_argument(args))
return octave_value_list();
const int gpib_board = args(0).int_value();
const int gpib_device = args(1).int_value();
const std::string gpib_string = args(2).string_value();
unsigned short addlist[2] = {gpib_device, NOADDR};
SendIFC(gpib_board);
// ENABLE all on GPIB bus
EnableRemote(gpib_board, addlist);
// If error, Bye!
if (ibsta & ERR)
{
error("gpib_send: Instrument enable failed!");
return octave_value_list();
}
Send(gpib_board, gpib_device, gpib_string.c_str(), strlen(gpib_string.c_str()), NLend);
if (ibsta & ERR)
{
error("gpib_send: Send failed!");
return octave_value_list();
}
return octave_value_list();
}
%clear all
%close all
addpath([getenv('OPENAIR1_DIR') '/PHY/LTE_REFSIG/']);
addpath([getenv('OPENAIR1_DIR') '/PHY/LTE_TRANSPORT/']);
primary_synch; %loads the primary sync signal
%sss_gen; %loads the secondary sync signal
% grab a frame
% load frame
%addpath([getenv('OPENAIR_TARGETS') '/SIMU/USER/']);
%eNBtxsig1
%keyboard
%figure(1)
%plot(real(s))
%pss_t = upsample(primary_synch0_time,4);
primary_synch;
primary_synch0_time;
pss0_up = interp(primary_synch0_time,4);
pss0_up_cp = [pss0_up(512-127:end) pss0_up];
% plot(real(pss0_up_cp))
pss0_up_cp = [pss0_up(512-127:end) pss0_up]*1024;
% plot(real(pss0_up_cp))
pss_t = pss0_up_cp;
s = receivedA2B1;
[corr,lag] = xcorr(s(:,1).',pss_t.');
[pss_amp, pss_pos0] = max(abs(corr));
pss_pos = lag(pss_pos0);
pss_ref=pss_pos;
frame_start=pss_ref
# % Author: Mirsad Cirkic
# % Organisation: Eurecom (and Linkoping University)
# % E-mail: mirsad.cirkic@liu.se
addpath('/homes/kaltenbe/Devel/openair/openair4G/trunk/targets/ARCH/EXMIMO/USERSPACE/OCTAVE');
%clear
paramsinitialized=false;
limeparms;
rxgain=0;
txgain=10;
eNB_flag = 0;
card = 0;
Ntrx=4;
dual_tx=0;
active_rfA=[0 0 0 0];
active_rfB=[1 1 1 1];
active_rf=active_rfA+active_rfB;
if(active_rfA*active_rfB'!=0) error("The A and B transceive chains must be orthogonal./n") endif
%fc = 2660000000;
fc = 1917600000;
%fc = 859.5e6;
autocal_mode=active_rf;
%rf_mode=(RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1) * active_rf;
%rf_mode=(TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM) * active_rf;
% we have to enable both DMA transfers so that the switching signal in the LSB of the TX buffer gets set
rf_mode=(TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM+DMAMODE_TX+TXEN+DMAMODE_RX+RXEN) * active_rf;
tdd_config = DUPLEXMODE_FDD+TXRXSWITCH_TESTRX; LSBSWITCH_FLAG=false; %we also need the LSB switching for the woduplex script, otherwise we don't receive anything
%tdd_config = DUPLEXMODE_FDD+TXRXSWITCH_LSB; LSBSWITCH_FLAG=true;
syncmode = SYNCMODE_FREE;
rf_local = [8254744 8255063 8257340 8257340]; %eNB2tx 1.9GHz
rf_vcocal=rf_vcocal_19G*active_rf;
rffe_rxg_low = 61*active_rf;
rffe_rxg_final = 61*active_rf;
rffe_band = B19G_TDD*active_rf;
rf_rxdc = rf_rxdc*active_rf;
freq_rx = fc*active_rf;
freq_tx = freq_rx; %+1.92e6;
tx_gain = txgain.*active_rf;
rx_gain = rxgain*active_rf;
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNB_flag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band,autocal_mode);
autocal_mode=0*active_rf; % Autocalibration is only needed the first time we conf. exmimo
amp = pow2(14)-1;
n_bit = 16;
chanest_full = 1;
paramsinitialized=true;
clear;
card=0;
limeparms;
TX_LO_LEAKAGE_MIN0 = 99999;
TX_LO_LEAKAGE_MIN1 = 99999;
%freq_rx = 1907588000*[1 1 1 1];
freq_rx = 859500000*[1 1 1 1];
freq_tx = freq_rx; %+1920000;
rf_vcocal = rf_vcocal_859*[1 1 1 1];
rf_rxdc = rf_rxdc*[1 1 1 1];
rxgain = 30*[1 1 1 1];
txgain = 25*[1 1 1 1];
tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB;
syncmode = SYNCMODE_FREE;
rffe_rxg_low = 31*[1 1 1 1];
rffe_rxg_final = 31*[1 1 1 1];
rffe_band = TVWS_TDD*[1 1 1 1];
sleepafterconfig=0.2
% coarse calibration loop for both rx chains
for txdc_I=0:4:63
for txdc_Q=0:4:63
rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1)*[1 1 0 0];
rf_mode = rf_mode + (DMAMODE_RX+DMAMODE_TX)*[1 1 0 0];
rf_local = (txdc_I + (txdc_Q)*(2^6) + 31*(2^12) + 31*(2^18))*[1 1 1 1];
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rxgain,txgain,0,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
sleep(sleepafterconfig)
s=oarf_get_frame(card);
sF0 = 20*log10(abs(fftshift(fft(s(:,1)))));
sF1 = 20*log10(abs(fftshift(fft(s(:,2)))));
f = (7.68*(0:length(s(:,1))-1)/(length(s(:,1))))-3.84;
spec0 = sF0;
spec1 = sF1;
RX_LO_LEAKAGE0 = sF0(1+(length(sF0)/2));
TX_LO_LEAKAGE0 = sF0(1+(.75*length(sF0)));
TX_SIG0 = sF0(1+((11/16)*length(sF0)));
TX_IQ0 = sF0(1+((13/16)*length(sF0))) - TX_SIG0;
RX_IQ0 = sF0(1+((5/16)*length(sF0))) - TX_SIG0;
RX_LO_LEAKAGE1 = sF1(1+(length(sF0)/2));
TX_LO_LEAKAGE1 = sF1(1+(.75*length(sF0)));
TX_SIG1 = sF1(1+((11/16)*length(sF0)));
TX_IQ1 = sF1(1+((13/16)*length(sF0))) - TX_SIG1;
RX_IQ1 = sF1(1+((5/16)*length(sF0))) - TX_SIG1;
% subplot(211)
% plot(f',spec0,'r')
% axis([-3.84,3.84,40,160])
% subplot(212)
% plot(f',spec1,'b')
% axis([-3.84,3.84,40,160])
% grid
% drawnow
if (TX_LO_LEAKAGE0 < TX_LO_LEAKAGE_MIN0)
TX_LO_LEAKAGE_MIN0=TX_LO_LEAKAGE0;
txdc_I_min0 = txdc_I;
txdc_Q_min0 = txdc_Q;
TX_LO_LEAKAGE0
txdc_I_min0
txdc_Q_min0
fflush(stdout);
end
if (TX_LO_LEAKAGE1 < TX_LO_LEAKAGE_MIN1)
TX_LO_LEAKAGE_MIN1=TX_LO_LEAKAGE1;
txdc_I_min1 = txdc_I;
txdc_Q_min1 = txdc_Q;
TX_LO_LEAKAGE1
txdc_I_min1
txdc_Q_min1
fflush(stdout);
end
end
end
% fine calibration loop for RX1 (RX2 stays constant)
txdc_I_min02 = txdc_I_min0;
txdc_Q_min02 = txdc_Q_min0;
for deltaI = -3:3,
for deltaQ = -3:3,
txdc_I = txdc_I_min0 + deltaI;
txdc_Q = txdc_Q_min0 + deltaQ;
if (txdc_I>=0) && (txdc_Q>=0) && (txdc_I < 64) && (txdc_Q < 64)
% printf("txdc_IQ => (%d,%d)\n",txdc_I,txdc_Q);
% fflush(stdout);
rf_local(1) = txdc_I + (txdc_Q)*(2^6) + 31*(2^12) + 31*(2^18);
rf_local(2) = txdc_I_min1 + (txdc_Q_min1)*(2^6) + 31*(2^12) + 31*(2^18);
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rxgain,txgain,0,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
sleep(sleepafterconfig)
s=oarf_get_frame(card);
sF0 = 20*log10(abs(fftshift(fft(s(:,1)))));
spec0 = sF0;
spec1 = sF1;
RX_LO_LEAKAGE = sF0(1+(length(sF0)/2));
TX_LO_LEAKAGE = sF0(1+(.75*length(sF0)));
TX_SIG = sF0(1+((11/16)*length(sF0)));
TX_IQ = sF0(1+((13/16)*length(sF0))) - TX_SIG;
RX_IQ = sF0(1+((5/16)*length(sF0))) - TX_SIG;
% subplot(211)
% plot(f',spec0,'r')
% axis([-3.84,3.84,40,160])
% grid
% drawnow
if (TX_LO_LEAKAGE < TX_LO_LEAKAGE_MIN0)
TX_LO_LEAKAGE_MIN0=TX_LO_LEAKAGE;
txdc_I_min02 = txdc_I;
txdc_Q_min02 = txdc_Q;
TX_LO_LEAKAGE
txdc_I_min02
txdc_Q_min02
fflush(stdout);
end
end
end
end
% fine calibration loop for RX2 (RX1 stays constant)
txdc_I_min12 = txdc_I_min1;
txdc_Q_min12 = txdc_Q_min1;
for deltaI = -3:3,
for deltaQ = -3:3,
txdc_I = txdc_I_min1 + deltaI;
txdc_Q = txdc_Q_min1 + deltaQ;
if (txdc_I>=0) && (txdc_Q>=0) && (txdc_I < 64) && (txdc_Q < 64)
% printf("txdc_IQ => (%d,%d)\n",txdc_I,txdc_Q);
% fflush(stdout);
% rf_local = txdc_I_min02 + (txdc_Q_min02)*(2^6) + (txdc_I)*(2^12) + (txdc_Q)*(2^18);
rf_local(1) = txdc_I_min02 + (txdc_Q_min02)*(2^6) + 31*(2^12) + 31*(2^18);
rf_local(2) = txdc_I + (txdc_Q)*(2^6) + 31*(2^12) + 31*(2^18);
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rxgain,txgain,0,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
sleep(sleepafterconfig)
s=oarf_get_frame(card);
sF1 = 20*log10(abs(fftshift(fft(s(:,2)))));
spec1 = sF1;
RX_LO_LEAKAGE = sF1(1+(length(sF0)/2));
TX_LO_LEAKAGE = sF1(1+(.75*length(sF0)));
TX_SIG = sF1(1+((11/16)*length(sF0)));
TX_IQ = sF1(1+((13/16)*length(sF0))) - TX_SIG;
RX_IQ = sF1(1+((5/16)*length(sF0))) - TX_SIG;
% subplot(212)
% plot(f',spec1,'b')
% axis([-3.84,3.84,40,160])
% grid
% drawnow
if (TX_LO_LEAKAGE < TX_LO_LEAKAGE_MIN1)
TX_LO_LEAKAGE_MIN1=TX_LO_LEAKAGE;
txdc_I_min12 = txdc_I;
txdc_Q_min12 = txdc_Q;
TX_LO_LEAKAGE
txdc_I_min12
txdc_Q_min12
fflush(stdout);
end
end
end
end
TX_LO_LEAKAGE_MIN0
txdc_I_min02
txdc_Q_min02
TX_LO_LEAKAGE_MIN1
txdc_I_min12
txdc_Q_min12
rf_local(1) = txdc_I_min02 + (txdc_Q_min02)*(2^6) + 31*(2^12) + 31*(2^18);
rf_local(2) = txdc_I_min12 + (txdc_Q_min12)*(2^6) + 31*(2^12) + 31*(2^18);
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rxgain,txgain,0,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
sleep(sleepafterconfig)
s=oarf_get_frame(card);
sF0 = 20*log10(abs(fftshift(fft(s(:,1)))));
sF1 = 20*log10(abs(fftshift(fft(s(:,2)))));
spec0 = sF0;
spec1 = sF1;
RX_LO_LEAKAGE = sF0(1+(length(sF0)/2))
TX_LO_LEAKAGE = sF0(1+(.75*length(sF0)))
TX_SIG = sF0(1+((11/16)*length(sF0)))
TX_IQ = sF0(1+((13/16)*length(sF0))) - TX_SIG
RX_IQ = sF0(1+((5/16)*length(sF0))) - TX_SIG
RX_LO_LEAKAGE = sF1(1+(length(sF0)/2))
TX_LO_LEAKAGE = sF1(1+(.75*length(sF0)))
TX_SIG = sF1(1+((11/16)*length(sF0)))
TX_IQ = sF1(1+((13/16)*length(sF0))) - TX_SIG
RX_IQ = sF1(1+((5/16)*length(sF0))) - TX_SIG
subplot(211)
plot(f',spec0,'r')
subplot(212)
plot(f',spec1,'b')
axis([-3.84,3.84,40,160])
grid
drawnow
%gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % activate output
%legend('Antenna Port 0','Antenna Port 1');
grid
rf_local
clear all
close all
card=0;
limeparms;
%freq_rx = 1907588000*[1 1 1 1];
%freq_rx = 700600000*[1 1 1 1];
freq_rx = 748000000*[1 1 1 1];
freq_tx = freq_rx; %+1920000;
rxgain = 0*[1 1 1 1];
txgain = 0*[1 1 1 1];
tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB;
syncmode = SYNCMODE_FREE;
%rf_local = [8254813 8255016 8254813 8254813]; % from the tx calibration
%rf_local = [8255842 8255064 8257340 8257340]; % 700MHz
rf_local = [8256776 8255788 8257340 8257340]; % 850MHz
rf_rxdc = rf_rxdc*[1 1 1 1]; % initial value
rf_vcocal= rf_vcocal_850*[1 1 1 1];
rffe_rxg_low = 31*[1 1 1 1];
rffe_rxg_final = 31*[1 1 1 1];
rffe_band = TVWS_TDD*[1 1 1 1];
sleepafterconfig=0.2
% coarse calibration loop for both rx chains
for ant=1:4
rf_mode = zeros(1,4);
rf_mode(ant) = (RXEN+0+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM+DMAMODE_RX+0);
dc_off_re_min = 99999;
dc_off_im_min = 99999;
stepsize = 64;
rxdc_Q_s = 0;
rxdc_I = 0;
while (stepsize>=1)
stepsize = stepsize/2;
if (rxdc_I<0)
rxdc_I_s = 64+abs(rxdc_I);
else
rxdc_I_s = rxdc_I;
end
rf_rxdc = ((128+rxdc_I_s) + (128+rxdc_Q_s)*(2^8))*[1 1 1 1];
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rxgain,txgain,0,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
sleep(sleepafterconfig)
s=oarf_get_frame(card);
figure(1)
plot(real(s));
ylim([-2048 2048]);
drawnow;
%sF0 = 20*log10(abs(fftshift(fft(s(:,1)))));
%sF1 = 20*log10(abs(fftshift(fft(s(:,2)))));
%f = (7.68*(0:length(s(:,1))-1)/(length(s(:,1))))-3.84;
%spec0 = sF0;
%spec1 = sF1;
rxdc_I
rxdc_I_s
dc_offset = mean(s(:,ant));
fflush(stdout);
if (abs(real(dc_offset))<dc_off_re_min)
dc_off_re_min = abs(real(dc_offset));
rxdc_I_min(ant) = rxdc_I_s;
end
if (real(dc_offset)>0)
rxdc_I = rxdc_I+stepsize;
else
rxdc_I = rxdc_I-stepsize;
end
end
stepsize = 64;
rxdc_Q = 0;
while (stepsize>=1)
stepsize = stepsize/2;
if (rxdc_Q<0)
rxdc_Q_s = 64+abs(rxdc_Q);
else
rxdc_Q_s = rxdc_Q;
end
rf_rxdc = ((128+rxdc_I_s) + (128+rxdc_Q_s)*(2^8))*[1 1 1 1];
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rxgain,txgain,0,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
sleep(sleepafterconfig)
s=oarf_get_frame(card);
figure(2)
plot(imag(s));
ylim([-2048 2048]);
drawnow;
%sF0 = 20*log10(abs(fftshift(fft(s(:,1)))));
%sF1 = 20*log10(abs(fftshift(fft(s(:,2)))));
%f = (7.68*(0:length(s(:,1))-1)/(length(s(:,1))))-3.84;
%spec0 = sF0;
%spec1 = sF1;
rxdc_Q
rxdc_Q_s
dc_offset = mean(s(:,ant));
fflush(stdout);
if (abs(imag(dc_offset))<dc_off_im_min)
dc_off_im_min = abs(imag(dc_offset));
rxdc_Q_min(ant) = rxdc_Q_s;
end
if (imag(dc_offset)>0)
rxdc_Q = rxdc_Q+stepsize;
else
rxdc_Q = rxdc_Q-stepsize;
end
end
end
rxdc_I_min
rxdc_Q_min
rf_rxdc_min = ((128+rxdc_I_min) + (128+rxdc_Q_min)*(2^8))
\ No newline at end of file
% Octave defines, according to pcie_interface.h
% Parameters for rf_mode in structure exmimo_rf_t
RXEN=1;
TXEN=2;
TXLPFENMASK=4;
TXLPFEN=4;
TXLPFMASK =15*(2^3);
TXLPF14 =0;
TXLPF10 =1*(2^3);
TXLPF7 =2*(2^3);
TXLPF6 =3*(2^3);
TXLPF5 =4*(2^3);
TXLPF4375 =5*(2^3);
TXLPF35 =6*(2^3);
TXLPF3 =7*(2^3);
TXLPF275 =8*(2^3);
TXLPF25 =9*(2^3);
TXLPF192 =10*(2^3);
TXLPF15 =11*(2^3);
TXLPF1375 =12*(2^3);
TXLPF125 =13*(2^3);
TXLPF0875 =14*(2^3);
TXLPF075 =15*(2^3);
RXLPFENMASK=1*(2^7);
RXLPFEN =128;
RXLPFMASK =15*(2^8);
RXLPF14 =0;
RXLPF10 =1*(2^8);
RXLPF7 =2*(2^8);
RXLPF6 =3*(2^8);
RXLPF5 =4*(2^8);
RXLPF4375 =5*(2^8);
RXLPF35 =6*(2^8);
RXLPF3 =7*(2^8);
RXLPF275 =8*(2^8);
RXLPF25 =9*(2^8);
RXLPF192 =10*(2^8);
RXLPF15 =11*(2^8);
RXLPF1375 =12*(2^8);
RXLPF125 =13*(2^8);
RXLPF0875 =14*(2^8);
RXLPF075 =15*(2^8);
LNAMASK=3*(2^12);
LNADIS =0;
LNA1ON =1*(2^12);
LNA2ON =2*(2^12) ;
LNA3ON =3*(2^12);
LNAGAINMASK=3*(2^14);
LNAByp =1*(2^14);
LNAMed =2*(2^14);
LNAMax =3*(2^14);
RFBBMASK =7*(2^16);
RFBBNORM =0;
RFBBRXLPF =1*(2^16);
RFBBRXVGA =2*(2^16);
RFBBOUTPUT=3*(2^16);
RFBBLNA1 =4*(2^16);
RFBBLNA2 =5*(2^16);
RFBBLNA3 =6*(2^16);
RXLPFMODEMASK=3*(2^19);
RXLPFNORM =0;
RXLPFBYP =1*(2^19);
RXLPFBPY2 =3*(2^19);
TXLPFMODEMASK=1*(2^21);
TXLPFNORM =0;
TXLPFBYP =1*(2^21);
RXOUTSW =1*(2^22);
DMAMODE_TRXMASK =3*(2^23);
DMAMODE_RX =1*(2^23);
DMAMODE_TX =2*(2^23);
rf_local = 31 + 31*(2^6) + 31*(2^12) + 31*(2^18);
rf_rxdc = 0 + 0*(2^8); % DC offset ( DCOFF_I_RXFE [6:0], DCOFF_Q_RXFE[14:8] )
rf_vcocal_19G = ((0xE)*(2^6)) + (0xE); % VCO calibration values for 1.9 GHz
rf_vcocal_700 = ((0x24)*(2^6)) + (0x24); % 700 MHz
rf_vcocal_850 = ((0x1d)*(2^6)) + (0x1d); %850 MHz
rf_vcocal_859 = ((31)*(2^6)) + (31); %859.5 MHz
%rf_vcocal_26G_eNB = ((0x1f)*(2^6)) + (0x13);
%rf_vcocal_26G_UE = ((0x13)*(2^6)) + (0x1f);
rf_vcocal_26G_UE = ((0x3)*(2^6)) + (0x26);
rf_vcocal_26G_eNB = ((0x26)*(2^6)) + (0x0);
% register values and masks for tdd_config
DUPLEXMODE_MASK = 1*(2^0);
DUPLEXMODE_FDD = 0;
DUPLEXMODE_TDD = 2*(2^0);
TXRXSWITCH_MASK = 3*(2^1);
TXRXSWITCH_LSB = 0;
TXRXSWITCH_FPGA = 1*(2^1);
TXRXSWITCH_TESTRX = 2*(2^1);
TXRXSWITCH_TESTTX = 3*(2^1);
SWITCHSTATE_MASK = 1*(2^3);
SWITCHSTATE_0 = 0;
SWITCHSTATE_1 = 1*(2^3);
TEST_ADACLOOP_MASK= 1*(2^4);
TEST_ADACLOOP_EN = 1*(2^4);
% multicard synchronization mode (multicard_syncmode)
SYNCMODE_FREE = 0;
SYNCMODE_MASTER = 1;
SYNCMODE_SLAVE = 2;
% external RF frontend
TVWS_TDD = 0;
DD_FDD = 1;
DD_TDD = 2;
B19G_TDD = 3;
B24G_TDD = 4;
B26G_TDD = 5;
B26G_FDD = 6;
B35G_TDD = 7;
B50G_TDD = 8;
\ No newline at end of file
This diff is collapsed.
// Maxime Guillaud - created Fri May 12 16:20:04 CEST 2006
// Matthias Ihmig, 2013
// see http://www.gnu.org/software/octave/doc/interpreter/Dynamically-Linked-Functions.html#Dynamically-Linked-Functions
// and http://wiki.octave.org/wiki.pl?CodaTutorial
// and http://octave.sourceforge.net/coda/c58.html
// compilation: see Makefile
// Update: Wed May 23 17:25:39 CEST 2007, fifo acquisition of signal buffer (RK)
// 29.01.2013: adopted to new kernel driver
#include <octave/oct.h>
extern "C" {
#include "openair0_lib.h"
}
#define FCNNAME "oarf_get_frame"
#define TRACE 1
static bool any_bad_argument(const octave_value_list &args)
{
octave_value v;
if (args.length()!=1)
{
error(FCNNAME);
error("syntax: oarf_get_frame(card)");
return true;
}
v=args(0);
if ((!v.is_real_scalar()) || (v.scalar_value() < -2) || (floor(v.scalar_value()) != v.scalar_value()) || (v.scalar_value() >= MAX_CARDS))
{
error(FCNNAME);
error("card must be 0-3 for a specific card, or -1 to get frame from all cards.\nSet framing.sync_mode =SYNCMODE_MASTER for one card and =SYNCMODE_SLAVE to obtain synchronized frames.\n");
return true;
}
return false;
}
int find_mastercard()
{
int card=0, found_master=0, i;
const char *str[] = { "FREE", "MASTER", "SLAVE" };
printf("Card configuration: card");
for (i=0; i<openair0_num_detected_cards; i++)
printf(" [%i]=%s,", i, str[ openair0_exmimo_pci[i].exmimo_config_ptr->framing.multicard_syncmode ]);
printf("\n");
for (i=0; i<openair0_num_detected_cards; i++)
{
if ( openair0_exmimo_pci[i].exmimo_config_ptr->framing.multicard_syncmode == SYNCMODE_MASTER )
{
if (found_master >= 1)
{
printf("Warning: There is more than one master active! Will put card[%i] back into SYNCMODE_FREE!\n", i);
openair0_exmimo_pci[i].exmimo_config_ptr->framing.multicard_syncmode == SYNCMODE_FREE;
}
else
{
card = i;
found_master++;
}
}
}
if (found_master == 0)
printf("Warning: No master activated! Will trigger getframe on card 0\n");
return card;
}
DEFUN_DLD (oarf_get_frame, args, nargout,"Get frame")
{
int numant, no_getframe_ioctl=0;
if (any_bad_argument(args))
return octave_value_list();
int card = args(0).int_value();
octave_value returnvalue;
int i,aa;
short *rx_sig[MAX_CARDS * MAX_ANTENNAS];
int ret;
ret = openair0_open();
if ( ret != 0 )
{
error(FCNNAME);
if (ret == -1)
error("Error opening /dev/openair0");
if (ret == -2)
error("Error mapping bigshm");
if (ret == -3)
error("Error mapping RX or TX buffer");
return octave_value(ret);
}
if (card == -2)
{
no_getframe_ioctl = 1;
card = -1;
}
if (card <-1 || card >= openair0_num_detected_cards)
error("card number must be between 0 and %d. Or -1 for all cards.", openair0_num_detected_cards-1);
if (card == -1) {
numant = openair0_num_detected_cards * openair0_num_antennas[0];
card = find_mastercard();
}
else
numant = openair0_num_antennas[card];
if ( no_getframe_ioctl )
{
// print mbox counters
for (i=0; i<numant; i++)
{
if ( numant == openair0_num_antennas[card] )
printf("rx_cnt[%d] = %d, tx_cnt[%d] = %d, ", i, *openair0_exmimo_pci[card].rxcnt_ptr[i],
i, *openair0_exmimo_pci[card].txcnt_ptr[i]);
else
printf("rx_cnt[%d] = %d, tx_cnt[%d] = %d, ", i, *openair0_exmimo_pci[i / (int)openair0_num_antennas[0]].rxcnt_ptr[i % openair0_num_antennas[0]],
i, *openair0_exmimo_pci[i / (int)openair0_num_antennas[0]].txcnt_ptr[i % openair0_num_antennas[0]]);
}
printf("\n");
}
ComplexMatrix dx (FRAME_LENGTH_COMPLEX_SAMPLES, numant);
/*
// set the tx buffer to 0x00010001 to put switch in rx mode
for (aa=0; aa<numant; aa++)
for (i=0; i<FRAME_LENGTH_COMPLEX_SAMPLES; i++)
((int*)(openair0_exmimo_pci[card].dac_head[aa]))[i] = 0x00010001;
*/
if ((openair0_exmimo_pci[card].exmimo_config_ptr->framing.tdd_config & TXRXSWITCH_MASK) != TXRXSWITCH_TESTRX)
printf("Warning: tdd_config is not set to TXRXSWITCH_TESTRX! You better know what you are doing! :)\n");
// assign userspace pointers
for (i=0; i<numant; i++)
{
if ( numant == openair0_num_antennas[card] )
rx_sig[i] = (short*) openair0_exmimo_pci[ card ].adc_head[ i ];
else
rx_sig[i] = (short*) openair0_exmimo_pci[ i / (int)openair0_num_antennas[0] ].adc_head[i % openair0_num_antennas[0]];
//printf("adc_head[%i] = %p ", i, rx_sig[i]);
}
printf("\n");
// msg("Getting buffer...\n");
if ( no_getframe_ioctl == 0)
openair0_get_frame(card);
for (i=0; i<FRAME_LENGTH_COMPLEX_SAMPLES; i++)
for (aa=0; aa<numant; aa++)
dx(i, aa) = Complex( rx_sig[aa][i*2], rx_sig[aa][i*2+1] );
openair0_close();
return octave_value (dx);
}
// Matthias Ihmig, 2013
// see http://www.gnu.org/software/octave/doc/interpreter/Dynamically-Linked-Functions.html#Dynamically-Linked-Functions
// and http://wiki.octave.org/wiki.pl?CodaTutorial
// and http://octave.sourceforge.net/coda/c58.html
// compilation: see Makefile
#include <octave/oct.h>
extern "C" {
#include "openair0_lib.h"
}
#define FCNNAME "oarf_get_num_detected_cards"
#define TRACE 1
static bool any_bad_argument(const octave_value_list &args)
{
octave_value v;
if (args.length()!=0)
{
error(FCNNAME);
error("syntax: oarf_get_num_detected_cards");
return true;
}
return false;
}
DEFUN_DLD (oarf_get_num_detected_cards, args, nargout,"Returns number of detected cards.")
{
if (any_bad_argument(args))
return octave_value_list();
int ret;
octave_value returnvalue;
ret = openair0_open();
if ( ret != 0 )
{
error(FCNNAME);
if (ret == -1)
error("Error opening /dev/openair0");
if (ret == -2)
error("Error mapping bigshm");
if (ret == -3)
error("Error mapping RX or TX buffer");
return octave_value(ret);
}
returnvalue = openair0_num_detected_cards;
openair0_close( );
return octave_value(returnvalue);
}
// Matthias Ihmig, 2013
// Maxime Guillaud - created Fri May 12 16:20:04 CEST 2006
// see http://www.gnu.org/software/octave/doc/interpreter/Dynamically-Linked-Functions.html#Dynamically-Linked-Functions
// and http://wiki.octave.org/wiki.pl?CodaTutorial
// and http://octave.sourceforge.net/coda/c58.html
// compilation: see Makefile
// Update: Wed May 23 17:25:39 CEST 2007, fifo acquisition of signal buffer (RK)
#include <octave/oct.h>
extern "C" {
#include "openair0_lib.h"
}
#define FCNNAME "oarf_send_frame"
#define TRACE 1
static bool any_bad_argument(const octave_value_list &args)
{
octave_value v;
if (args.length()!=3)
{
error(FCNNAME);
error("syntax: oarf_send_frame(card,sig,nbits)\n card (starting from 0), sig is a 2D or 4D vector (depending on no. of antennas), nbits is number of bits to quantize the signal to.");
return true;
}
v=args(0);
if ((!v.is_real_scalar()) || (v.scalar_value() < 0.0) || (floor(v.scalar_value()) != v.scalar_value()) || (v.scalar_value() >= MAX_CARDS))
{
error(FCNNAME);
error("card must be between 0 and MAX_CARDS.");
return true;
}
v=args(1);
printf("signal: R %d, C %d\n",v.rows(),v.columns());
return false;
v=args(2);
if ((!v.is_real_scalar()) || (v.scalar_value()!=8) || (v.scalar_value()!=16))
{
error(FCNNAME);
error("nbits must be either 8 (CBMIMO) or 16 (ExpressMIMO)bits.");
return true;
}
}
DEFUN_DLD (oarf_send_frame, args, nargout,"Send frame")
{
if (any_bad_argument(args))
return octave_value_list();
const int card = args(0).int_value();
ComplexMatrix dx = args(1).complex_matrix_value();
octave_value returnvalue;
int i, ret;
unsigned int length,aa,nbits, numcols;
int dummy=0;
ret = openair0_open();
if ( ret != 0 )
{
error(FCNNAME);
if (ret == -1)
error("Error opening /dev/openair0");
if (ret == -2)
error("Error mapping bigshm");
if (ret == -3)
error("Error mapping RX or TX buffer");
return octave_value(ret);
}
if (card <0 || card >= openair0_num_detected_cards) {
error("Invalid card number!");
return octave_value(-4);
}
numcols = args(1).columns();
printf("colums = %d, rows = %d\n\n\n", numcols, args(1).rows());
if ( numcols<1 || (numcols > openair0_num_antennas[card]) || (args(1).rows()!=76800))
{
error(FCNNAME);
error("input array must be of size (%d, 1..%d).", 76800, openair0_num_antennas[card]);
return octave_value_list();
}
if ((openair0_exmimo_pci[card].exmimo_config_ptr->framing.tdd_config & TXRXSWITCH_MASK) != TXRXSWITCH_TESTTX)
printf("Warning: tdd_config is not set to TXRXSWITCH_TESTTX! You better know what you are doing! :)\n");
nbits = args(2).scalar_value();
for (aa=0;aa<numcols;aa++)
{
if (nbits==16)
{
for (i=0;i<76800;i++)
{
if (i<64)
printf("%d: %d,%d\n",i,(short)real(dx(i,aa)),(short)imag(dx(i,aa)));
((short*) openair0_exmimo_pci[card].dac_head[aa])[2*i] = (short)(real(dx(i,aa)));
((short*) openair0_exmimo_pci[card].dac_head[aa])[1+(2*i)] = (short)(imag(dx(i,aa)));
}
}
else if (nbits==8)
{
for (i=0;i<76800;i++)
{
if (i<64)
printf("%d: %d,%d\n",i,char(real(dx(i,aa))),char(imag(dx(i,aa))));
((char*) openair0_exmimo_pci[card].dac_head[aa])[2*i] = char(real(dx(i,aa)));
((char*) openair0_exmimo_pci[card].dac_head[aa])[1+(2*i)] = char(imag(dx(i,aa)));
}
}
else {
error(FCNNAME);
error("nbits has to be 8 or 16!");
}
}
openair0_start_rt_acquisition( card );
openair0_close();
return octave_value (dx);
}
// Matthias Ihmig, 2013
// Florian Kaltenberger - created 2010-01-22
// see http://www.gnu.org/software/octave/doc/interpreter/Dynamically-Linked-Functions.html#Dynamically-Linked-Functions
// and http://wiki.octave.org/wiki.pl?CodaTutorial
// and http://octave.sourceforge.net/coda/c58.html
// compilation: see Makefile
#include <octave/oct.h>
extern "C" {
#include "openair0_lib.h"
}
#define FCNNAME "oarf_stop"
#define TRACE 1
static bool any_bad_argument(const octave_value_list &args)
{
octave_value v;
if (args.length()!=1)
{
error(FCNNAME);
error("syntax: oarf_stop(card)");
return true;
}
v=args(0);
if ((!v.is_real_scalar()) || (v.scalar_value() < -1) || (floor(v.scalar_value()) != v.scalar_value()) || (v.scalar_value() >= MAX_CARDS))
{
error(FCNNAME);
error("card must be 0..number of cards-1.\nUse card = -1 to stop all cards.\n");
return true;
}
return false;
}
DEFUN_DLD (oarf_stop, args, nargout,"Stop RT acquisition and write registers.")
{
int a,b;
if (any_bad_argument(args))
return octave_value_list();
int card = args(0).int_value();
int ret;
octave_value returnvalue;
ret = openair0_open();
if ( ret != 0 )
{
error(FCNNAME);
if (ret == -1)
error("Error opening /dev/openair0");
if (ret == -2)
error("Error mapping bigshm");
if (ret == -3)
error("Error mapping RX or TX buffer");
return octave_value(ret);
}
if (card <-1 || card >= openair0_num_detected_cards)
error("Invalid card number (num detected cards: %d, card: %d)!", openair0_num_detected_cards, card);
if (card == -1) {
for (card = 0; card < openair0_num_detected_cards; card++)
returnvalue = openair0_stop( card );
} else
returnvalue = openair0_stop( card );
openair0_close( );
return octave_value(returnvalue);
}
card=0;
s = oarf_get_frame(card);
%s=s-0.99999*mean(s(:,2));
sig0 = s(:,1);
sig1 = s(:,2);
#sig0 = s(5000:end,1); % first channel
#sig1 = s(5000:end,2); % 2nd channel
bw=7.68e6;
spec = abs(fft(sig1)).^2;
%[a,b] = max(spec(2:end)); b=b+1;
[a,b] = max(spec);
freq = (b-1)*bw/length(sig0);
L= 1000;
W = 1;
offset_vec = (0:L-1)*((2*W)+1);
W2 = 1+(2*W);
window_vec = (-W : W);
pn = zeros(1,(2*L) - 1);
for i = 1:L,
pn(i+L-1) = sum(spec(offset_vec(i) + b + window_vec));
end
for i = 2:L,
pn(L-i+1) = sum(spec(-offset_vec(i) + b + window_vec));
end
pn_2 = 10*log10(pn / pn(L)) - 10*log10(W2*bw/length(sig0));
f = ((-L+1):(L-1))*W2*bw/length(sig0);
ylabel('dBc/Hz')
xlabel("f_offset (Hz)")
title("Phase Noise @ IQ output for Fc = 1912.6 + Fs/4 MHz CW input at antenna")
semilogx(f(L:(2*L - 1)),pn_2(L:(2*L -1)))
grid on
axis([1e2 100e3 -90 -30]);
sum(pn*(f(2)-f(1)))
signal_amp = 10*log10(pn(L))
close all
figure
for i=1:4
subplot(220+i);plot(20*log10(abs(fftshift(fft(received(:,i))))));
axis([0 76799 10 140])
endfor
figure
t=[0:512-1]/7.68;%512*1e-2;
plot(t,20*log10(abs(tchanests)))
xlabel('time (usec)')
ylabel('|h|')
legend('SMBV->Antenna1','SMBV->Antenna2','SMBV->Antenna3','SMBV->Antenna4');
axis([0 10 10 60])
figure
plot(20*log10(abs(fchanests)));
ylim([40 100])
xlabel('freq')
ylabel('|h|')
legend('SMBV->Antenna1','SMBV->Antenna2','SMBV->Antenna3','SMBV->Antenna4');
short primary_synch0[144] = {0,0,0,0,0,0,0,0,0,0,32767,0,-26120,-19785,11971,-30502,-24020,-22288,32117,6492,31311,9658,-16384,-28378,25100,-21063,-7292,-31946,20429,25618,14948,29158,11971,-30502,31311,9658,25100,-21063,-16384,28377,-24020,22287,32117,6492,-7292,31945,20429,25618,-26120,-19785,-16384,-28378,-16384,28377,-26120,-19785,-32402,4883,31311,-9659,32117,6492,-7292,-31946,32767,-1,25100,-21063,-24020,22287,-32402,4883,-32402,4883,-24020,22287,25100,-21063,32767,-1,-7292,-31946,32117,6492,31311,-9659,-32402,4883,-26120,-19785,-16384,28377,-16384,-28378,-26120,-19785,20429,25618,-7292,31945,32117,6492,-24020,22287,-16384,28377,25100,-21063,31311,9658,11971,-30502,14948,29158,20429,25618,-7292,-31946,25100,-21063,-16384,-28378,31311,9658,32117,6492,-24020,-22288,11971,-30502,-26120,-19785,32767,0,0,0,0,0,0,0,0,0,0,0};
short primary_synch1[144] = {0,0,0,0,0,0,0,0,0,0,32767,0,-31754,-8086,-24020,-22288,2448,32675,-26120,19784,27073,18458,-16384,28377,25100,21062,-29523,14217,-7292,31945,-13477,-29868,-24020,-22288,27073,18458,25100,21062,-16384,-28378,2448,-32676,-26120,19784,-29523,-14218,-7292,31945,-31754,-8086,-16384,28377,-16384,-28378,-31754,-8086,31311,-9659,27073,-18459,-26120,19784,-29523,14217,32767,-1,25100,21062,2448,-32676,31311,-9659,31311,-9659,2448,-32676,25100,21062,32767,0,-29523,14217,-26120,19784,27073,-18459,31311,-9659,-31754,-8086,-16384,-28378,-16384,28377,-31754,-8086,-7292,31945,-29523,-14218,-26120,19784,2448,-32676,-16384,-28378,25100,21062,27073,18458,-24020,-22288,-13477,-29868,-7292,31945,-29523,14217,25100,21062,-16384,28377,27073,18458,-26120,19784,2448,32675,-24020,-22288,-31754,-8086,32767,0,0,0,0,0,0,0,0,0,0,0};
short primary_synch2[144] = {0,0,0,0,0,0,0,0,0,0,32767,0,-31754,8085,-24020,22287,2448,-32676,-26120,-19785,27073,-18459,-16384,-28378,25100,-21063,-29523,-14218,-7292,-31946,-13477,29867,-24020,22287,27073,-18459,25100,-21063,-16384,28377,2448,32675,-26120,-19785,-29523,14217,-7292,-31946,-31754,8085,-16384,-28378,-16384,28377,-31754,8085,31311,9658,27073,18458,-26120,-19785,-29523,-14218,32767,0,25100,-21063,2448,32675,31311,9658,31311,9658,2448,32675,25100,-21063,32767,0,-29523,-14218,-26120,-19785,27073,18458,31311,9658,-31754,8085,-16384,28377,-16384,-28378,-31754,8085,-7292,-31946,-29523,14217,-26120,-19785,2448,32675,-16384,28377,25100,-21063,27073,-18459,-24020,22287,-13477,29867,-7292,-31946,-29523,-14218,25100,-21063,-16384,-28378,27073,-18459,-26120,-19785,2448,-32676,-24020,22287,-31754,8085,32767,-1,0,0,0,0,0,0,0,0,0,0};
unsigned char primary_synch0_tab[72] = {0,0,0,0,0,85,110,97,109,146,145,106,92,103,139,137,97,145,92,127,124,146,130,139,110,106,127,110,118,88,146,103,85,92,124,118,118,124,92,85,103,146,88,118,110,127,106,110,139,130,146,124,127,92,145,97,137,139,103,92,106,145,146,109,97,110,85,0,0,0,0,0};
unsigned char primary_synch1_tab[72] = {0,0,0,0,0,85,114,109,133,123,142,127,141,121,130,105,109,142,141,106,100,123,112,130,114,127,106,114,88,91,123,121,85,141,100,88,88,100,141,85,121,123,91,88,114,106,127,114,130,112,123,100,106,141,142,109,105,130,121,141,127,142,123,133,109,114,85,0,0,0,0,0};
unsigned char primary_synch2_tab[72] = {0,0,0,0,0,85,119,124,100,110,91,106,92,112,103,128,124,91,92,127,133,110,121,103,119,106,127,119,145,142,110,112,85,92,133,145,145,133,92,85,112,110,142,145,119,127,106,119,103,121,110,133,127,92,91,124,128,103,112,92,106,91,110,100,124,119,85,0,0,0,0,0};
unsigned char primary_synch0_tab[72] = {0,0,0,0,97,110,85,0,106,145,146,109,137,139,103,92,127,92,145,97,139,130,146,124,110,127,106,110,103,146,88,118,118,124,92,85,85,92,124,118,118,88,146,103,110,106,127,110,124,146,130,139,97,145,92,127,92,103,139,137,109,146,145,106,0,85,110,97,0,0,0,0};
unsigned char primary_synch1_tab[72] = {0,0,0,0,0,85,110,97,109,146,145,106,92,103,139,137,97,145,92,127,124,146,130,139,110,106,127,110,118,88,146,103,85,92,124,118,118,124,92,85,103,146,88,118,110,127,106,110,139,130,146,124,127,92,145,97,137,139,103,92,106,145,146,109,97,110,85,0,0,0,0,0};
unsigned char primary_synch2_tab[72] = {0,0,0,0,0,85,110,97,109,146,145,106,92,103,139,137,97,145,92,127,124,146,130,139,110,106,127,110,118,88,146,103,85,92,124,118,118,124,92,85,103,146,88,118,110,127,106,110,139,130,146,124,127,92,145,97,137,139,103,92,106,145,146,109,97,110,85,0,0,0,0,0};
clear all
Nmeas=1
rx_spec
Niter=1
meas=1
for meas=1:Nmeas
close all
receivedA2B1=oarf_get_frame(card);
%oarf_stop(card);
initial_sync
N=76800;
indA=[1 0 0 0];
indB=[1 2 3 4];
Nanta=length(indA);
Nantb=length(indB);
fchan=zeros(512,Nantb);
tchan=fchan;
frame_start=abs(frame_start)
I= [frame_start:N,1:frame_start-1];
receivedA2B=receivedA2B1(I',:);
%load where2_v1_final.mat data
load filesave0811.mat data
Nofs=3840; % The offset in samples between the downlink and uplink sequences. It must be a multiple of 640, 3840 samples is 0.5 ms.
maskA2B=kron(ones(1,N/(2*Nofs)),[ones(1,Nofs) zeros(1,Nofs)])';
datamaskA2B=diag(kron(ones(1,N/(2*Nofs)),[ones(1,Nofs/640) zeros(1,Nofs/640)]));
%signalA2B=s2;
Da2b_T=datamaskA2B*data;
%tmps=s2;
Da2b_R=zeros(Niter*120,Nantb*301);
for i=0:119;
ifblock=receivedA2B(i*640+[1:640],indB);
ifblock(1:128,:)=[];
fblock=fft(ifblock);
fblock(1,:)=[];
fblock(151:360,:)=[];
Da2b_R((Niter-1)*120+i+1,:,meas)=vec(fblock);
endfor
HA2B=repmat(conj(Da2b_T),Niter,Nantb).*Da2b_R(:,:,meas);
phasesA2B=unwrap(angle(HA2B));
if(mean(var(phasesA2B))>0.5)
disp("The phases of your estimates from A to B are a bit high (larger than 0.5 rad.), something is wrong.");
endif
chanestsA2B(:,:,meas)=reshape(diag(repmat(Da2b_T,Niter,Nantb)'*Da2b_R(:,:,meas))/size(Da2b_T,1),301,Nantb);
#fchanestsA2B=zeros(512,Nantb);
#for i=1:Nantb
# fchanestsA2B(:,i)=[0; chanestsA2B([1:150],i,meas); zeros(210,1); chanestsA2B(151:301,i,meas)];
#endfor
fchanestsA2B(:,:,meas)=[zeros(1,Nantb); chanestsA2B([1:150],:,meas); zeros(210,Nantb); chanestsA2B(151:301,:,meas)];
tchanestsA2B(:,:,meas)=ifft(fchanestsA2B(:,:,meas));
%keyboard
end %% Nmeas
received = receivedA2B;
phases = phasesA2B;
tchanests = [tchanestsA2B(:,:,end)];% , tchanestsB2A(:,:,end)];
fchanests = [fchanestsA2B(:,:,end)];% , fchanestsB2A(:,:,end)];
plots
clear all
Nmeas=1
rx_spec
Niter=1
meas=1
for meas=1:Nmeas
close all
receivedA2B1=oarf_get_frame(card);
%oarf_stop(card);
initial_sync
N=76800;
indA=[1 0 0 0];
indB=[1 2 3 4];
Nanta=length(indA);
Nantb=length(indB);
fchan=zeros(512,Nantb);
tchan=fchan;
frame_start=abs(frame_start)
I= [frame_start:N,1:frame_start-1];
receivedA2B=receivedA2B1(I',:);
%load where2_v1_final.mat data
load filesave0811.mat data
Nofs=3840; % The offset in samples between the downlink and uplink sequences. It must be a multiple of 640, 3840 samples is 0.5 ms.
maskA2B=kron(ones(1,N/(2*Nofs)),[ones(1,Nofs) zeros(1,Nofs)])';
datamaskA2B=diag(kron(ones(1,N/(2*Nofs)),[ones(1,Nofs/640) zeros(1,Nofs/640)]));
%signalA2B=s2;
Da2b_T=datamaskA2B*data;
%tmps=s2;
Da2b_R=zeros(Niter*120,Nantb*301);
for i=0:119;
ifblock=receivedA2B(i*640+[1:640],indB);
ifblock(1:128,:)=[];
fblock=fft(ifblock);
fblock(1,:)=[];
fblock(151:360,:)=[];
Da2b_R((Niter-1)*120+i+1,:,meas)=vec(fblock);
endfor
HA2B=repmat(conj(Da2b_T),Niter,Nantb).*Da2b_R(:,:,meas);
phasesA2B=unwrap(angle(HA2B));
if(mean(var(phasesA2B))>0.5)
disp("The phases of your estimates from A to B are a bit high (larger than 0.5 rad.), something is wrong.");
endif
chanestsA2B(:,:,meas)=reshape(diag(repmat(Da2b_T,Niter,Nantb)'*Da2b_R(:,:,meas))/size(Da2b_T,1),301,Nantb);
#fchanestsA2B=zeros(512,Nantb);
#for i=1:Nantb
# fchanestsA2B(:,i)=[0; chanestsA2B([1:150],i,meas); zeros(210,1); chanestsA2B(151:301,i,meas)];
#endfor
fchanestsA2B(:,:,meas)=[zeros(1,Nantb); chanestsA2B([1:150],:,meas); zeros(210,Nantb); chanestsA2B(151:301,:,meas)];
tchanestsA2B(:,:,meas)=ifft(fchanestsA2B(:,:,meas));
%keyboard
end %% Nmeas
received = receivedA2B;
phases = phasesA2B;
tchanests = [tchanestsA2B(:,:,end)];% , tchanestsB2A(:,:,end)];
fchanests = [fchanestsA2B(:,:,end)];% , fchanestsB2A(:,:,end)];
plots
## Composes rf_local values: rfl(txi, txq, rxi, rxq)
## Author: Matthias Ihmig <ihmig@solstice>
## Created: 2012-12-05
function [ ret ] = rfl(txi, txq, rxi, rxq)
ret = txi + txq*2^6 + rxi*2^12 + rxq*2^18;
endfunction
## Decodes rf_local values: [ txi, txq, rxi, rxq ] = rfldec(rflocal)
## Author: Matthias Ihmig <ihmig@solstice>
## Created: 2012-12-05
function [ txi, txq, rxi, rxq ] = rfldec(rflocal)
txi = mod(floor( rflocal /1 ), 64)
txq = mod(floor( rflocal /64), 64)
rxi = mod(floor( rflocal /4096), 64)
rxq = mod(floor( rflocal /262144), 64)
endfunction
close all
clear all
hold off
gpib_card=0; % first GPIB PCI card in the computer
gpib_device=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu
fc = 1907600e3;
fs = 7680e3;
fref = fc+fs/4;
power_dBm = -100;
cables_loss_dB = 6; % we need to account for the power loss between the signal generator and the card input (splitter, cables)
dual_tx = 0;
tdd = 1;
card = 0;
limeparms;
%rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM+DMAMODE_RX+DMAMODE_TX)*[1 1 1 1];
rf_mode1 = (RXEN+0+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM+DMAMODE_RX+0);
rf_mode2 = (RXEN+0+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA2ON+LNAMax+RFBBNORM+DMAMODE_RX+0);
rf_mode = [rf_mode1 rf_mode2 0 0];
freq_rx = 1907600000*[1 1 1 1];
freq_tx = freq_rx;
tx_gain = 25*[1 1 1 1];
rx_gain = 15*[1 1 1 1];
%rf_local= [8254744 8255063 8257340 8257340]; %rf_local*[1 1 1 1];
rf_local = [8254813 8255016 8254813 8254813]; %exmimo2_2
%rf_rxdc = rf_rxdc*[1 1 1 1];
%rf_rxdc = ((128+rxdc_I) + (128+rxdc_Q)*(2^8))*[1 1 1 1];
rf_rxdc = [37059 35459 36300 36999]; %exmimo2_2
rf_vcocal=rf_vcocal_19G*[1 1 1 1];
eNBflag = 0;
tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB;
syncmode = SYNCMODE_FREE;
rffe_rxg_low = 63*[1 1 1 1];
rffe_rxg_final = 63*[1 1 1 1];
rffe_band = B19G_TDD*[1 1 1 1];
gpib_send(gpib_card,gpib_device,'*RST;*CLS'); % reset and configure the signal generator
%gpib_send(gpib_card,gpib_device,sprintf("POW %ddBm",power_dBm+cables_loss_dB));
gpib_send(gpib_card,gpib_device,'POW -14dBm');
%gpib_send(gpib_card,gpib_device,'FREQ 1.91860GHz');
%gpib_send(gpib_card,gpib_device,'FREQ 1.919225GHz');
%gpib_send(gpib_card,gpib_device,'FREQ 1.909225GHz');
gpib_send(gpib_card,gpib_device,sprintf("FREQ %dHz",fref));
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
ALL_rxrfmode = [LNAByp LNAMed LNAMax];
ALL_gain = 0:10:30;
SpN0 = zeros(length(ALL_rxrfmode),length(ALL_gain));
SpN1 = zeros(length(ALL_rxrfmode),length(ALL_gain));
N0 = zeros(length(ALL_rxrfmode),length(ALL_gain));
N1 = zeros(length(ALL_rxrfmode),length(ALL_gain));
S0 = zeros(length(ALL_rxrfmode),length(ALL_gain));
S1 = zeros(length(ALL_rxrfmode),length(ALL_gain));
G0 = zeros(length(ALL_rxrfmode),length(ALL_gain));
G1 = zeros(length(ALL_rxrfmode),length(ALL_gain));
NF0 = zeros(length(ALL_rxrfmode),length(ALL_gain));
NF1 = zeros(length(ALL_rxrfmode),length(ALL_gain));
SNR0 = zeros(length(ALL_rxrfmode),length(ALL_gain));
SNR1 = zeros(length(ALL_rxrfmode),length(ALL_gain));
%keyboard
idx_power = 1;
for LNA=ALL_rxrfmode
%gpib_send(gpib_card,gpib_device,['POW ' int2str(power_dBm+cables_loss_dB) 'dBm']);
idx_gain = 1;
for rx_gain=ALL_gain
rf_mode = (RXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNA+RFBBNORM+DMAMODE_RX)*[1 1 0 0];
rx_gain = rx_gain * [1 1 1 1];
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
sleep(1);
% signal measurement
gpib_send(gpib_card,gpib_device,'OUTP:STAT ON'); % activate output
sleep(.5);
s=oarf_get_frame(card);
sleep(.5);
SpN0(idx_power,idx_gain) = mean(abs(s(:,1)).^2) - abs(mean(s(:,1))).^2;
SpN1(idx_power,idx_gain) = mean(abs(s(:,2)).^2) - abs(mean(s(:,2))).^2;
figure(1);
hold off
plot(20*log10(abs(fft(s(:,1)))),'r',20*log10(abs(fft(s(:,2)))),'b')
title("Signal");
ylim([0 200]);
% noise measurement
gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
sleep(.5);
s=oarf_get_frame(card); %oarf_get_frame
sleep(.5);
N0(idx_power,idx_gain) = mean(abs(s(:,1)).^2) - abs(mean(s(:,1))).^2;
N1(idx_power,idx_gain) = mean(abs(s(:,2)).^2) - abs(mean(s(:,2))).^2;
figure(2);
hold off
plot(20*log10(abs(fft(s(:,1)))),'r',20*log10(abs(fft(s(:,2)))),'b')
title("Noise");
ylim([0 200]);
% do some plausibility checks
% if ((N0(idx_power,idx_gain) > SpN0(idx_power,idx_gain)) ||
% (N1(idx_power,idx_gain) > SpN1(idx_power,idx_gain)))
% error("something is wrong");
% end
S0(idx_power,idx_gain) = 10*log10(SpN0(idx_power,idx_gain)-N0(idx_power,idx_gain));
S1(idx_power,idx_gain) = 10*log10(SpN1(idx_power,idx_gain)-N1(idx_power,idx_gain));
G0(idx_power,idx_gain) = S0(idx_power,idx_gain) - power_dBm;
G1(idx_power,idx_gain) = S1(idx_power,idx_gain) - power_dBm;
NF0(idx_power,idx_gain) = 10*log10(N0(idx_power,idx_gain)) - G0(idx_power,idx_gain) + 105; % 108 is the thermal noise
NF1(idx_power,idx_gain) = 10*log10(N1(idx_power,idx_gain)) - G1(idx_power,idx_gain) + 105;
SNR0(idx_power,idx_gain) = S0(idx_power,idx_gain)-10*log10(N0(idx_power,idx_gain));
SNR1(idx_power,idx_gain) = S1(idx_power,idx_gain)-10*log10(N1(idx_power,idx_gain));
printf(' %d: Signal strength (%f,%f), Gain (%f %f), N (%f %f) SNR (%f %f) NF (%f %f)\n',
rx_gain(1), S0(idx_power,idx_gain),S1(idx_power,idx_gain),
G0(idx_power,idx_gain),G1(idx_power,idx_gain),
10*log10(N0(idx_power,idx_gain)),10*log10(N1(idx_power,idx_gain)),
SNR0(idx_power,idx_gain),SNR1(idx_power,idx_gain),
NF0(idx_power,idx_gain),NF1(idx_power,idx_gain));
fflush(stdout);
%fprintf(fid,'%d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n',
%power_dBm,gain2391,gain9862, S0,S1,G0,G1,10*log10(N0),10*log10(N1),SNR0,SNR1,NF0,NF1);
idx_gain = idx_gain + 1;
figure(3)
hold off
plot(ALL_gain,G0,'o-','markersize',10)
hold on
plot(ALL_gain,G1,'x-','markersize',10)
legend('Byp RX0','Med RX0','Max RX0','Byp RX1','Med RX1','Max RX1');
title('Gains')
figure(4)
hold off
plot(ALL_gain,NF0,'o-','markersize',10)
hold on
plot(ALL_gain,NF1,'x-','markersize',10)
legend('Byp RX0','Med RX0','Max RX0','Byp RX1','Med RX1','Max RX1');
title('Noise Figure')
end
idx_power = idx_power + 1;
end
%gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
%l0 = [ALL_gain2391; ones(size(ALL_gain2391))].'\G0;
%l1 = [ALL_gain2391; ones(size(ALL_gain2391))].'\G1;
close all
clear all
hold off
gpib_card=0; % first GPIB PCI card in the computer
gpib_device=28; % this is configured in the signal generator Utilities->System->GPIB->Address menu
fc = 1907600e3;
fs = 7680e3;
fref = fc+fs/4;
power_dBm = -70;
cables_loss_dB = 6; % we need to account for the power loss between the signal generator and the card input (splitter, cables)
dual_tx = 0;
tdd = 1;
card = 0;
limeparms;
%rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM+DMAMODE_RX+DMAMODE_TX)*[1 1 1 1];
rf_mode1 = (RXEN+0+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM+DMAMODE_RX+0);
rf_mode2 = (RXEN+0+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA2ON+LNAMax+RFBBNORM+DMAMODE_RX+0);
rf_mode = [rf_mode1 rf_mode2 0 0];
freq_rx = 1907600000*[1 1 1 1];
freq_tx = freq_rx;
tx_gain = 25*[1 1 1 1];
rx_gain = 15*[1 1 1 1];
%rf_local= [8254744 8255063 8257340 8257340]; %rf_local*[1 1 1 1];
rf_local = [8254813 8255016 8254813 8254813]; %exmimo2_2
%rf_rxdc = rf_rxdc*[1 1 1 1];
%rf_rxdc = ((128+rxdc_I) + (128+rxdc_Q)*(2^8))*[1 1 1 1];
rf_rxdc = [37059 35459 36300 36999]; %exmimo2_2
rf_rxdc = [34689 34756 36300 36999]; %exmimo2_2 with external RF
rf_vcocal=rf_vcocal_19G*[1 1 1 1];
eNBflag = 0;
tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB;
syncmode = SYNCMODE_FREE;
rffe_rxg_low = 31*[1 1 1 1];
rffe_rxg_final = 31*[1 1 1 1];
rffe_band = B19G_TDD*[1 1 1 1];
gpib_send(gpib_card,gpib_device,'*RST;*CLS'); % reset and configure the signal generator
%gpib_send(gpib_card,gpib_device,sprintf("POW %ddBm",power_dBm+cables_loss_dB));
gpib_send(gpib_card,gpib_device,sprintf("POW %ddBm",-14));
%gpib_send(gpib_card,gpib_device,'FREQ 1.91860GHz');
%gpib_send(gpib_card,gpib_device,'FREQ 1.919225GHz');
%gpib_send(gpib_card,gpib_device,'FREQ 1.909225GHz');
gpib_send(gpib_card,gpib_device,sprintf("FREQ %dHz",fref));
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
%ALL_rxrfmode = [LNAByp LNAMed LNAMax];
%ALL_gain = 0:10:30;
ALL_rxrfmode = LNAMax;
ALL_gain = 30;
ALL_rffe_rxg_low = [0 7:8:64];
ALL_rffe_rxg_final = [0 7:8:64];
SpN0 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
SpN1 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
N0 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
N1 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
S0 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
S1 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
G0 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
G1 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
NF0 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
NF1 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
SNR0 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
SNR1 = zeros(length(ALL_rffe_rxg_low),length(ALL_rffe_rxg_final));
%keyboard
idx_power = 1;
for LNA=ALL_rxrfmode
rf_mode = (RXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNA+RFBBNORM+DMAMODE_RX)*[1 1 0 0];
for rffe_rxg_low=ALL_rffe_rxg_low
rffe_rxg_low = rffe_rxg_low*[1 1 1 1];
idx_gain = 1;
for rx_gain=ALL_gain
rx_gain = rx_gain * [1 1 1 1];
for rffe_rxg_final=ALL_rffe_rxg_final
rffe_rxg_final = rffe_rxg_final*[1 1 1 1];
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band);
sleep(1);
% signal measurement
gpib_send(gpib_card,gpib_device,'OUTP:STAT ON'); % activate output
sleep(.5);
s=oarf_get_frame(card);
sleep(.5);
SpN0(idx_power,idx_gain) = mean(abs(s(:,1)).^2) - abs(mean(s(:,1))).^2;
SpN1(idx_power,idx_gain) = mean(abs(s(:,2)).^2) - abs(mean(s(:,2))).^2;
figure(1);
hold off
plot(20*log10(abs(fft(s(:,1)))),'r',20*log10(abs(fft(s(:,2)))),'b')
title("Signal");
ylim([0 200]);
% noise measurement
gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
sleep(.5);
s=oarf_get_frame(card); %oarf_get_frame
sleep(.5);
N0(idx_power,idx_gain) = mean(abs(s(:,1)).^2) - abs(mean(s(:,1))).^2;
N1(idx_power,idx_gain) = mean(abs(s(:,2)).^2) - abs(mean(s(:,2))).^2;
figure(2);
hold off
plot(20*log10(abs(fft(s(:,1)))),'r',20*log10(abs(fft(s(:,2)))),'b')
title("Noise");
ylim([0 200]);
% do some plausibility checks
% if ((N0(idx_power,idx_gain) > SpN0(idx_power,idx_gain)) ||
% (N1(idx_power,idx_gain) > SpN1(idx_power,idx_gain)))
% error("something is wrong");
% end
S0(idx_power,idx_gain) = 10*log10(SpN0(idx_power,idx_gain)-N0(idx_power,idx_gain));
S1(idx_power,idx_gain) = 10*log10(SpN1(idx_power,idx_gain)-N1(idx_power,idx_gain));
G0(idx_power,idx_gain) = S0(idx_power,idx_gain) - power_dBm;
G1(idx_power,idx_gain) = S1(idx_power,idx_gain) - power_dBm;
NF0(idx_power,idx_gain) = 10*log10(N0(idx_power,idx_gain)) - G0(idx_power,idx_gain) + 105; % 108 is the thermal noise
NF1(idx_power,idx_gain) = 10*log10(N1(idx_power,idx_gain)) - G1(idx_power,idx_gain) + 105;
SNR0(idx_power,idx_gain) = S0(idx_power,idx_gain)-10*log10(N0(idx_power,idx_gain));
SNR1(idx_power,idx_gain) = S1(idx_power,idx_gain)-10*log10(N1(idx_power,idx_gain));
printf(' %d: Signal strength (%f,%f), Gain (%f %f), N (%f %f) SNR (%f %f) NF (%f %f)\n',
rx_gain(1), S0(idx_power,idx_gain),S1(idx_power,idx_gain),
G0(idx_power,idx_gain),G1(idx_power,idx_gain),
10*log10(N0(idx_power,idx_gain)),10*log10(N1(idx_power,idx_gain)),
SNR0(idx_power,idx_gain),SNR1(idx_power,idx_gain),
NF0(idx_power,idx_gain),NF1(idx_power,idx_gain));
fflush(stdout);
%fprintf(fid,'%d, %d, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n',
%power_dBm,gain2391,gain9862, S0,S1,G0,G1,10*log10(N0),10*log10(N1),SNR0,SNR1,NF0,NF1);
idx_gain = idx_gain + 1;
figure(3)
hold off
plot(ALL_rffe_rxg_final,G0,'o-','markersize',10)
hold on
plot(ALL_rffe_rxg_final,G1,'x-','markersize',10)
legend('Byp RX0','Med RX0','Max RX0','Byp RX1','Med RX1','Max RX1');
title('Gains')
figure(4)
hold off
plot(ALL_rffe_rxg_final,NF0,'o-','markersize',10)
hold on
plot(ALL_rffe_rxg_final,NF1,'x-','markersize',10)
legend('Byp RX0','Med RX0','Max RX0','Byp RX1','Med RX1','Max RX1');
title('Noise Figure')
end
end
idx_power = idx_power + 1;
end
end
%gpib_send(gpib_card,gpib_device,'OUTP:STAT OFF'); % deactivate output
%l0 = [ALL_gain2391; ones(size(ALL_gain2391))].'\G0;
%l1 = [ALL_gain2391; ones(size(ALL_gain2391))].'\G1;
dual_tx=0;
card=0;
limeparms;
active_rf = [1 1 1 1];
%rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM)*[1 1 1 1];
rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM)*active_rf;
rf_mode = rf_mode+(DMAMODE_RX*active_rf);
%freq_rx = 2540000000*[1 1 1 1];
freq_rx = 1917600000*active_rf;
%freq_rx = 1912600000*active_rf; %+ 2540000000*[0 1 0 0]; % + 859500000*[0 0 1 0];
%freq_rx = 1912600000*[1 1 1 1];
%freq_rx = 859500000*[1 1 1 1];
freq_tx = freq_rx; %+1.92e6;
%freq_tx = 2660000000*[1 1 1 1];
tx_gain = 0*[1 1 1 1];
rx_gain = 30*[1 1 1 1];
rf_local= [8254744 8255063 8257340 8257340]; %rf_local*[1 1 1 1];
%rf_local= [8254212 8256991 8257340 8257340]; %exmimo2 850mhz
rf_rxdc = rf_rxdc*[1 1 1 1];
%rf_vcocal=rf_vcocal_859*[1 1 1 1];
rf_vcocal=rf_vcocal_19G*[1 1 1 1];
eNBflag = 0;
tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_TESTRX;
%tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB;
syncmode = SYNCMODE_FREE;
rffe_rxg_low = 61*active_rf;
rffe_rxg_final = 61*active_rf;
rffe_band = B19G_TDD*active_rf;
autocal = [1 1 1 1];
oarf_config_exmimo(card,freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNBflag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band,autocal)
gpib_card=0; % first GPIB PCI card in the computer
gpib_device=28; % this is configured in the signal generator Utilities->System
cables_loss_dB = 6; % we need to account for the power loss between the signa
power_dBm = -95;
%gpib_send(gpib_card,gpib_device,['POW ' int2str(power_dBm+cables_loss_dB) 'dBm']);
%gpib_send(gpib_card,gpib_device,'OUTP:STAT ON'); % activate output
This source diff could not be displayed because it is too large. You can view the blob instead.
%fc = 2660000000;
fc = 1907600000;
%fc = 859.5e6;
rxgain=30;
txgain=25;
eNB_flag = 0;
card = 0;
limeparms;
rf_mode = (RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM) * [1 1 1 1];
rf_mode = rf_mode + (DMAMODE_TX)*[1 1 1 1];
%rf_mode = RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1;
%rf_local= [8253704 8253704 8257340 8257340]; %eNB2tx %850MHz
%rf_local= [8255004 8253440 8257340 8257340]; % ex2 700 MHz
rf_local = [8254744 8255063 8257340 8257340]; %eNB2tx 1.9GHz
%rf_local = [8257292 8257300 8257340 8257340]; %ex2 850 MHz
%rf_local = rf_local * ones(1,4);
rf_rxdc = rf_rxdc * ones(1,4);
%rf_vcocal = rf_vcocal_859 * ones(1,4);
rf_vcocal = rf_vcocal_19G * ones(1,4);
%rf_vcocal = rf_vcocal_26G_eNB * ones(1,4);
rxgain = rxgain*ones(1,4);
txgain = txgain*ones(1,4);
freq_tx = fc*[1 1 1 1];
freq_rx = freq_tx;
%freq_rx = freq_tx-120000000*[1 1 1 1];
%freq_tx = freq_rx+1920000;
tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_TESTTX;
syncmode = SYNCMODE_FREE;
rffe_rxg_low = 61*[1 1 1 1];
rffe_rxg_final = 61*[1 1 1 1];
rffe_band = B19G_TDD*[1 1 1 1];
autocal = [1 1 1 1];
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rxgain,txgain,eNB_flag,rf_mode,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band,autocal);
amp = pow2(14)-1;
n_bit = 16;
s = zeros(76800,4);
select = 1;
switch(select)
case 1
s(:,1) = floor(amp * (exp(sqrt(-1)*.5*pi*(0:((76800)-1)))));
s(:,2) = floor(amp * (exp(sqrt(-1)*.5*pi*(0:((76800)-1)))));
s(:,3) = floor(amp * (exp(sqrt(-1)*.5*pi*(0:((76800)-1)))));
s(:,4) = floor(amp * (exp(sqrt(-1)*.5*pi*(0:((76800)-1)))));
case 2
s(38400+128,1)= 80-1j*40;
s(38400+138,1)= -80+1j*40;
case 3
for i=0:(12*5-1)
s((38401+640*i):(38400+640*(i+1)),1)=floor(linspace(-127,128,640)); %+1j*floor(linspace(128,-127,640));
end
case 4
pss0_f0=[0,0,0,0,0,0,0,0,0,0,32767,0,-26120,-19785,11971,-30502,-24020,-22288,32117,6492,31311,9658,-16384,-28378,25100,-21063,-7292,-31946,20429,25618,14948,29158,11971,-30502,31311,9658,25100,-21063,-16384,28377,-24020,22287,32117,6492,-7292,31945,20429,25618,-26120,-19785,-16384,-28378,-16384,28377,-26120,-19785,-32402,4883,31311,-9659,32117,6492,-7292,-31946,32767,-1,25100,-21063,-24020,22287,-32402,4883,-32402,4883,-24020,22287,25100,-21063,32767,-1,-7292,-31946,32117,6492,31311,-9659,-32402,4883,-26120,-19785,-16384,28377,-16384,-28378,-26120,-19785,20429,25618,-7292,31945,32117,6492,-24020,22287,-16384,28377,25100,-21063,31311,9658,11971,-30502,14948,29158,20429,25618,-7292,-31946,25100,-21063,-16384,-28378,31311,9658,32117,6492,-24020,-22288,11971,-30502,-26120,-19785,32767,0,0,0,0,0,0,0,0,0,0,0];
pss0_f = pss0_f0(1:2:length(pss0_f0)) + sqrt(-1)*pss0_f0(2:2:length(pss0_f0));
pss0_f = [0 pss0_f(37:72) zeros(1,512-73) pss0_f(1:36)];
pss0_t = ifft(pss0_f);
pss0_t = [pss0_t((512-127):512) pss0_t];
pss0_t = [pss0_t zeros(1,512+36) pss0_t];
pss0_max = max(max(abs(real(pss0_t))),max(abs(imag(pss0_t))));
pss0_t_fp_re = floor(real(8192*pss0_t/pss0_max));
pss0_t_fp_im = floor(imag(8192*pss0_t/pss0_max));
s(38400+(1:length(pss0_t_fp_re)),1) = 2*floor(pss0_t_fp_re) + 2*sqrt(-1)*floor(pss0_t_fp_im);
s(38400+(1:length(pss0_t_fp_re)),2) = 2*floor(pss0_t_fp_re) + 2*sqrt(-1)*floor(pss0_t_fp_im);
otherwise
error('unknown case')
endswitch
s = s*2;
%s(38400:end,1) = (1+1j);
%s(38400:end,2) = (1+1j);
sleep (1)
%keyboard
oarf_send_frame(card,s,n_bit);
figure(1)
hold off
plot(real(s(:,1)),'r')
hold on
plot(imag(s(:,2)),'b')
dual_tx=1;
cbmimo1=0;
if (cbmimo1)
oarf_config(0,1,dual_tx,255);
amp = pow2(7)-1;
n_bit = 8;
else
oarf_config_exmimo(1902600000,1,dual_tx,30);
amp = pow2(15)-1;
n_bit = 16;
end
s = zeros(76800,2);
s(:,1) = 8*floor(amp*OFDM_TX_FRAME(512,211,128,120,8));
s(:,2) = 8*floor(amp*OFDM_TX_FRAME(512,211,128,120,8));
%s(:,1) = amp * (exp(sqrt(-1)*.5*pi*(0:((76800)-1))));
%s(:,2) = amp * (exp(sqrt(-1)*.5*pi*(0:((76800)-1))));
if (cbmimo1)
oarf_set_tx_gain(110,110,110,110);
end
oarf_send_frame(0,s,n_bit);
plot(20*log10(abs(fft(s(:,1)))))
# % Author: Wael Guibene, Mirsad Cirkic, Florian Kaltenberger
# % Organisation: Eurecom
# % E-mail: guibene@eurecom.fr
# % Model: A: the SMVB (1Tx), B: ExpressMIMO2 Card with 4Rx
clear all
initparams;
if(paramsinitialized && ~LSBSWITCH_FLAG)
disp(["\n\n------------\nThis code is, so far, only written for single runs. Multiple " ...
"runs will overwrite the previous measurement data, i.e., the " ...
"data structures are not defined for multiple runs. You will need to " ...
"add code in order to save the intermediate measurements and the " ...
"corresponding timestamps.\n------------"])
N=76800;
M=8;
indA=[1 0 0 0];%find(active_rfA==1);
indB=[1 2 3 4];%find(active_rfB==1);
Nanta=length(indA);
Nantb=length(indB);
% if(Nanta!=1)
% error("Node A can only have one antenna active\n");
% endif
Niter=1;
if(Niter!=1)
error("We should only use one get_frame at each run.\n");
endif
Nmeas = 1;
# %% ------- Prepare the signals for A2B ---------- %%
%rx_spec;
load where2_v1_final.mat
close all;
sig_ref=real(s2);
signalA2B=sig_ref;%zeros(N,4);
%signalB2A=zeros(N,4);
%ia=1; ib=1;
%Db2a_T=[];
%for i=1:4
% if(indA(ia)==i)
Da2b_T=data;
tmps=sig_ref;
% signalA2B(:,i)=tmps*2; %make sure LSB is 0 (switch=tx)
% signalB2A(:,i)=repmat(1+1j,76800,1); %make sure LSB is 1 (switch=rx)
% if(length(indA)> ia) ia=ia+1; endif
% endif
% % if(indB(ib)==i)
% % % This part could be improved by creating fully orthogonal sequences
% % [tmpd, tmps]=genrandpskseq(N,M,amp);
% % signalB2A(:,i)=tmps*2;
% % signalA2B(:,i)=repmat(1+1j,76800,1);
% % Db2a_T=[Db2a_T tmpd];
% % if(length(indB)> ib) ib=ib+1; endif
% % endif
%endfor
%#%%------------Prepare the signals for B2A---------------%%
% for i=1:4
% if(indB(ib)==i)
% [tmpd, tmps]=genrandpskseq(N,M,amp);
% signalB2A(:,i)=tmps*2; %make sure LSB is 0 (switch=tx)
% signalA2B(:,i)=repmat(1+1j,76800,1); %make sure LSB is 1 (switch=rx)
% Db2a_T=[Db2a_T tmpd];
% if(length(indB)> ib) ib=ib+1; endif
% endif
% endfor
% if (!chanest_full)
% signalB2A(1:38400,3)=0;
% signalB2A(38401:end,2)=0;
% Db2a_T(1:60,302:end) = 0;
% Db2a_T(61:end,1:301) = 0;
% end
% Da2b_R=zeros(Niter*120,Nantb*301,Nmeas);
% Db2a_R=zeros(Niter*120,Nanta*301,Nmeas);
for meas=1:Nmeas
# %% ------- Node A to B transmission ------- %%
%oarf_send_frame(card,signalA2B,n_bit);
%keyboard
%sleep(0.01);
receivedA2B1=oarf_get_frame(card);
initial_sync;
frame_start=abs(frame_start);
I= [frame_start:N,1:frame_start-1];
receivedA2B(:,1)=receivedA2B1(I',1);
receivedA2B(:,2)=receivedA2B1(I',2);
receivedA2B(:,3)=receivedA2B1(I',3);
receivedA2B(:,4)=receivedA2B1(I',4);
%oarf_stop(card); %not good, since it does a reset
%sleep(0.01);
#%%----------Node B to A transmission---------%%
% oarf_send_frame(card,signalB2A,n_bit);
% %keyboard
% sleep(0.01);
% receivedB2A=oarf_get_frame(card);
% %oarf_stop(card); %not good, since it does a reset
# %% ------- Do the A to B channel estimation ------- %%
for i=0:119;
ifblock=receivedA2B(i*640+[1:640],indB);
ifblock(1:128,:)=[];
fblock=fft(ifblock);
fblock(1,:)=[];
fblock(151:360,:)=[];
Da2b_R((Niter-1)*120+i+1,:,meas)=vec(fblock);
endfor
HA2B=repmat(conj(Da2b_T),Niter,Nantb).*Da2b_R(:,:,meas);
phasesA2B=unwrap(angle(HA2B));
if(mean(var(phasesA2B))>0.5)
disp("The phases of your estimates from A to B are a bit high (larger than 0.5 rad.), something is wrong.");
endif
chanestsA2B(:,:,meas)=reshape(diag(repmat(Da2b_T,Niter,Nantb)'*Da2b_R(:,:,meas))/size(Da2b_T,1),301,Nantb);
#fchanestsA2B=zeros(512,Nantb);
#for i=1:Nantb
# fchanestsA2B(:,i)=[0; chanestsA2B([1:150],i,meas); zeros(210,1); chanestsA2B(151:301,i,meas)];
#endfor
fchanestsA2B(:,:,meas)=[zeros(1,Nantb); chanestsA2B([1:150],:,meas); zeros(210,Nantb); chanestsA2B(151:301,:,meas)];
tchanestsA2B(:,:,meas)=ifft(fchanestsA2B(:,:,meas));
%% ------- Do the B to A channel estimation ------- %%
% for i=0:119;
% ifblock=receivedB2A(i*640+[1:640],indA);
% ifblock(1:128,:)=[];
% fblock=fft(ifblock);
% fblock(1,:)=[];
% fblock(151:360,:)=[];
% Db2a_R((Niter-1)*120+i+1,:,meas)=fblock.';
% endfor
% HB2A=conj(repmat(Db2a_T,Niter,1)).*repmat(Db2a_R(:,:,meas),1,Nantb);
% phasesB2A=unwrap(angle(HB2A));
% if(mean(var(phasesB2A))>0.5)
% disp("The phases of your estimates from B to A are a bit high (larger than 0.5 rad.), something is wrong.");
% endif
% if (chanest_full)
% chanestsB2A(:,:,meas)=zeros(301,Nantb);
% inds=repmat([1:Nantb]',1,301);
% for ci=1:301;
% data=Db2a_T(:,ci+[0:Nantb-1]*301);
% rec=Db2a_R(:,ci,meas);
% chanestsB2A(ci,:,meas)=(inv(data'*data)*data'*rec).';
% endfor
% else
% chanestsB2A(:,:,meas)=reshape(diag(repmat(Db2a_T,Niter,1)'*repmat(Db2a_R(:,:,meas),1,Nantb)/(Niter*60)),301,Nantb);
% end
#fchanestsB2A=zeros(512,Nantb);
#for i=1:Nantb
# fchanestsB2A(:,i)=[0; chanestsB2A([1:150],i); zeros(210,1); chanestsB2A(151:301,i)];
#endfor
%fchanestsB2A(:,:,meas) = [zeros(1,Nantb); chanestsB2A([1:150],:,meas); zeros(210,Nantb); chanestsB2A(151:301,:,meas)];
% tchanestsB2A(:,:,meas)=ifft(fchanestsB2A(:,:,meas));
end
%% -- Some plotting code -- %% (you can uncomment what you see fit)
received = receivedA2B;
phases = phasesA2B;
tchanests = [tchanestsA2B(:,:,end)];% , tchanestsB2A(:,:,end)];
fchanests = [fchanestsA2B(:,:,end)];% , fchanestsB2A(:,:,end)];
clf
figure(1)
for i=1:4
subplot(220+i);plot(20*log10(abs(fftshift(fft(received(:,i))))));
endfor
figure(2)
t=[0:512-1]/512*1e-2;
plot(t,20*log10(abs(tchanests)))
xlabel('time')
ylabel('|h|')
legend('SigGEN->Antenna1','SigGEN->Antenna2','SigGEN->Antenna3','SigGEN->Antenna4');
figure(4)
plot(20*log10(abs(fchanests)));
ylim([40 100])
xlabel('freq')
ylabel('|h|')
legend('SigGEN->Antenna1','SigGEN->Antenna2','SigGEN->Antenna3','SigGEN->Antenna4');
i=1
if (i==0)
figure(3)
wndw = 50;
for i=1:5:Nantb*301 %# sliding window size
phamean = filter(ones(wndw,1)/wndw, 1, phases(:,i)); %# moving average
plot(phamean(wndw:end),'LineWidth',2);
title(['subcarrier ' num2str(i)]);
xlabel('time')
ylabel('phase')
ylim([-pi pi])
drawnow;
pause(0.1)
endfor
phavar=var(phases);
plotphavar=[];
for i=0:Nantb-1
plotphavar=[plotphavar; phavar([1:301]+i*301)];
endfor
plot([1:150 362:512],plotphavar,'o');
%ylim([0 pi])
xlabel('subcarrier')
ylabel('phase variance')
end
endif
%else
% if(LSBSWITCH_FLAG) error("You have to unset the LSB switch flag (LSBSWITCH_FLAG) in initparams.m.\n")
% else error("You have to run init.params.m first!")
% endif
%endif
This diff is collapsed.
clear all
Nmeas=1
rx_spec
for meas=1:Nmeas
close all
receivedA2B1=oarf_get_frame(card);
initial_sync
N=76800;
indA=[1 0 0 0];
indB=[1 2 3 4];
Nanta=length(indA);
Nantb=length(indB);
fchan=zeros(512,Nantb);
tchan=fchan;
frame_start=abs(frame_start)
I= [frame_start:N,1:frame_start-1];
receivedA2B=receivedA2B1(I',:);
%load where2_v1_final.mat
load filesave0811.mat
Nofs=3840; % The offset in samples between the downlink and uplink sequences. It must be a multiple of 640, 3840 samples is 0.5 ms.
maskA2B=kron(ones(1,N/(2*Nofs)),[ones(1,Nofs) zeros(1,Nofs)])';
datamaskA2B=diag(kron(ones(1,N/(2*Nofs)),[ones(1,Nofs/640) zeros(1,Nofs/640)]));
signalA2B=s2;
Da2b_T=datamaskA2B*data;
%tmps=s2;
Niter=1
Da2b_R=zeros(Niter*120,Nantb*301);
for i=0:119;
ifblock=receivedA2B(i*640+[1:640],indB);
ifblock(1:128,:)=[];
fblock=fft(ifblock);
fblock(1,:)=[];
fblock(151:360,:)=[];
Da2b_R((Niter-1)*120+i+1,:)=vec(fblock);
endfor
HA2B=repmat(conj(Da2b_T),1,Nantb).*Da2b_R;
phasesA2B=unwrap(angle(HA2B));
chanestsA2B=reshape(diag(repmat(Da2b_T,1,Nantb)'*Da2b_R)/size(Da2b_T,1),301,Nantb);
fchanestsA2B=zeros(512,Nantb);
for i=1:Nantb
fchanestsA2B(:,i)=[0; chanestsA2B([1:150],i); zeros(210,1); chanestsA2B(151:301,i)];
endfor
tchanestsA2B=ifft(fchanestsA2B);
fchan=fchanestsA2B+fchan;
end %% Nmeas
siglevel0_dB=10*log10(sum(abs((receivedA2B(:,1)-mean(receivedA2B(:,1))).^2))/length(receivedA2B(:,1)));
siglevel1_dB=10*log10(sum(abs((receivedA2B(:,2)-mean(receivedA2B(:,2))).^2))/length(receivedA2B(:,2)));
siglevel2_dB=10*log10(sum(abs((receivedA2B(:,3)-mean(receivedA2B(:,3))).^2))/length(receivedA2B(:,3)));
siglevel3_dB=10*log10(sum(abs((receivedA2B(:,4)-mean(receivedA2B(:,4))).^2))/length(receivedA2B(:,4)));
fprintf("SigLevels : %2.2f dB,%2.2f dB,%2.2f dB,%2.2f dB\n",siglevel0_dB,siglevel1_dB,siglevel2_dB,siglevel3_dB);
received = receivedA2B;
fchanests = [fchan(:,:)/Nmeas];
tchanests = ifft((fchan));
plots
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment