New version also supports two carriers
git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5316 818b1a75-f10b-46b9-bf7c-635c3b92a50f
This commit is contained in:
@@ -1,112 +1,144 @@
|
|||||||
close all
|
close all
|
||||||
clear all
|
clear all
|
||||||
|
|
||||||
enable_plots=1; %eanbles figures
|
global symbols_per_slot slots_per_frame;
|
||||||
|
|
||||||
|
enable_plots=2; %enables figures
|
||||||
|
|
||||||
%% preload and init data
|
%% preload and init data
|
||||||
addpath('../../../openair1/PHY/LTE_REFSIG');
|
addpath('../../../openair1/PHY/LTE_REFSIG');
|
||||||
primary_synch; %loads the primary sync signal
|
primary_synch; %loads the primary sync signal
|
||||||
pss_t = upsample(primary_synch0_time,4);
|
|
||||||
|
|
||||||
%load('E:\EMOS\corridor\ofdm_pilots_sync_2048_v7.mat');
|
%load('E:\EMOS\corridor\ofdm_pilots_sync_2048_v7.mat');
|
||||||
load('ofdm_pilots_sync_30MHz.mat');
|
load('ofdm_pilots_sync_30MHz.mat');
|
||||||
|
|
||||||
ofdm_symbol_length = num_carriers + prefix_length;
|
n_carriers = 2; % use 1 for UHF and 2 for 2.6GHz
|
||||||
frame_length = ofdm_symbol_length*num_symbols_frame;
|
nframes = 100; % frames in one block
|
||||||
useful_carriers = num_carriers-num_zeros-1;
|
symbols_per_slot = 6;
|
||||||
|
slots_per_frame = 20;
|
||||||
|
|
||||||
|
switch n_carriers
|
||||||
|
case 1,
|
||||||
|
p = init_params(25,3,4); %this can be 25, 50, or 100
|
||||||
|
pss_t = upsample(primary_synch0_time,4);
|
||||||
|
|
||||||
|
%filename = 'E:\EMOS\corridor\trials1\eNB_data_20140331_UHF_run1.EMOS';
|
||||||
|
filename = 'D:\trials1 train extracted\eNB_data_20140331_UHF_run1.EMOS';
|
||||||
|
|
||||||
|
case 2,
|
||||||
|
p(1) = init_params(50,2,4);
|
||||||
|
p(2) = init_params(100,2,4);
|
||||||
|
pss_t = upsample(primary_synch0_time,4*2); % this assumes we are doing the sync on the first carrier, which is 10MHz
|
||||||
|
|
||||||
|
%filename = 'E:\EMOS\corridor\trials1\eNB_data_20140331_UHF_run1.EMOS';
|
||||||
|
filename = 'D:\trials1 train extracted\eNB_data_20140331_2.6GHz_run1.EMOS';
|
||||||
|
end
|
||||||
|
|
||||||
%filename = 'E:\EMOS\corridor\trials1\eNB_data_20140331_UHF_run1.EMOS';
|
|
||||||
filename = 'D:\trials1 train extracted\eNB_data_20140331_UHF_run1.EMOS';
|
|
||||||
destdir = 'E:\EMOS\corridor\trials1 train';
|
destdir = 'E:\EMOS\corridor\trials1 train';
|
||||||
|
|
||||||
samples_slot = 7680/2;
|
% derived parameters
|
||||||
slots_per_frame = 20;
|
samples_slot_agg = sum([p.nant_rx].*[p.samples_slot]);
|
||||||
nframes = 100;
|
num_symbols_frame = symbols_per_slot*slots_per_frame;
|
||||||
nant_rx=3;
|
|
||||||
nant_tx=4;
|
|
||||||
|
|
||||||
d = dir(filename);
|
d = dir(filename);
|
||||||
nblocks = floor(d.bytes/(samples_slot*slots_per_frame*nframes*nant_rx*4));
|
nblocks = floor(d.bytes/(samples_slot_agg*slots_per_frame*nframes*4));
|
||||||
PDP_total = zeros(nblocks*nframes,useful_carriers/4,nant_tx,nant_rx);
|
PDP_total = zeros(nblocks*nframes,p(1).useful_carriers/4,p(1).nant_tx,p(1).nant_rx);
|
||||||
|
|
||||||
%% main loop
|
%% main loop
|
||||||
fid = fopen(filename,'r');
|
fid = fopen(filename,'r');
|
||||||
|
|
||||||
vStorage = []; %%
|
vStorage1 = [];
|
||||||
|
vStorage2 = [];
|
||||||
|
|
||||||
|
block = 1;
|
||||||
block = 1; %
|
|
||||||
flag1 = 1;
|
flag1 = 1;
|
||||||
start=2;
|
start=2;
|
||||||
|
|
||||||
threshold = 3e+4 ; % maybe should change that !!!!
|
threshold = 3e+4 ; % maybe should change that !!!!
|
||||||
|
|
||||||
% fseek(fid,samples_slot*slots_per_frame*nframes*nant*102*2,'bof');
|
fseek(fid,samples_slot_agg*slots_per_frame*nframes*120*2,'bof'); %advance 30 sec
|
||||||
% %advance 102 sec
|
|
||||||
|
|
||||||
while ~feof(fid)
|
while ~feof(fid)
|
||||||
fprintf(1,'Processing block %d of %d',block,nblocks);
|
fprintf(1,'Processing block %d of %d',block,nblocks);
|
||||||
|
|
||||||
[v,c]=fread(fid, samples_slot*slots_per_frame*nframes*nant_rx*2, 'int16',0,'ieee-le');
|
[v,c]=fread(fid, 2*samples_slot_agg*slots_per_frame*nframes, 'int16',0,'ieee-le');
|
||||||
if (c==0)
|
if (c==0)
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
v1 = double(v(1:2:end))+1j*double(v(2:2:end));
|
v0 = double(v(1:2:end))+1j*double(v(2:2:end));
|
||||||
|
|
||||||
nframes = 100;
|
v1 = zeros(p(1).samples_slot*slots_per_frame*nframes,p(1).nant_rx);
|
||||||
|
|
||||||
v2 = zeros(samples_slot*slots_per_frame*nframes,nant_rx);
|
|
||||||
for slot=1:slots_per_frame*nframes
|
for slot=1:slots_per_frame*nframes
|
||||||
for a=1:nant_rx
|
for a=1:p(1).nant_rx
|
||||||
v2((slot-1)*samples_slot+1:slot*samples_slot,a) = ...
|
v1((slot-1)*p(1).samples_slot+1:slot*p(1).samples_slot,a) = ...
|
||||||
v1((slot-1)*samples_slot*nant_rx+(a-1)*samples_slot+1:...
|
v0((slot-1)*samples_slot_agg+(a-1)*p(1).samples_slot+1:...
|
||||||
(slot-1)*samples_slot*nant_rx+ a *samples_slot,1);
|
(slot-1)*samples_slot_agg+ a *p(1).samples_slot,1);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if n_carriers==2
|
||||||
|
v2 = zeros(p(2).samples_slot*slots_per_frame*nframes,p(2).nant_rx);
|
||||||
|
for slot=1:slots_per_frame*nframes
|
||||||
|
for a=1:p(2).nant_rx
|
||||||
|
v2((slot-1)*p(2).samples_slot+1:slot*p(2).samples_slot,a) = ...
|
||||||
|
v0((slot-1)*samples_slot_agg+(a-1)*p(2).samples_slot+1:...
|
||||||
|
(slot-1)*samples_slot_agg+ a *p(2).samples_slot,1);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
v2 = [vStorage; v2] ;%%
|
v1 = [vStorage1; v1] ;
|
||||||
if size(v2,1) > frame_length*nframes ;
|
if size(v1,1) > p(1).frame_length*nframes ;
|
||||||
nframes = floor(size(v2,1) / frame_length) ;
|
nframes = floor(size(v1,1) / p(1).frame_length) ;
|
||||||
vStorage = v2(frame_length*nframes+1:end,:) ;
|
vStorage1 = v1(p(1).frame_length*nframes+1:end,:) ;
|
||||||
v2(frame_length*nframes + 1 : end,:) = [] ;
|
v1(p(1).frame_length*nframes + 1 : end,:) = [] ;
|
||||||
start = 1 ;
|
start = 1 ;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if n_carriers==2
|
||||||
|
v2 = [vStorage1; v2] ;
|
||||||
|
if size(v2,1) > p(2).frame_length*nframes ;
|
||||||
|
nframes = floor(size(v2,1) / p(2).frame_length) ;
|
||||||
|
vStorage1 = v2(p(2).frame_length*nframes+1:end,:) ;
|
||||||
|
v2(p(2).frame_length*nframes + 1 : end,:) = [] ;
|
||||||
|
start = 1 ;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if enable_plots>=2
|
if enable_plots>=2
|
||||||
figure(1)
|
figure(1)
|
||||||
plot(20*log10(abs(fftshift(fft(v2)))))
|
plot(20*log10(abs(fftshift(fft(v1)))))
|
||||||
end
|
end
|
||||||
|
|
||||||
%% frame start detection
|
%% frame start detection
|
||||||
if flag1==1
|
if flag1==1
|
||||||
[corr,lag] = xcorr(v2(:,1),pss_t);
|
[corr,lag] = xcorr(v1(:,1),pss_t);
|
||||||
%[m,idx]=max(abs(corr));
|
%[m,idx]=max(abs(corr));
|
||||||
%[m,idx]=peaksfinder(corr,frame_length);
|
%[m,idx]=peaksfinder(corr,frame_length);
|
||||||
|
|
||||||
tmp = corr(nframes*slots_per_frame*samples_slot:end);
|
tmp = corr(nframes*slots_per_frame*p(1).samples_slot:end);
|
||||||
tmp2 = reshape(tmp,slots_per_frame*samples_slot,nframes);
|
tmp2 = reshape(tmp,slots_per_frame*p(1).samples_slot,nframes);
|
||||||
[m,idx] = max(abs(tmp2),[],1);
|
[m,idx] = max(abs(tmp2),[],1);
|
||||||
|
|
||||||
% meanCorr = mean(abs(tmp2));
|
% meanCorr = mean(abs(tmp2));
|
||||||
% [mm,where] = max(m./meanCorr)
|
% [mm,where] = max(m./meanCorr)
|
||||||
|
|
||||||
idx(m < threshold) = [];
|
idx(m < threshold) = [];
|
||||||
if size(idx,2) <= 1
|
if size(idx,2) <= 1
|
||||||
flag1 = 1 ;
|
flag1 = 1 ;
|
||||||
flag2 = 0 ;
|
flag2 = 0 ;
|
||||||
|
|
||||||
vStorage = [];
|
vStorage1 = [];
|
||||||
% elseif size(idx,2) == nframes
|
% elseif size(idx,2) == nframes
|
||||||
%
|
%
|
||||||
% flag1 = 0;
|
% flag1 = 0;
|
||||||
% flag2 = 1;
|
% flag2 = 1;
|
||||||
else
|
else
|
||||||
flag1 = 0 ;
|
flag1 = 0 ;
|
||||||
flag2 = 1 ;
|
flag2 = 1 ;
|
||||||
end
|
end
|
||||||
|
|
||||||
frame_offset = round(median(idx)) - prefix_length;
|
frame_offset = round(median(idx)) - p(1).prefix_length;
|
||||||
|
|
||||||
|
|
||||||
if enable_plots>=2
|
if enable_plots>=2
|
||||||
@@ -117,76 +149,103 @@ while ~feof(fid)
|
|||||||
plot(frame_offset,m(1),'ro')
|
plot(frame_offset,m(1),'ro')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
frame_offset = 0; %%%%% line 93 florian's
|
frame_offset = 0;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
%%
|
||||||
if flag2 == 1
|
if flag2 == 1
|
||||||
for i=start:nframes;
|
for i=start:nframes;
|
||||||
fprintf(1,'.');
|
fprintf(1,'.');
|
||||||
frame_start = (slots_per_frame*samples_slot)*(i-1)+frame_offset+1;
|
frame_start1 = (slots_per_frame*p(1).samples_slot)*(i-1)+frame_offset+1;
|
||||||
%frame_start = lag(idx(i))-prefix_length;
|
if n_carriers==2
|
||||||
% frame_start = lag(i) - prefix_length;
|
frame_start2 = (slots_per_frame*p(2).samples_slot)*(i-1)+frame_offset*2+1;
|
||||||
|
end
|
||||||
|
|
||||||
if i<nframes
|
if i<nframes
|
||||||
%% ofdm receiver
|
%% ofdm receiver
|
||||||
received_f = OFDM_RX(v2(frame_start:frame_start+frame_length,:),num_carriers,useful_carriers,prefix_length,num_symbols_frame);
|
received_f1 = OFDM_RX(v1(frame_start1:frame_start1+p(1).frame_length,:),p(1).num_carriers,p(1).useful_carriers,p(1).prefix_length,num_symbols_frame);
|
||||||
|
if n_carriers==2
|
||||||
|
received_f2 = OFDM_RX(v2(frame_start2:frame_start2+p(2).frame_length,:),p(2).num_carriers,p(2).useful_carriers,p(2).prefix_length,num_symbols_frame);
|
||||||
|
end
|
||||||
else
|
else
|
||||||
vStorage = [v2(frame_start:end,:) ; vStorage]; %%
|
vStorage1 = [v1(frame_start1:end,:) ; vStorage1]; %%
|
||||||
end
|
if n_carriers==2
|
||||||
%% MIMO channel estimation
|
vStorage2 = [v2(frame_start2:end,:) ; vStorage2]; %%
|
||||||
H = zeros(num_symbols_frame/2,useful_carriers/4,nant_tx,nant_rx);
|
|
||||||
for itx=1:nant_tx
|
|
||||||
% f_start and t_start indicate the start of the pilots in time
|
|
||||||
% and frequency according to the specifications (see .doc file).
|
|
||||||
% t_start has to be >=2, since the first symbol is the PSS.
|
|
||||||
f_start = mod(itx-1,2)*2+1;
|
|
||||||
t_start = floor((itx-1)/2)+1;
|
|
||||||
for irx=1:nant_rx
|
|
||||||
H(:,:,itx,irx)=conj(squeeze(f3(itx,t_start:2:end,f_start:4:end))).*received_f(t_start:2:end,f_start:4:end,irx);
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Ht = ifft(H,[],2);
|
|
||||||
PDP = mean(abs(Ht).^2,1);
|
|
||||||
PDP_all = squeeze(mean(mean(PDP,3),4));
|
|
||||||
PDP_total((block-1)*nframes+i+1,:,:,:) = PDP;
|
|
||||||
|
|
||||||
% adjust frame offset base on channel estimate to compensate for
|
|
||||||
% timing drift. We try to keep the peak of the impulse response at
|
|
||||||
% sample prefix_length/8.
|
|
||||||
[m,idx] = max(fft(ifft(PDP_all),num_carriers));
|
|
||||||
offset = idx - prefix_length/8;
|
|
||||||
if offset > prefix_length
|
|
||||||
offset = offset - num_carriers;
|
|
||||||
end
|
|
||||||
if abs(offset) > 5
|
|
||||||
frame_offset = frame_offset + round(offset/4);
|
|
||||||
end
|
|
||||||
|
|
||||||
if enable_plots>=1
|
|
||||||
figure(3)
|
|
||||||
for itx=1:nant_tx
|
|
||||||
for irx=1:nant_rx
|
|
||||||
subplot(nant_tx,nant_rx,(itx-1)*nant_rx + irx);
|
|
||||||
surf(20*log10(abs(Ht(:,:,itx,irx))))
|
|
||||||
%xlabel('time [OFDM symbol]')
|
|
||||||
%ylabel('delay time [samples]')
|
|
||||||
%zlabel('power [dB]')
|
|
||||||
shading interp
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
figure(4)
|
|
||||||
for itx=1:nant_tx
|
%% MIMO channel estimation
|
||||||
for irx=1:nant_rx
|
if (n_carriers==1)
|
||||||
subplot(nant_tx,nant_rx,(itx-1)*nant_rx + irx);
|
transmit_f1 = f3;
|
||||||
plot(10*log10(PDP(:,:,itx,irx)))
|
else
|
||||||
ylim([50 80])
|
transmit_f1 = f2;
|
||||||
xlim([0 75])
|
transmit_f2 = f1;
|
||||||
%xlabel('delay time [samples]')
|
end
|
||||||
%ylabel('power [dB]')
|
for carrier=1:n_carriers
|
||||||
|
if (carrier==1)
|
||||||
|
transmit_f = transmit_f1;
|
||||||
|
received_f = received_f1;
|
||||||
|
else
|
||||||
|
transmit_f = transmit_f2;
|
||||||
|
received_f = received_f2;
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
H = zeros(num_symbols_frame/2,p(carrier).useful_carriers/4,p(carrier).nant_tx,p(carrier).nant_rx);
|
||||||
|
for itx=1:p(carrier).nant_tx
|
||||||
|
% f_start and t_start indicate the start of the pilots in time
|
||||||
|
% and frequency according to the specifications (see .doc file).
|
||||||
|
% t_start has to be >=2, since the first symbol is the PSS.
|
||||||
|
f_start = mod(itx-1,2)*2+1;
|
||||||
|
t_start = floor((itx-1)/2)+1;
|
||||||
|
for irx=1:p(carrier).nant_rx
|
||||||
|
H(:,:,itx,irx)=conj(squeeze(transmit_f(itx,t_start:2:end,f_start:4:end))).*received_f(t_start:2:end,f_start:4:end,irx);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
drawnow
|
Ht = ifft(H,[],2);
|
||||||
end
|
PDP = mean(abs(Ht).^2,1);
|
||||||
|
PDP_all = squeeze(mean(mean(PDP,3),4));
|
||||||
|
%PDP_total((block-1)*nframes+i+1,:,:,:) = PDP;
|
||||||
|
|
||||||
|
if enable_plots>=1
|
||||||
|
figure(3+2*(carrier-1))
|
||||||
|
for itx=1:p(carrier).nant_tx
|
||||||
|
for irx=1:p(1).nant_rx
|
||||||
|
subplot(p(1).nant_tx,p(1).nant_rx,(itx-1)*p(1).nant_rx + irx);
|
||||||
|
surf(20*log10(abs(Ht(:,:,itx,irx))))
|
||||||
|
%xlabel('time [OFDM symbol]')
|
||||||
|
%ylabel('delay time [samples]')
|
||||||
|
%zlabel('power [dB]')
|
||||||
|
shading interp
|
||||||
|
end
|
||||||
|
end
|
||||||
|
figure(4+2*(carrier-1))
|
||||||
|
for itx=1:p(1).nant_tx
|
||||||
|
for irx=1:p(1).nant_rx
|
||||||
|
subplot(p(1).nant_tx,p(1).nant_rx,(itx-1)*p(1).nant_rx + irx);
|
||||||
|
plot(10*log10(PDP(:,:,itx,irx)))
|
||||||
|
ylim([50 80])
|
||||||
|
xlim([0 75])
|
||||||
|
%xlabel('delay time [samples]')
|
||||||
|
%ylabel('power [dB]')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
drawnow
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
% adjust frame offset base on channel estimate to compensate for
|
||||||
|
% timing drift. We try to keep the peak of the impulse response at
|
||||||
|
% sample prefix_length/8.
|
||||||
|
[m,idx] = max(fft(ifft(PDP_all),p(1).num_carriers));
|
||||||
|
offset = idx - p(1).prefix_length/8;
|
||||||
|
if offset > p(1).prefix_length
|
||||||
|
offset = offset - p(1).num_carriers;
|
||||||
|
end
|
||||||
|
if abs(offset) > 5
|
||||||
|
frame_offset = frame_offset + round(offset/4);
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
fprintf(1,'\n');
|
fprintf(1,'\n');
|
||||||
|
|||||||
Reference in New Issue
Block a user