Commit c1088427 authored by Florian Kaltenberger's avatar Florian Kaltenberger

changed to matlab formatting


git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4360 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 35674e5d
# % Author: Mirsad Cirkic, Florian Kaltenberger % 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 ' ...
"add code in order to save the intermediate measurements and the " ... 'add code in order to save the intermediate measurements and the ' ...
"corresponding timestamps.\n------------"]) 'corresponding timestamps.\n------------'])
N=76800; N=76800;
M=4; M=4;
Ntaps=8; Ntaps=8;
...@@ -15,16 +15,16 @@ if(paramsinitialized && ~LSBSWITCH_FLAG) ...@@ -15,16 +15,16 @@ if(paramsinitialized && ~LSBSWITCH_FLAG)
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) if(Nanta~=1)
error("Node A can only have one antenna active\n"); error('Node A can only have one antenna active\n');
endif end
Niter=1; Niter=1;
if(Niter!=1) if(Niter~=1)
error("We should only use one get_frame at each run.\n"); error('We should only use one get_frame at each run.\n');
endif end
Nmeas = 10; Nmeas = 10;
# %% ------- Prepare the signals for A2B ---------- %% %% ------- Prepare the signals for A2B ---------- %%
signalA2B=zeros(N,4,Nmeas); signalA2B=zeros(N,4,Nmeas);
signalB2A=zeros(N,4,Nmeas); signalB2A=zeros(N,4,Nmeas);
Db2a_T=[]; Db2a_T=[];
...@@ -36,20 +36,20 @@ if(paramsinitialized && ~LSBSWITCH_FLAG) ...@@ -36,20 +36,20 @@ if(paramsinitialized && ~LSBSWITCH_FLAG)
[tmpd, tmps]=genrandpskseq(N,M,amp); [tmpd, tmps]=genrandpskseq(N,M,amp);
signalA2B(:,i,meas)=tmps; %make sure LSB is 0 (switch=tx) signalA2B(:,i,meas)=tmps; %make sure LSB is 0 (switch=tx)
Dtmp=[Dtmp tmpd]; Dtmp=[Dtmp tmpd];
if(length(indA)> ia) ia=ia+1; endif if(length(indA)> ia) ia=ia+1; end
endif end
% if(indB(ib)==i) % if(indB(ib)==i)
% % This part could be improved by creating fully orthogonal sequences % % 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*2; % signalB2A(:,i)=tmps*2;
% signalA2B(:,i)=repmat(1+1j,76800,1); % signalA2B(:,i)=repmat(1+1j,76800,1);
% Db2a_T=[Db2a_T tmpd]; % Db2a_T=[Db2a_T tmpd];
% if(length(indB)> ib) ib=ib+1; endif % if(length(indB)> ib) ib=ib+1; end
% endif % end
endfor end
Da2b_T=[Da2b_T; Dtmp]; Da2b_T=[Da2b_T; Dtmp];
#%%------------Prepare the signals for B2A---------------%% %%------------Prepare the signals for B2A---------------%%
Dtmp=[]; Dtmp=[];
for i=1:4 for i=1:4
if(indB(ib)==i) if(indB(ib)==i)
...@@ -57,17 +57,17 @@ if(paramsinitialized && ~LSBSWITCH_FLAG) ...@@ -57,17 +57,17 @@ if(paramsinitialized && ~LSBSWITCH_FLAG)
signalB2A(:,i,meas)=tmps*2; %make sure LSB is 0 (switch=tx) signalB2A(:,i,meas)=tmps*2; %make sure LSB is 0 (switch=tx)
signalA2B(:,i,meas)=repmat(1+1j,76800,1); %make sure LSB is 1 (switch=rx) signalA2B(:,i,meas)=repmat(1+1j,76800,1); %make sure LSB is 1 (switch=rx)
Dtmp=[Dtmp tmpd]; Dtmp=[Dtmp tmpd];
if(length(indB)> ib) ib=ib+1; endif if(length(indB)> ib) ib=ib+1; end
endif end
endfor end
Db2a_T=[Db2a_T; Dtmp]; Db2a_T=[Db2a_T; Dtmp];
endfor end
Da2b_R=zeros(Nmeas*120,Nantb*301); Da2b_R=zeros(Nmeas*120,Nantb*301);
Db2a_R=zeros(Nmeas*120,Nanta*301); Db2a_R=zeros(Nmeas*120,Nanta*301);
for meas=1:Nmeas for meas=1:Nmeas
# %% ------- Node A to B transmission ------- %% %% ------- Node A to B transmission ------- %%
oarf_send_frame(card,squeeze(signalA2B(:,:,meas)),n_bit); oarf_send_frame(card,squeeze(signalA2B(:,:,meas)),n_bit);
%keyboard %keyboard
sleep(0.01); sleep(0.01);
...@@ -75,14 +75,14 @@ for meas=1:Nmeas ...@@ -75,14 +75,14 @@ for meas=1:Nmeas
%oarf_stop(card); %not good, since it does a reset %oarf_stop(card); %not good, since it does a reset
sleep(0.01); sleep(0.01);
#%%----------Node B to A transmission---------%% %%----------Node B to A transmission---------%%
oarf_send_frame(card,squeeze(signalB2A(:,:,meas)),n_bit); oarf_send_frame(card,squeeze(signalB2A(:,:,meas)),n_bit);
%keyboard %keyboard
sleep(0.01); sleep(0.01);
receivedB2A=oarf_get_frame(card); receivedB2A=oarf_get_frame(card);
%oarf_stop(card); %not good, since it does a reset %oarf_stop(card); %not good, since it does a reset
# %% ------- Do the A to B signal post preparation ------- %% %% ------- 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,:)=[];
...@@ -90,10 +90,10 @@ for meas=1:Nmeas ...@@ -90,10 +90,10 @@ for meas=1:Nmeas
fblock(1,:)=[]; fblock(1,:)=[];
fblock(151:360,:)=[]; fblock(151:360,:)=[];
Da2b_R((meas-1)*120+i+1,:)=vec(fblock); Da2b_R((meas-1)*120+i+1,:)=vec(fblock);
endfor end
%% ------- Do the B to A signal post preparation ------- %% %% ------- Do the B to A signal post preparation ------- %%
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,:)=[];
...@@ -101,26 +101,26 @@ for meas=1:Nmeas ...@@ -101,26 +101,26 @@ for meas=1:Nmeas
fblock(1,:)=[]; fblock(1,:)=[];
fblock(151:360,:)=[]; fblock(151:360,:)=[];
Db2a_R((meas-1)*120+i+1,:)=fblock.'; Db2a_R((meas-1)*120+i+1,:)=fblock.';
endfor end
endfor end
# %% ------- Do the A to B channel estimation ------- %% %% ------- Do the A to B channel estimation ------- %%
HA2B=repmat(conj(Da2b_T),1,Nantb).*Da2b_R; HA2B=repmat(conj(Da2b_T),1,Nantb).*Da2b_R;
phasesA2B=unwrap(angle(HA2B)); phasesA2B=unwrap(angle(HA2B));
if(mean(var(phasesA2B))>0.5) 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."); disp('The phases of your estimates from A to B are a bit high (larger than 0.5 rad.), something is wrong.');
endif end
DA2B=repmat(Da2b_T,1,Nantb); DA2B=repmat(Da2b_T,1,Nantb);
chanestsA2B=reshape(diag(DA2B'*Da2b_R)./diag(DA2B'*DA2B),301,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,:)]; fchanestsA2B=[zeros(1,Nantb); chanestsA2B([1:150],:); zeros(210,Nantb); chanestsA2B(151:301,:)];
tchanestsA2B=ifft(fchanestsA2B); tchanestsA2B=ifft(fchanestsA2B);
# %% ------- Do the B to A channel estimation ------- %% %% ------- Do the B to A channel estimation ------- %%
HB2A=conj(Db2a_T.*repmat(Db2a_R,1,Nantb)); 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 from B to A 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 end
if (chanest_full) if (chanest_full)
chanestsB2A=zeros(301,Nantb); chanestsB2A=zeros(301,Nantb);
...@@ -129,19 +129,20 @@ endfor ...@@ -129,19 +129,20 @@ endfor
data=Db2a_T(:,ci+[0:Nantb-1]*301); data=Db2a_T(:,ci+[0:Nantb-1]*301);
rec=Db2a_R(:,ci); rec=Db2a_R(:,ci);
chanestsB2A(ci,:)=(inv(data'*data)*data'*rec).'; chanestsB2A(ci,:)=(inv(data'*data)*data'*rec).';
endfor end
else else
chanestsB2A=reshape(diag(Db2a_T'*repmat(Db2a_R,1,Nantb)/(Nmeas*60)),301,Nantb); chanestsB2A=reshape(diag(Db2a_T'*repmat(Db2a_R,1,Nantb)/(Nmeas*60)),301,Nantb);
end end
#fchanestsB2A=zeros(512,Nantb); %fchanestsB2A=zeros(512,Nantb);
#for i=1:Nantb %for i=1:Nantb
# fchanestsB2A(:,i)=[0; chanestsB2A([1:150],i); zeros(210,1); chanestsB2A(151:301,i)]; % fchanestsB2A(:,i)=[0; chanestsB2A([1:150],i); zeros(210,1); chanestsB2A(151:301,i)];
#endfor %end
fchanestsB2A = [zeros(1,Nantb); chanestsB2A([1:150],:); zeros(210,Nantb); chanestsB2A(151:301,:)]; fchanestsB2A = [zeros(1,Nantb); chanestsB2A([1:150],:); zeros(210,Nantb); chanestsB2A(151:301,:)];
tchanestsB2A=ifft(fchanestsB2A); tchanestsB2A=ifft(fchanestsB2A);
% save *chanests*
% save DA2B_T DA2B_R DB2A_T DB2A_R in seperate file
%% -- Some plotting code -- %% (you can uncomment what you see fit) %% -- Some plotting code -- %% (you can uncomment what you see fit)
...@@ -154,7 +155,7 @@ endfor ...@@ -154,7 +155,7 @@ endfor
figure(1) figure(1)
for i=1:4 for i=1:4
subplot(220+i);plot(20*log10(abs(fftshift(fft(received(:,i)))))); subplot(220+i);plot(20*log10(abs(fftshift(fft(received(:,i))))));
endfor end
figure(2) figure(2)
t=[0:512-1]/512*1e-2; t=[0:512-1]/512*1e-2;
...@@ -184,12 +185,12 @@ endfor ...@@ -184,12 +185,12 @@ endfor
ylim([-pi pi]) ylim([-pi pi])
drawnow; drawnow;
pause(0.1) pause(0.1)
endfor end
phavar=var(phases); 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)];
endfor end
plot([1:150 362:512],plotphavar,'o'); plot([1:150 362:512],plotphavar,'o');
%ylim([0 pi]) %ylim([0 pi])
xlabel('subcarrier') xlabel('subcarrier')
...@@ -197,7 +198,7 @@ endfor ...@@ -197,7 +198,7 @@ endfor
end end
else else
if(LSBSWITCH_FLAG) error("You have to unset 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 end
endif end
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