From 35169c13e7a12c6a1aef6283c6c7c0412da592a0 Mon Sep 17 00:00:00 2001
From: Cirkic <cirkic@eurecom.fr>
Date: Fri, 19 Jul 2013 14:35:08 +0000
Subject: [PATCH] Cleaned up some code and made it more transparent.
git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4043 818b1a75-f10b-46b9-bf7c-635c3b92a50f
---
targets/PROJECTS/TDDREC/initparams.m | 6 +-
targets/PROJECTS/TDDREC/runmeas.m | 134 ------------------
targets/PROJECTS/TDDREC/runmeas_wduplex.m | 155 +++++++++++++++++++++
targets/PROJECTS/TDDREC/runmeas_woduplex.m | 69 +++++----
4 files changed, 199 insertions(+), 165 deletions(-)
delete mode 100644 targets/PROJECTS/TDDREC/runmeas.m
create mode 100644 targets/PROJECTS/TDDREC/runmeas_wduplex.m
diff --git a/targets/PROJECTS/TDDREC/initparams.m b/targets/PROJECTS/TDDREC/initparams.m
index 3f3fd69199..2628e859de 100644
--- a/targets/PROJECTS/TDDREC/initparams.m
+++ b/targets/PROJECTS/TDDREC/initparams.m
@@ -15,6 +15,8 @@ active_rfA=[1 0 0 0];
active_rfB=[0 1 0 0];
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 = 1912600000; %1907600000;
%fc = 859.5e6;
@@ -23,8 +25,8 @@ fc = 1912600000; %1907600000;
%rf_mode=(RXEN+TXEN+TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAByp+RFBBLNA1) * active_rf;
autocal_mode=active_rf;
rf_mode=(TXLPFNORM+TXLPFEN+TXLPF25+RXLPFNORM+RXLPFEN+RXLPF25+LNA1ON+LNAMax+RFBBNORM) * active_rf;
-tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_TESTTX;
-%tdd_config = DUPLEXMODE_FDD + TXRXSWITCH_LSB;
+tdd_config = DUPLEXMODE_FDD+TXRXSWITCH_TESTTX; LSBSWITCH_FLAG=false;
+%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;
diff --git a/targets/PROJECTS/TDDREC/runmeas.m b/targets/PROJECTS/TDDREC/runmeas.m
deleted file mode 100644
index 3586e42d4f..0000000000
--- a/targets/PROJECTS/TDDREC/runmeas.m
+++ /dev/null
@@ -1,134 +0,0 @@
-# % Author: Mirsad Cirkic
-# % Organisation: Eurecom (and Linkoping University)
-# % E-mail: mirsad.cirkic@liu.se
-
-if(paramsinitialized)
- 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);
- Niter=1;
- # %% ------- Node A to B channel measurements ------- %%
- # 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);
- # [Da2b_T, signalA2B]=genrandpskseq(N,M,amp);
- # signalA2B=repmat(signalA2B,1,4);
- # oarf_send_frame(card,signalA2B,n_bit);
- # fprintf('A to B: Frame sent to Tx buffer.\n')
- # fprintf('A to B: Acquiring chan. measurements....\n')
- # loop=true;
- # chanests=[];
- # Da2b_R=zeros(Niter*120,Nantb*301);
- # Da2b_T=repmat(Da2b_T,Niter,Nantb);
- # for iter=0:(Niter-1) % Do the chan. est until SNR is good enough. That is, do the "oarf_get_fram(card)
- # receivedA2B=oarf_get_frame(card);
- # fprintf('A to B: Frame grabbed from Rx buffer.\n')
- # 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
- # endfor
- # H=conj(Da2b_T).*Da2b_R;
- # phases=unwrap(angle(H));
- # chanests=diag(Da2b_T'*Da2b_R)/size(Da2b_T,1);
- # 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);
-
- # %% -- Do some plotting
- # 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
- # oarf_stop(card);
- # fprintf(' done\n')
-
- %% ------- Node B to A channel measurements ------- %%
- 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);
- signalB2A=zeros(N,4);
- Db2a_R=zeros(Niter*120,Nanta*301);
- [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
- %receivedB2A=sum(signalB2A*diag([1 2 3 4]),2)+100*randn(N,1);
-
- oarf_send_frame(card,signalB2A,n_bit);
- if(length(indA)!=1) error("Node A can only have one antenna active\n"); endif
- for iter=0:(Niter-1) % Do the chan. est until SNR is good enough. That is, do the "oarf_get_fram(card)
- fprintf('B to A: Frame grabbed from Rx buffer.\n')
- receivedB2A=oarf_get_frame(card);
-
- 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
- endfor
- oarf_stop(card);
-
- # # -- Do the channel estimation
- 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);
- phases=unwrap(angle(H));
- # 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
diff --git a/targets/PROJECTS/TDDREC/runmeas_wduplex.m b/targets/PROJECTS/TDDREC/runmeas_wduplex.m
new file mode 100644
index 0000000000..a10e8aba75
--- /dev/null
+++ b/targets/PROJECTS/TDDREC/runmeas_wduplex.m
@@ -0,0 +1,155 @@
+# % Author: Mirsad Cirkic
+# % Organisation: Eurecom (and Linkoping University)
+# % E-mail: mirsad.cirkic@liu.se
+
+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=4;
+ signalA2B=zeros(N,4);
+ signalB2A=zeros(N,4);
+ indA=find(active_rfA==1);
+ indB=find(active_rfB==1);
+ Nanta=length(indA);
+ Nantb=length(indB);
+ 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(mod(Nofs,640)!=0) error("blabla") endif
+
+ if(Nanta!=1) error("Node A can only have one antenna active\n"); endif
+ if(Niter!=1) error("We should only use one get_frame at each run.\n"); endif
+
+# %% ------- Prepare the signals for both A2B and B2A ------- %
+ maskA2B=kron(ones(1,N/(2*Nofs)),[ones(1,Nofs) zeros(1,Nofs)])';
+ 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=[];
+ for i=1:4
+ if(indA(ia)==i)
+ [tmpd, tmps]=genrandpskseq(N,M,amp);
+ Da2b_T=datamaskA2B*tmpd;
+ 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
+ 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*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.
+ Db2a_T=[Db2a_T datamaskB2A*tmpd];
+ if(length(indB)> ib) ib=ib+1; endif
+ endif
+ endfor
+
+ signal = signalA2B+signalB2A;
+
+# %% ------- Node B and A duplex transmission/reception ------- %%
+ rf_mode_current = rf_mode + (DMAMODE_TX+TXEN+DMAMODE_RX+RXEN)*active_rf;
+ 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,signal,n_bit);
+ received=oarf_get_frame(card);
+ oarf_stop(card);
+ receivedA2B=received.*repmat(maskA2B,1,4);
+ receivedB2A=received.*repmat(maskB2A,1,4);
+
+# %% ------- 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((Niter-1)*120+i+1,:)=vec(fblock);
+ 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 ------- %%
+ 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((Niter-1)*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
+ if(!LSBSWITCH_FLAG) error("You have to set the LSB switch flag (LSBSWITCH_FLAG) in initparams.m.\n")
+ else error("You have to run init.params.m first!")
+ endif
+endif
diff --git a/targets/PROJECTS/TDDREC/runmeas_woduplex.m b/targets/PROJECTS/TDDREC/runmeas_woduplex.m
index 232b4d876e..a9a354ea85 100644
--- a/targets/PROJECTS/TDDREC/runmeas_woduplex.m
+++ b/targets/PROJECTS/TDDREC/runmeas_woduplex.m
@@ -2,15 +2,16 @@
# % 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.")
+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=4;
- signalB2A=zeros(N,1);
signalA2B=zeros(N,4);
+ signalB2A=zeros(N,4);
indA=find(active_rfA==1);
indB=find(active_rfB==1);
Nanta=length(indA);
@@ -22,32 +23,39 @@ if(paramsinitialized)
endif
# %% ------- Prepare the signals for both A2B and B2A ------- %%
- [Da2b_T, signalA2B]=genrandpskseq(N,M,amp);
- signalA2B=repmat(signalA2B,1,4);
+ signalA2B=zeros(N,4);
signalB2A=zeros(N,4);
- [Db2a_T,tmps]=genorthqpskseq(Nantb,N,amp);
- ind=1;
+ ia=1; ib=1;
+ Db2a_T=[];
for i=1:4
- if(indB(ind)==i)
- signalB2A(:,i)=tmps(:,ind);
- if(length(indB)> ind) ind=ind+1; endif
+ if(indA(ia)==i)
+ [Da2b_T, tmps]=genrandpskseq(N,M,amp);
+ signalA2B(:,i)=tmps;
+ 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;
+ Db2a_T=[Db2a_T tmpd];
+ if(length(indB)> ib) ib=ib+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 ------- %%
+# %% ------- Node B to A transmission ------- %%
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);
+# %% ------- Node A to B transmission ------- %%
+ 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);
+ receivedA2B=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;
@@ -56,17 +64,18 @@ if(paramsinitialized)
fblock=fft(ifblock);
fblock(1,:)=[];
fblock(151:360,:)=[];
- Da2b_R(iter*120+i+1,:)=vec(fblock);
+ Da2b_R((Niter-1)*120+i+1,:)=vec(fblock);
endfor
- HA2B=conj(Da2b_T).*Da2b_R;
+ 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=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])];
+ 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);
@@ -78,7 +87,7 @@ if(paramsinitialized)
fblock=fft(ifblock);
fblock(1,:)=[];
fblock(151:360,:)=[];
- Db2a_R(iter*120+i+1,:)=fblock.';
+ Db2a_R((Niter-1)*120+i+1,:)=fblock.';
endfor
HB2A=conj(repmat(Db2a_T,Niter,1)).*repmat(Db2a_R,1,Nantb);
phasesB2A=unwrap(angle(HB2A));
@@ -137,5 +146,7 @@ if(paramsinitialized)
else
- error("You have to run init.params.m first!")
-end
+ 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
--
GitLab