Commit 9e08ca87 authored by Florian Kaltenberger's avatar Florian Kaltenberger

added George's peak finder to emos_read.m

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5179 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent df29718a
function La = LanczosKernel(a,x0,samples)
min = floor(x0) - a;
max = ceil(x0) + a;
min(min<1)=1;
max(max>size(samples,2))=size(samples,2);
La=zeros(size(x0,2),1);
for i=1:size(x0,2)
La(i)=sinc((-x0(i)+(min(i):max(i)))).*sinc(((-x0(i)+(min(i):max(i)))/a))*samples(min(i):max(i))';
end
\ No newline at end of file
close all
clear all
%% read data
fid = fopen('E:\EMOS\corridor\eNB_data_20140108_185919.EMOS','r');
[v,c]=fread(fid, 76800*4*100, 'int16',0,'ieee-le');
v2 = double(v(1:2:end))+1j*double(v(2:2:end));
fclose(fid);
figure(1)
plot(abs(fftshift(fft(v2))))
enable_plots=1; %eanbles figures
%% sync
%% preload and init data
addpath('../../../openair1/PHY/LTE_REFSIG');
primary_synch; %loads the primary sync signal
pss_t = upsample(primary_synch0_time,4*4);
[corr,lag] = xcorr(v2,pss_t);
figure(2);
plot(lag,abs(corr));
%% frame start detection
%load('../LOCALIZATION/ofdm_pilots_sync_2048.mat');
load('E:\EMOS\corridor\ofdm_pilots_sync_2048_v7.mat');
ofdm_symbol_length = num_carriers + prefix_length;
frame_length = ofdm_symbol_length*num_symbols_frame;
useful_carriers = num_carriers-num_zeros-1;
% TODO: do a proper peak detection. for now just take the max
[m,i]=max(abs(corr));
frame_start = lag(i) - prefix_length;
filename = 'E:\EMOS\corridor\eNB_data_20140108_185919.EMOS';
samples_slot = 7680*2;
slots_per_frame = 20;
nframes = 100;
d = dir(filename);
nblocks = floor(d.bytes/(samples_slot*slots_per_frame*nframes*4));
PDP_total = zeros(nblocks*nframes,useful_carriers);
%% main loop
fid = fopen(filename,'r');
block = 1;
while ~feof(fid)
fprintf(1,'Processing block %d of %d',block,nblocks);
[v,c]=fread(fid, samples_slot*slots_per_frame*nframes*2, 'int16',0,'ieee-le');
v2 = double(v(1:2:end))+1j*double(v(2:2:end));
[corr,lag] = xcorr(v2,pss_t);
if enable_plots>=2
figure(1)
plot(abs(fftshift(fft(v2))))
%% ofdm receiver
received = v2(frame_start:frame_start+frame_length);
received_f = zeros(num_symbols_frame,useful_carriers);
for i=0:num_symbols_frame-1;
ifblock=received(i*ofdm_symbol_length+[1:ofdm_symbol_length]);
figure(2);
plot(lag,abs(corr));
end
%% frame start detection
%[m,i]=max(abs(corr));
[m,idx]=peaksfinder(corr,frame_length);
for i=1:size(idx,2)-1; % the last frame is not complite
fprintf(1,'.');
frame_start = lag(idx(i))-prefix_length;
% frame_start = lag(i) - prefix_length;
%% ofdm receiver
received = v2(frame_start:frame_start+frame_length);
received_f = zeros(num_symbols_frame,useful_carriers);
for j=0:num_symbols_frame-1;
ifblock=received(j*ofdm_symbol_length+(1:ofdm_symbol_length));
ifblock(1:prefix_length)=[];
fblock=fft(ifblock);
received_f(i+1,:) = [fblock(2:useful_carriers/2+1); fblock(end-useful_carriers/2+1:end)];
end
received_f(j+1,:) = [fblock(2:useful_carriers/2+1); fblock(end-useful_carriers/2+1:end)];
end
%% channel estimation
H=conj(f).*received_f;
Ht = ifft(H,[],2);
PDP = mean(abs(Ht(2:end,:).^2),1);
figure(3)
surf(20*log10(abs(Ht)))
xlabel('time [OFDM symbol]')
ylabel('delay time [samples]')
zlabel('power [dB]')
shading interp
figure(4)
plot(10*log10(PDP))
xlabel('delay time [samples]')
ylabel('power [dB]')
%% channel estimation
H=conj(f).*received_f;
Ht = ifft(H,[],2);
PDP = mean(abs(Ht(2:end,:).^2),1);
PDP_total((block-1)*nframes+i+1,:) = PDP;
if enable_plots>=1
figure(3)
surf(20*log10(abs(Ht)))
xlabel('time [OFDM symbol]')
ylabel('delay time [samples]')
zlabel('power [dB]')
shading interp
figure(4)
plot(10*log10(PDP))
xlabel('delay time [samples]')
ylabel('power [dB]')
end
end
fprintf(1,'\n');
block = block+1;
end
fclose(fid);
function [m,ind]=peaksfinder(corr,frame_length)
threshold=45000;
consecutivePos=[];
highCorrVal=find(abs(corr)>threshold);
num_peak=0;
k=1;
consecutivePos(1)=highCorrVal(1);
for i_high=1:size(highCorrVal,1)-1
if highCorrVal(i_high+1)-highCorrVal(i_high)==1
consecutivePos(k+1)=highCorrVal(i_high+1);
k=k+1;
else
num_peak=num_peak+1;
[m(num_peak),temp_idx]=max(abs(corr(min(consecutivePos):max(consecutivePos))));
ind(num_peak)=min(consecutivePos)-1+temp_idx;
consecutivePos=[];
consecutivePos(1)=highCorrVal(i_high+1);
k=1;
end
end
num_peak=num_peak+1;
[m(num_peak),temp_idx]=max(abs(corr(min(consecutivePos):max(consecutivePos))));
ind(num_peak)=min(consecutivePos)-1+temp_idx;
% a bigining for make code which clculate the best peak in respect to whole frlames
% corrMatrix=vec2mat(corr, frame_length);
% corrMatrix(end,:)=[];
% sumCorrMatrix=sum(abs(corrMatrix));
% [Value Pos]=max(sumCorrMatrix);
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