Commit 35674e5d authored by Florian Kaltenberger's avatar Florian Kaltenberger

renamed runmeas_woduplex.m -> runmeas_full_duplex.m

deleted runmeas_wduplex.m
added runmeas_long_chanest.m

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4359 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 55028fbb
% do some beamforming % do some beamforming
signalA2B=zeros(N,4); signalA2B=zeros(N,4);
signalB2A=zeros(N,4); signalB2A=zeros(N,4);
signalB2A_prec=zeros(N,4); signalB2A_prec_full=zeros(N,4);
signalB2A_diag=zeros(N,4); signalB2A_prec_diag=zeros(N,4);
%%----------Node A to B transmission---------%% %%----------Node A to B transmission---------%%
for i=1:4 for i=1:4
......
# % Author: Mirsad Cirkic # % Author: Mirsad Cirkic, Florian Kaltenberger
# % Organisation: Eurecom (and Linkoping University) # % Organisation: Eurecom (and Linkoping University)
# % E-mail: mirsad.cirkic@liu.se # % E-mail: mirsad.cirkic@liu.se
if(paramsinitialized && LSBSWITCH_FLAG) if(paramsinitialized && ~LSBSWITCH_FLAG)
disp(["\n\n------------\nThis code is, so far, only written for single runs. Multiple " ... disp(["\n\n------------\nThis code is, so far, only written for single runs. Multiple " ...
"runs will overwrite the previous measurement data, i.e., the " ... "runs will overwrite the previous measurement data, i.e., the " ...
"data structures are not defined for multiple runs. You will need to " ... "data structures are not defined for multiple runs. You will need to " ...
...@@ -10,110 +10,173 @@ if(paramsinitialized && LSBSWITCH_FLAG) ...@@ -10,110 +10,173 @@ if(paramsinitialized && LSBSWITCH_FLAG)
"corresponding timestamps.\n------------"]) "corresponding timestamps.\n------------"])
N=76800; N=76800;
M=4; M=4;
Ntaps=8;
indA=find(active_rfA==1); indA=find(active_rfA==1);
indB=find(active_rfB==1); indB=find(active_rfB==1);
Nanta=length(indA); Nanta=length(indA);
Nantb=length(indB); Nantb=length(indB);
if(Nanta!=1)
error("Node A can only have one antenna active\n");
endif
Niter=1; Niter=1;
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. if(Niter!=1)
if(mod(Nofs,640)!=0) error("blabla") endif error("We should only use one get_frame at each run.\n");
endif
if(Nanta!=1) error("Node A can only have one antenna active\n"); endif Nmeas = 10;
if(Niter!=1) error("We should only use one get_frame at each run.\n"); endif
# %% ------- Prepare the signals for A2B ---------- %%
# %% ------- Prepare the signals for both A2B and B2A ------- % signalA2B=zeros(N,4,Nmeas);
maskA2B=kron(ones(1,N/(2*Nofs)),[ones(1,Nofs) zeros(1,Nofs)])'; signalB2A=zeros(N,4,Nmeas);
maskB2A=ones(N,1)-maskA2B;
datamaskA2B=diag(kron(ones(1,N/(2*Nofs)),[ones(1,Nofs/640) zeros(1,Nofs/640)]));
datamaskB2A=eye(N/640)-datamaskA2B;
signalA2B=zeros(N,4);
signalB2A=zeros(N,4);
ia=1; ib=1;
Db2a_T=[]; Db2a_T=[];
for meas=1:Nmeas
ia=1; ib=1;
Dtmp=[];
for i=1:4 for i=1:4
if(indA(ia)==i) if(indA(ia)==i)
[tmpd, tmps]=genrandpskseq(N,M,amp); [tmpd, tmps]=genrandpskseq(N,M,amp);
Da2b_T=datamaskA2B*tmpd; signalA2B(:,i,meas)=tmps; %make sure LSB is 0 (switch=tx)
signalA2B(:,i)=tmps*4.*maskA2B+maskB2A*sqrt(-1); %Added maskB2A to set the LSB correctly. The factor 4 there should make a 2 bit shift. Don't know if that is correct Dtmp=[Dtmp tmpd];
if(length(indA)> ia) ia=ia+1; endif if(length(indA)> ia) ia=ia+1; endif
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
Da2b_T=[Da2b_T; Dtmp];
#%%------------Prepare the signals for B2A---------------%%
Dtmp=[];
for i=1:4
if(indB(ib)==i) if(indB(ib)==i)
% This part could be improved by creating fully orthogonal sequences
[tmpd, tmps]=genrandpskseq(N,M,amp); [tmpd, tmps]=genrandpskseq(N,M,amp);
signalB2A(:,i)=tmps*4.*maskB2A+maskA2B*sqrt(-1); %Added maskA2B to set the LSB correctly. The factor 4 there should make a 2 bit shift. Don't know if that is correct. signalB2A(:,i,meas)=tmps*2; %make sure LSB is 0 (switch=tx)
Db2a_T=[Db2a_T datamaskB2A*tmpd]; signalA2B(:,i,meas)=repmat(1+1j,76800,1); %make sure LSB is 1 (switch=rx)
Dtmp=[Dtmp tmpd];
if(length(indB)> ib) ib=ib+1; endif if(length(indB)> ib) ib=ib+1; endif
endif endif
endfor endfor
Db2a_T=[Db2a_T; Dtmp];
endfor
signal = signalA2B+signalB2A; Da2b_R=zeros(Nmeas*120,Nantb*301);
Db2a_R=zeros(Nmeas*120,Nanta*301);
# %% ------- Node B and A duplex transmission/reception ------- %%
rf_mode_current = rf_mode + (DMAMODE_TX+TXEN+DMAMODE_RX+RXEN)*active_rf; for meas=1:Nmeas
oarf_config_exmimo(card, freq_rx,freq_tx,tdd_config,syncmode,rx_gain,tx_gain,eNB_flag,rf_mode_current,rf_rxdc,rf_local,rf_vcocal,rffe_rxg_low,rffe_rxg_final,rffe_band,autocal_mode); # %% ------- Node A to B transmission ------- %%
oarf_send_frame(card,signal,n_bit); oarf_send_frame(card,squeeze(signalA2B(:,:,meas)),n_bit);
received=oarf_get_frame(card); %keyboard
oarf_stop(card); sleep(0.01);
receivedA2B=received.*repmat(maskA2B,1,4); receivedA2B=oarf_get_frame(card);
receivedB2A=received.*repmat(maskB2A,1,4); %oarf_stop(card); %not good, since it does a reset
sleep(0.01);
# %% ------- Do the A to B channel estimation ------- %%
Da2b_R=zeros(Niter*120,Nantb*301); #%%----------Node B to A transmission---------%%
oarf_send_frame(card,squeeze(signalB2A(:,:,meas)),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 signal post preparation ------- %%
for i=0:119; for i=0:119;
ifblock=receivedA2B(i*640+[1:640],indB); ifblock=receivedA2B(i*640+[1:640],indB);
ifblock(1:128,:)=[]; ifblock(1:128,:)=[];
fblock=fft(ifblock); fblock=fft(ifblock);
fblock(1,:)=[]; fblock(1,:)=[];
fblock(151:360,:)=[]; fblock(151:360,:)=[];
Da2b_R((Niter-1)*120+i+1,:)=vec(fblock); Da2b_R((meas-1)*120+i+1,:)=vec(fblock);
endfor endfor
HA2B=repmat(conj(Da2b_T),1,Nantb).*Da2b_R;
phasesA2B=unwrap(angle(HA2B));
if(mean(var(phasesA2B))>0.5)
disp("The phases of your estimates are a bit high (larger than 0.5 rad.), something is wrong.");
endif
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);
%% ------- Do the B to A channel estimation ------- %% %% ------- Do the B to A signal post preparation ------- %%
Db2a_R=zeros(Niter*120,Nanta*301);
for i=0:119; for i=0:119;
ifblock=receivedB2A(i*640+[1:640],indA); ifblock=receivedB2A(i*640+[1:640],indA);
ifblock(1:128,:)=[]; ifblock(1:128,:)=[];
fblock=fft(ifblock); fblock=fft(ifblock);
fblock(1,:)=[]; fblock(1,:)=[];
fblock(151:360,:)=[]; fblock(151:360,:)=[];
Db2a_R((Niter-1)*120+i+1,:)=fblock.'; Db2a_R((meas-1)*120+i+1,:)=fblock.';
endfor endfor
HB2A=conj(repmat(Db2a_T,Niter,1)).*repmat(Db2a_R,1,Nantb); endfor
# %% ------- Do the A to B channel estimation ------- %%
HA2B=repmat(conj(Da2b_T),1,Nantb).*Da2b_R;
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
DA2B=repmat(Da2b_T,1,Nantb);
chanestsA2B=reshape(diag(DA2B'*Da2b_R)./diag(DA2B'*DA2B),301,Nantb);
fchanestsA2B=[zeros(1,Nantb); chanestsA2B([1:150],:); zeros(210,Nantb); chanestsA2B(151:301,:)];
tchanestsA2B=ifft(fchanestsA2B);
# %% ------- Do the B to A channel estimation ------- %%
HB2A=conj(Db2a_T.*repmat(Db2a_R,1,Nantb));
phasesB2A=unwrap(angle(HB2A)); phasesB2A=unwrap(angle(HB2A));
if(mean(var(phasesB2A))>0.5) if(mean(var(phasesB2A))>0.5)
disp("The phases of your estimates are a bit high (larger than 0.5 rad.), something is wrong."); disp("The phases of your estimates from B to A are a bit high (larger than 0.5 rad.), something is wrong.");
endif endif
chanestsB2A=reshape(diag(repmat(Db2a_T,Niter,1)'*repmat(Db2a_R,1,Nantb)/(Niter*120)),301,Nantb);
if (chanest_full)
chanestsB2A=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);
chanestsB2A(ci,:)=(inv(data'*data)*data'*rec).';
endfor
else
chanestsB2A=reshape(diag(Db2a_T'*repmat(Db2a_R,1,Nantb)/(Nmeas*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 = [zeros(1,Nantb); chanestsB2A([1:150],:); zeros(210,Nantb); chanestsB2A(151:301,:)];
tchanestsB2A=ifft(fchanestsB2A);
%% -- Some plotting code -- %% (you can uncomment what you see fit) %% -- Some plotting code -- %% (you can uncomment what you see fit)
received = receivedB2A;
phases = phasesB2A;
tchanests = [tchanestsA2B(:,:,end), tchanestsB2A(:,:,end)];
fchanests = [fchanestsA2B(:,:,end), fchanestsB2A(:,:,end)];
clf clf
figure(1) figure(1)
for i=1:4 for i=1:4
subplot(220+i);plot(20*log10(abs(fftshift(fft(receivedA2B(:,i)))))); subplot(220+i);plot(20*log10(abs(fftshift(fft(received(:,i))))));
endfor endfor
figure(2) figure(2)
t=[0:512-1]/512*1e-2; t=[0:512-1]/512*1e-2;
plot(t,abs(tchanestsA2B)) plot(t,20*log10(abs(tchanests)))
xlabel('time') xlabel('time')
ylabel('|h|') ylabel('|h|')
legend('A->B1','A->B2','A->B3','B1->A','B2->A','B3->A');
%legend('A->B1','A->B2','B1->A','B2->A');
figure(4)
plot(20*log10(abs(fchanests)));
ylim([40 100])
xlabel('freq')
ylabel('|h|')
legend('A->B1','A->B2','A->B3','B1->A','B2->A','B3->A');
%legend('A->B1','A->B2','B1->A','B2->A');
if (0)
figure(3) figure(3)
wndw = 50; wndw = 50;
for i=1:5:Nantb*301 %# sliding window size for i=1:5:Nantb*301 %# sliding window size
phamean = filter(ones(wndw,1)/wndw, 1, phasesA2B(:,i)); %# moving average phamean = filter(ones(wndw,1)/wndw, 1, phases(:,i)); %# moving average
plot(phamean(wndw:end),'LineWidth',2); plot(phamean(wndw:end),'LineWidth',2);
title(['subcarrier ' num2str(i)]); title(['subcarrier ' num2str(i)]);
xlabel('time') xlabel('time')
...@@ -122,7 +185,7 @@ if(paramsinitialized && LSBSWITCH_FLAG) ...@@ -122,7 +185,7 @@ if(paramsinitialized && LSBSWITCH_FLAG)
drawnow; drawnow;
pause(0.1) pause(0.1)
endfor endfor
phavar=var(phasesA2B); phavar=var(phases);
plotphavar=[]; plotphavar=[];
for i=0:Nantb-1 for i=0:Nantb-1
plotphavar=[plotphavar; phavar([1:301]+i*301)]; plotphavar=[plotphavar; phavar([1:301]+i*301)];
...@@ -131,23 +194,10 @@ if(paramsinitialized && LSBSWITCH_FLAG) ...@@ -131,23 +194,10 @@ if(paramsinitialized && LSBSWITCH_FLAG)
%ylim([0 pi]) %ylim([0 pi])
xlabel('subcarrier') xlabel('subcarrier')
ylabel('phase variance') ylabel('phase variance')
end
# figure(4)
# plot(20*log10(abs(fchanests))), ylim([40 100])
# %end
# fprintf(' done\n')
# for i=0:(Nantb-1)
# fchanests(:,i+1)=[0; chanests(301*i+[1:150]); zeros(210,1); chanests(301*i+[151:301])];
# endfor
# tchanests=ifft(fchanests);
else else
if(!LSBSWITCH_FLAG) error("You have to set the LSB switch flag (LSBSWITCH_FLAG) in initparams.m.\n") 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!") else error("You have to run init.params.m first!")
endif endif
endif endif
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