Commit 90f6924a authored by Cirkic's avatar Cirkic
Browse files

Refined the code so as to make it more readable.

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4039 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 4380042c
function [carrierdata, s]=genorthqpskseq(Ns,N,amp)
if(N!=512*150)
error('The sequence length must be 76800.');
endif
s = zeros(N,Ns);
H=1; for k=1:log2(128) H=[H H; H -H]; end; H=H(:,1:120);
i=1; while(i<size(H,1)) h=H(i,:); inds=find(h*H'!=0); H(inds,:)=[]; H=[h; H]; i=i+1; end
Hc=H+sqrt(-1)*H;
if(sum(Hc*Hc'-240*eye(8))>0) error("The code is not orhtogonal\n"); endif
carrierdata=zeros(120,Ns*301);
orthinds=1:8;
for i=1:301
for k=1:Ns
randind=ceil((9-k)*rand());
carrierdata(:,i+(k-1)*301)=Hc(orthinds(randind),:)';
orthinds(randind)=[];
endfor
endfor
for k=1:Ns
for i=0:119
fblock=[0 carrierdata(i,1:150) zeros(1,210) carrierdata(i,151:301)];
ifblock=ifft(fblock,512);
block = [ifblock(end-127:end) ifblock]; # Cycl. prefix
s([1:640]+i*640,k)=floor(amp*block);
endfor
endfor
endfunction
\ No newline at end of file
# % Author: Mirsad Cirkic
# % Organisation: Eurecom (and Linkoping University)
# % E-mail: mirsad.cirkic@liu.se
function [carrierdata, s]=genorthqpskseq(Ns,N,amp) function [carrierdata, s]=genorthqpskseq(Ns,N,amp)
if(N!=512*150) if(N!=512*150)
......
# % Author: Mirsad Cirkic
# % Organisation: Eurecom (and Linkoping University)
# % E-mail: mirsad.cirkic@liu.se
function [carrierdata, s]=genrandpskseq(N,M,amp) function [carrierdata, s]=genrandpskseq(N,M,amp)
if(mod(N,640)~=0) if(mod(N,640)~=0)
......
# % Author: Mirsad Cirkic
# % Organisation: Eurecom (and Linkoping University)
# % E-mail: mirsad.cirkic@liu.se
clear clear
paramsinitialized=false; paramsinitialized=false;
limeparms; limeparms;
...@@ -8,7 +12,7 @@ card = 0; ...@@ -8,7 +12,7 @@ card = 0;
Ntrx=4; Ntrx=4;
dual_tx=0; dual_tx=0;
active_rfA=[1 0 0 0]; active_rfA=[1 0 0 0];
active_rfB=[0 1 1 0]; active_rfB=[0 1 0 0];
active_rf=active_rfA+active_rfB; active_rf=active_rfA+active_rfB;
%fc = 2660000000; %fc = 2660000000;
......
# % Author: Mirsad Cirkic
# % Organisation: Eurecom (and Linkoping University)
# % E-mail: mirsad.cirkic@liu.se
if(paramsinitialized) if(paramsinitialized)
N=76800; N=76800;
M=4; M=4;
...@@ -116,7 +120,7 @@ if(paramsinitialized) ...@@ -116,7 +120,7 @@ if(paramsinitialized)
oarf_stop(card); oarf_stop(card);
# # -- Do the channel estimation # # -- Do the channel estimation
chanests=reshape(diag(repmat(Db2a_T,Niter,1)'*repmat(Db2a_R,1,Nantb)/(Niter*120)),301,Nantb) chanests=reshape(diag(repmat(Db2a_T,Niter,1)'*repmat(Db2a_R,1,Nantb)/(Niter*120)),301,Nantb);
H=conj(repmat(Db2a_T,Niter,1)).*repmat(Db2a_R,1,Nantb); H=conj(repmat(Db2a_T,Niter,1)).*repmat(Db2a_R,1,Nantb);
phases=unwrap(angle(H)); phases=unwrap(angle(H));
# for i=0:(Nantb-1) # for i=0:(Nantb-1)
......
# % Author: Mirsad Cirkic
# % Organisation: Eurecom (and Linkoping University)
# % E-mail: mirsad.cirkic@liu.se
if(paramsinitialized)
disp("This 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.")
N=76800;
M=4;
signalB2A=zeros(N,1);
signalA2B=zeros(N,4);
indA=find(active_rfA==1);
indB=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
# %% ------- Prepare the signals for both A2B and B2A ------- %%
[Da2b_T, signalA2B]=genrandpskseq(N,M,amp);
signalA2B=repmat(signalA2B,1,4);
signalB2A=zeros(N,4);
[Db2a_T,tmps]=genorthqpskseq(Nantb,N,amp);
ind=1;
for i=1:4
if(indB(ind)==i)
signalB2A(:,i)=tmps(:,ind);
if(length(indB)> ind) ind=ind+1; endif
endif
endfor
# %% ------- Node A to B transmission/reception ------- %%
rf_mode_current = rf_mode + (DMAMODE_TX+TXEN)*active_rfA +(DMAMODE_RX+RXEN)*active_rfB;
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);
oarf_send_frame(card,signalA2B,n_bit);
receivedB2A=oarf_get_frame(card);
oarf_stop(card);
# %% ------- Node B to A transmission/reception ------- %%
rf_mode_current = rf_mode + (DMAMODE_TX+TXEN)*active_rfB +(DMAMODE_RX+RXEN)*active_rfA;
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);
oarf_send_frame(card,signalB2A,n_bit);
receivedB2A=oarf_get_frame(card);
oarf_stop(card);
# %% ------- Do the A to B channel estimation ------- %%
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(iter*120+i+1,:)=vec(fblock);
endfor
HA2B=conj(Da2b_T).*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=diag(Da2b_T'*Da2b_R)/size(Da2b_T,1);
for i=0:(Nantb-1)
fchanestsA2B(:,i+1)=[0; chanestsA2B(301*i+[1:150]); zeros(210,1); chanestsA2B(301*i+[151:301])];
endfor
tchanestsA2B=ifft(fchanestsA2B);
%% ------- Do the B to A channel estimation ------- %%
Db2a_R=zeros(Niter*120,Nanta*301);
for i=0:119;
ifblock=receivedB2A(i*640+[1:640],indA);
ifblock(1:128,:)=[];
fblock=fft(ifblock);
fblock(1,:)=[];
fblock(151:360,:)=[];
Db2a_R(iter*120+i+1,:)=fblock.';
endfor
HB2A=conj(repmat(Db2a_T,Niter,1)).*repmat(Db2a_R,1,Nantb);
phasesB2A=unwrap(angle(HB2A));
if(mean(var(phasesB2A))>0.5)
disp("The phases of your estimates are a bit high (larger than 0.5 rad.), something is wrong.");
endif
chanestsB2A=reshape(diag(repmat(Db2a_T,Niter,1)'*repmat(Db2a_R,1,Nantb)/(Niter*120)),301,Nantb);
# %% -- Some plotting code -- %% (you can uncomment what you see fit)
# clf
# figure(1)
# for i=1:4
# subplot(220+i);plot(20*log10(abs(fftshift(fft(receivedA2B(:,i))))));
# endfor
# figure(2)
# t=[0:512-1]/512*1e-2;
# plot(t,abs(tchanests))
# xlabel('time')
# ylabel('|h|')
# 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')
# 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
error("You have to run init.params.m first!")
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