Commit 4380042c authored by Cirkic's avatar Cirkic

Added the tdd rec. script files

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@4037 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 76b91cfe
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
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);
inds=1:8;
ind=8;
for i=1:301
for k=1:Ns
carrierdata(:,i+(k-1)*301)=Hc(inds(ind),:)';
inds(ind)=[];
ind=ind-1;
if(ind==0)
inds=1:8;
ind=8;
endif
endfor
endfor
for k=1:Ns
frstgroup=(k-1)*301+[1:150]; # The first group of OFDM carriers
sndgroup=(k-1)*301+[151:301]; # The second group of OFDM carriers
for i=0:119
fblock=[0 carrierdata(i+1,frstgroup) zeros(1,210) carrierdata(i+1,sndgroup)];
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
function [carrierdata, s]=genrandpskseq(N,M,amp)
if(mod(N,640)~=0)
error('The sequence length must be divisible with 640.');
endif
s = zeros(N,1);
MPSK=exp(sqrt(-1)*([1:M]*2*pi/M+pi/M));
% OFDM sequence with 512 FFT using randomly
% generated 4-QAM and 128 cyclic prefix
carrierdata=zeros(120,301);
for i=0:(N/640-1)
datablock=MPSK(ceil(rand(301,1)*M));
for j=1:301
carrierdata(i+1,j)=datablock(j);
endfor
fblock=[0 datablock(1:150) zeros(1,210) datablock(151:301)];
ifblock=ifft(fblock,512);
% Adding cycl. prefix making the block of 640 elements
block = [ifblock(end-127:end) ifblock];
s([1:640]+i*640)=floor(amp*block);
endfor
endfunction
\ No newline at end of file
clear
paramsinitialized=false;
limeparms;
rxgain=30;
txgain=25;
eNB_flag = 0;
card = 0;
Ntrx=4;
dual_tx=0;
active_rfA=[1 0 0 0];
active_rfB=[0 1 1 0];
active_rf=active_rfA+active_rfB;
%fc = 2660000000;
fc = 1912600000; %1907600000;
%fc = 859.5e6;
%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;
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;
paramsinitialized=true;
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
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