log_read.m 18.8 KB
Newer Older
Byiringi's avatar
 
Byiringi committed
1 2 3 4
clear all
close all

top_dir = 'P:\florian\CORRIDOR\trials2 train'; % needs to be updated according to your computer
Florian Kaltenberger's avatar
 
Florian Kaltenberger committed
5 6 7
d1 = dir(fullfile(top_dir,'UHF','*.log'));
d2 = dir(fullfile(top_dir,'2.6GHz','*.log'));

Byiringi's avatar
 
Byiringi committed
8 9


Byiringi's avatar
 
Byiringi committed
10 11


Florian Kaltenberger's avatar
 
Florian Kaltenberger committed
12 13 14 15 16 17
start_time = [1.400489088000000e+09 1.400493112000000e+09 1.400499696000000e+09 1.400506864000000e+09];

for idx=1:length(d1)
    data1{idx}=csvread(fullfile(top_dir,'UHF',d1(idx).name),1,0);
    data2{idx}=csvread(fullfile(top_dir,'2.6GHz',d2(idx).name),1,0);
    
Byiringi's avatar
 
Byiringi committed
18 19
    
    
Florian Kaltenberger's avatar
 
Florian Kaltenberger committed
20 21 22 23 24 25 26 27 28 29 30
    frame_start1(idx) = ceil(data1{idx}(find(data1{idx}(:,1)>start_time(idx),1,'first'),3)/92160000)*100;
    frame_start2(idx) = ceil(data2{idx}(find(data2{idx}(:,1)>start_time(idx),1,'first'),3)/368640000)*100;
    
    %% find the first dataset with valid GPS signal and throw away everything before
    idx1_start = find(data1{idx}(:,6)>0,1,'first');
    data1{idx}(1:idx1_start-1,:)=[];
    idx2_start = find(data2{idx}(:,6)>0,1,'first');
    data2{idx}(1:idx2_start-1,:)=[];
    
    rtime1 = data1{idx}(:,1) - data1{idx}(1,1);
    rtime2 = data2{idx}(:,1) - data2{idx}(1,1);
Byiringi's avatar
 
Byiringi committed
31
    
Florian Kaltenberger's avatar
 
Florian Kaltenberger committed
32 33 34 35 36 37 38 39 40
    %% plot gps coordinates
    figure(idx*10+1);
    hold off
    plot(data1{idx}(1:100:end,7),data1{idx}(1:100:end,8),'rx')
    hold on
    plot(data2{idx}(1:100:end,7),data2{idx}(1:100:end,8),'bx')
    xlabel('lat [deg]');
    ylabel('lon [deg]')
    legend('UHF','2.6GHz')
Byiringi's avatar
 
Byiringi committed
41
    title(sprintf('Run %d',idx));
Florian Kaltenberger's avatar
 
Florian Kaltenberger committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    
    %% plot RSSI
    % TODO: convert time (in unix epoch) into something more meaninful
    figure(idx*10+2);
    hold off
    plot(rtime1,smooth(data1{idx}(:,13),100),'r')
    hold on
    plot(rtime2,smooth(data2{idx}(:,13),100),'b')
    plot(rtime2,smooth(data2{idx}(:,19),100),'c')
    plot(rtime2,smooth(data2{idx}(:,25),100),'m')
    legend('UHF','2.6GHz card 1','2.6GHz card 2','2.6GHz card 3');
    xlabel('time [seconds]')
    ylabel('RSSI [dBm]')
    title(sprintf('Run %d',idx));
    
Byiringi's avatar
 
Byiringi committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
    
    
    %% measured distance (km)
    % We can get the distance between the base station and the RX antenna from the GPS coordinates
    distances1=zeros(size(data1{idx},1),1);
    distances2=zeros(size(data2{idx},1),1);
    for i=1:size(data1{idx},1)
        distances1(i)=Dist_Calc_from_GPS(data1{idx}(i,7),data1{idx}(i,8),48.25073056,1.55481944);
    end
    
    for i=1:size(data2{idx},1)
        distances2(i)=Dist_Calc_from_GPS(data2{idx}(i,7),data2{idx}(i,8),48.25073056,1.55481944);
    end
    
    
    figure (100+idx)
    subplot(1,2,1)
    plot(rtime1,distances1,'r',rtime1,smooth(data1{idx}(:,13),100),'b')
    title(sprintf('Run %d with the measured distance : UHF',idx));
    xlabel('time [s]');
    legend('distance [km]','RSSI [dBm]');
    
    subplot(1,2,2)
    plot(rtime2,distances2,'r',rtime2,smooth(data2{idx}(:,13),100),'b')
    title(sprintf('Run %d with the measured distance : 2.6GHz ',idx));
    xlabel('time [s]');
    legend('distance [km]','RSSI [dBm]');
    %% estimated distance under the assumption of a constant speed
    % We assume that the TGV speed is constant and then we find the distances to the base station with the time vector
    
    TGV_speed=82.5;%constant TGV speed in m/s
    
    
    
    [RSSI_max1,I_RSSI_max1]=max(data1{idx}(:,13));%we find the index corresponding to the maximum of RSSI
    time01=rtime1(I_RSSI_max1)*ones(length(rtime1),1);%time corresponding to the maximim of RSSI
    new_distances1=(TGV_speed*abs(rtime1-time01))/1000+min(distances1)*ones(length(rtime1),1);% new distance in km. is is minimum when the RSSI is maximum
    
    
    [RSSI_max2,I_RSSI_max2]=max(data2{idx}(:,13));
    time02=rtime2(I_RSSI_max2)*ones(length(rtime2),1);
    new_distances2=(TGV_speed*abs(rtime2-time02))/1000+min(distances2)*ones(length(rtime2),1);% distance in km
    
    
Byiringi's avatar
 
Byiringi committed
101
    if (idx==2)%For Run 2, there is an anomalous peak for the RSSI at the end. Here we ignore it
Byiringi's avatar
 
Byiringi committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        [RSSI_max2,I_RSSI_max2]=max(data2{idx}(1:32900,13));
        time02=rtime2(I_RSSI_max2)*ones(length(rtime2),1);
        new_distances2=(TGV_speed*abs(rtime2-time02))/1000+min(distances2)*ones(length(rtime2),1);% distance in km
    end
    
    figure (200+idx)
    subplot(1,2,1)
    plot(rtime1,new_distances1,'r',rtime1,smooth(data1{idx}(:,13),100),'b')
    title(sprintf('Run %d with the estimated distance : UHF',idx));
    xlabel('time [s]');
    legend('distance [km]','RSSI [dBm]');
    
    subplot(1,2,2)
    plot(rtime2,new_distances2,'r',rtime2,smooth(data2{idx}(:,13),100),'b')
    title(sprintf('Run %d with the estimated distance : 2.6GHz ',idx));
    xlabel('time [s]');
    legend('distance [km]','RSSI [dBm]');
    
    
    
    
    
    
Byiringi's avatar
 
Byiringi committed
125
    
Byiringi's avatar
 
Byiringi committed
126 127 128 129 130
    
    
    
    
    %% rssi(dBm) versus distance (log scale)
Byiringi's avatar
 
Byiringi committed
131 132 133
    % We will plot the rssi versus the distance. We separate the data
    % before and after the passing of the train for run 3 and run 4 because
    % all the antennas are poiting at the same direction
Byiringi's avatar
 
Byiringi committed
134 135
    
    % we heuristically determine a starting point and a ending point for the linear fitting
Byiringi's avatar
 
Byiringi committed
136 137
    if idx==1
        
Byiringi's avatar
 
Byiringi committed
138 139 140 141 142
        distance_break1_start=0.4;%in km
        distance_break1_end=7.5;
        distance_break2_start=0.4;
        distance_break2_end=7.5;
        
Byiringi's avatar
 
Byiringi committed
143 144 145 146
        
    end
    
    if idx==2
Byiringi's avatar
 
Byiringi committed
147 148 149 150 151
        distance_break1_start=0.8;%in km
        distance_break1_end=4.5;
        distance_break2_start=0.8;
        distance_break2_end=4.5;
        
Byiringi's avatar
 
Byiringi committed
152 153 154 155
        
    end
    
    if idx==3
Byiringi's avatar
 
Byiringi committed
156 157 158 159
        distance_before_break1_start=5;%in km
        distance_before_break1_end=23;
        distance_before_break2_start=5;
        distance_before_break2_end=23;
Byiringi's avatar
 
Byiringi committed
160 161 162 163 164 165 166 167 168 169 170 171 172
        
        distance_after_break1_start=2.274;%in km
        distance_after_break1_end=5.376;
        distance_after_break2_start=5.996;
        distance_after_break2_end=7.613;
    end
    
    if idx==4
        distance_before_break1_start=0.1176;%in km
        distance_before_break1_end=3.489;
        distance_before_break2_start=0.1344;
        distance_before_break2_end=3.78;
        
Byiringi's avatar
 
Byiringi committed
173 174 175 176
        distance_after_break1_start=0.5;%in km
        distance_after_break1_end=8;
        distance_after_break2_start=0.5;
        distance_after_break2_end=8;
Byiringi's avatar
 
Byiringi committed
177 178 179
    end
    
    
Byiringi's avatar
 
Byiringi committed
180 181 182 183 184 185 186 187
    if idx==1 || idx==2
        
        % indexes of the starting and ending points
        index_break1_start=1;
        index_break2_start=1;
        index_break1_end=1;
        index_break2_end=1;
        
Byiringi's avatar
 
Byiringi committed
188 189
    end
    
Byiringi's avatar
 
Byiringi committed
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
    if idx==3 || idx==4
        % indexes of the starting and ending points with the data before the passing of the
        % train
        index_break1_before_start=1;
        index_break2_before_start=1;
        index_break1_before_end=1;
        index_break2_before_end=1;
        
        % indexes of the starting and ending points with the data after the passing of the
        % train
        index_break1_after_start=I_RSSI_max1;
        index_break2_after_start=I_RSSI_max2;
        index_break1_after_end=I_RSSI_max1;
        index_break2_after_end=I_RSSI_max2;
        
Byiringi's avatar
 
Byiringi committed
205 206 207
    end
    
    
Byiringi's avatar
 
Byiringi committed
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
    if idx==1 || idx==2
        %starting points
        while (index_break1_start<length(new_distances1)) && (new_distances1(index_break1_start)>distance_break1_start)
            index_break1_start=index_break1_start+1;
        end
        while (index_break2_start<length(new_distances2)) && (new_distances2(index_break2_start)>distance_break2_start)
            index_break2_start=index_break2_start+1;
        end
        %ending points
        while (index_break1_end<length(new_distances1)) && (new_distances1(index_break1_end)>distance_break1_end)
            index_break1_end=index_break1_end+1;
        end
        while (index_break2_end<length(new_distances2)) && (new_distances2(index_break2_end)>distance_break2_end)
            index_break2_end=index_break2_end+1;
        end
        
        
    end
Byiringi's avatar
 
Byiringi committed
226
    
Byiringi's avatar
 
Byiringi committed
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
    if idx==3 || idx==4
        %starting points
        while (index_break1_before_start<length(new_distances1)) && (new_distances1(index_break1_before_start)>distance_before_break1_start)
            index_break1_before_start=index_break1_before_start+1;
        end
        while (index_break2_before_start<length(new_distances2)) && (new_distances2(index_break2_before_start)>distance_before_break2_start)
            index_break2_before_start=index_break2_before_start+1;
        end
        %ending points
        while (index_break1_before_end<length(new_distances1)) && (new_distances1(index_break1_before_end)>distance_before_break1_end)
            index_break1_before_end=index_break1_before_end+1;
        end
        while (index_break2_before_end<length(new_distances2)) && (new_distances2(index_break2_before_end)>distance_before_break2_end)
            index_break2_before_end=index_break2_before_end+1;
        end
        
        
        %starting points
        while (index_break1_after_start<length(new_distances1)) && (new_distances1(index_break1_after_start)<distance_after_break1_start)
            index_break1_after_start=index_break1_after_start+1;
        end
        while (index_break2_after_start<length(new_distances2)) && (new_distances2(index_break2_after_start)<distance_after_break2_start)
            index_break2_after_start=index_break2_after_start+1;
        end
        
        %ending points
        while (index_break1_after_end<length(new_distances1)) && (new_distances1(index_break1_after_end)<distance_after_break1_end)
            index_break1_after_end=index_break1_after_end+1;
        end
        while (index_break2_after_end<length(new_distances2)) && (new_distances2(index_break2_after_end)<distance_after_break2_end)
            index_break2_after_end=index_break2_after_end+1;
        end
        
    end
Byiringi's avatar
 
Byiringi committed
261 262
    
    
Byiringi's avatar
 
Byiringi committed
263 264
    
    
Byiringi's avatar
 
Byiringi committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
    if idx==1 || idx ==2
        figure(idx*10+3)
        
        
        
        
        hold off
        linearCoef1 = polyfit(10*log10(new_distances1(index_break1_end:index_break1_start)),data1{idx}(index_break1_end:index_break1_start,13),1);
        linearFit1 = polyval(linearCoef1,10*log10(new_distances1(index_break1_end:index_break1_start)));
        semilogx(new_distances1(1:I_RSSI_max1),data1{idx}(1:I_RSSI_max1,13),'rx',new_distances1(index_break1_end:index_break1_start),linearFit1,'r-')
        display(sprintf('Run %d :slope UHF : %f',idx,linearCoef1(1)))
        
        
        hold on
        linearCoef2 = polyfit(10*log10(new_distances2(index_break2_end:index_break2_start)),data2{idx}(index_break2_end:index_break2_start,13),1);
        linearFit2 = polyval(linearCoef2,10*log10(new_distances2(index_break2_end:index_break2_start)));
        semilogx(new_distances2(1:I_RSSI_max2),data2{idx}(1:I_RSSI_max2,13),'bx',new_distances2(index_break2_end:index_break2_start),linearFit2,'b-')
        display(sprintf('Run %d :slope 2.6GHz : %f',idx,linearCoef2(1)))
        
        
        title(sprintf('Run %d: With the data  the passing of the train',idx))
        legend('UHF','UHF:linear fitting','2.6GHz card 1','2.6GHz card 1:linear fitting');
        xlabel('distance [km]')
        ylabel('RSSI [dBm]')
        
        
        
        
        % Zoom on the linear fitting
        
        figure(idx*10+4)
        
        
        
        
        hold off
        
        linearCoef1 = polyfit(10*log10(new_distances1(index_break1_end:index_break1_start)),data1{idx}(index_break1_end:index_break1_start,13),1);
        linearFit1 = polyval(linearCoef1,10*log10(new_distances1(index_break1_end:index_break1_start)));
        semilogx(new_distances1(index_break1_end:index_break1_start),data1{idx}(index_break1_end:index_break1_start,13),'rx',new_distances1(index_break1_end:index_break1_start),linearFit1,'r-')
        %display(sprintf('Run %d :slope UHF : %f',idx,linearCoef1(1)))
        
        hold on
        
        linearCoef2 = polyfit(10*log10(new_distances2(index_break2_end:index_break2_start)),data2{idx}(index_break2_end:index_break2_start,13),1);
        linearFit2 = polyval(linearCoef2,10*log10(new_distances2(index_break2_end:index_break2_start)));
        semilogx(new_distances2(index_break2_end:index_break2_start),data2{idx}(index_break2_end:index_break2_start,13),'bx',new_distances2(index_break2_end:index_break2_start),linearFit2,'b-')
        %display(sprintf('Run %d :slope 2.6GHz : %f',idx,linearCoef2(1)))
        
        title(sprintf('Run %d: ',idx))
        legend('UHF','UHF:linear fitting','2.6GHz card 1','2.6GHz card 1:linear fitting');
        xlabel('distance [km]')
        ylabel('RSSI [dBm]')
        
        
    end
Byiringi's avatar
 
Byiringi committed
321 322 323
    
    
    
Byiringi's avatar
 
Byiringi committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418
    if idx==3 || idx==4
        
        
        figure(idx*10+3)
        
        
        subplot(2,1,1)
        
        hold off
        linearCoef1_before = polyfit(10*log10(new_distances1(index_break1_before_end:index_break1_before_start)),data1{idx}(index_break1_before_end:index_break1_before_start,13),1);
        linearFit1_before = polyval(linearCoef1_before,10*log10(new_distances1(index_break1_before_end:index_break1_before_start)));
        semilogx(new_distances1(1:I_RSSI_max1),data1{idx}(1:I_RSSI_max1,13),'rx',new_distances1(index_break1_before_end:index_break1_before_start),linearFit1_before,'r-')
        display(sprintf('Run %d :slope UHF before: %f',idx,linearCoef1_before(1)))
        
        
        hold on
        linearCoef2_before = polyfit(10*log10(new_distances2(index_break2_before_end:index_break2_before_start)),data2{idx}(index_break2_before_end:index_break2_before_start,13),1);
        linearFit2_before = polyval(linearCoef2_before,10*log10(new_distances2(index_break2_before_end:index_break2_before_start)));
        semilogx(new_distances2(1:I_RSSI_max2),data2{idx}(1:I_RSSI_max2,13),'bx',new_distances2(index_break2_before_end:index_break2_before_start),linearFit2_before,'b-')
        display(sprintf('Run %d :slope 2.6GHz before: %f',idx,linearCoef2_before(1)))
        
        
        title(sprintf('Run %d: With the data before the passing of the train',idx))
        legend('UHF','UHF:linear fitting','2.6GHz card 1','2.6GHz card 1:linear fitting');
        xlabel('distance [km]')
        ylabel('RSSI [dBm]')
        
        subplot(2,1,2)
        
        hold off
        linearCoef1_after = polyfit(10*log10(new_distances1(index_break1_after_start:index_break1_after_end)),data1{idx}(index_break1_after_start:index_break1_after_end,13),1);
        linearFit1_after = polyval(linearCoef1_after,10*log10(new_distances1(index_break1_after_start:index_break1_after_end)));
        semilogx(new_distances1(I_RSSI_max1:end),data1{idx}(I_RSSI_max1:end,13),'rx',new_distances1(index_break1_after_start:index_break1_after_end),linearFit1_after,'r-')
        display(sprintf('Run %d :slope UHF after: %f',idx,linearCoef1_after(1)))
        
        
        hold on
        linearCoef2_after = polyfit(10*log10(new_distances2(index_break2_after_start:index_break2_after_end)),data2{idx}(index_break2_after_start:index_break2_after_end,13),1);
        linearFit2_after = polyval(linearCoef2_after,10*log10(new_distances2(index_break2_after_start:index_break2_after_end)));
        semilogx(new_distances2(I_RSSI_max2:end),data2{idx}(I_RSSI_max2:end,13),'bx',new_distances2(index_break2_after_start:index_break2_after_end),linearFit2_after,'b-')
        display(sprintf('Run %d :slope 2.6GHz after: %f',idx,linearCoef2_after(1)))
        
        title(sprintf('Run %d: With the data after the passing of the train',idx))
        legend('UHF','UHF:linear fitting','2.6GHz card 1','2.6GHz card 1:linear fitting');
        xlabel('distance [km]')
        ylabel('RSSI [dBm]')
        
        
        % Zoom on the linear fitting
        
        figure(idx*10+4)
        
        
        subplot(2,1,1)
        
        hold off
        
        linearCoef1_before = polyfit(10*log10(new_distances1(index_break1_before_end:index_break1_before_start)),data1{idx}(index_break1_before_end:index_break1_before_start,13),1);
        linearFit1_before = polyval(linearCoef1_before,10*log10(new_distances1(index_break1_before_end:index_break1_before_start)));
        semilogx(new_distances1(index_break1_before_end:index_break1_before_start),data1{idx}(index_break1_before_end:index_break1_before_start,13),'rx',new_distances1(index_break1_before_end:index_break1_before_start),linearFit1_before,'r-')
        %display(sprintf('Run %d :slope UHF before: %f',idx,linearCoef1_before(1)))
        
        hold on
        
        linearCoef2_before = polyfit(10*log10(new_distances2(index_break2_before_end:index_break2_before_start)),data2{idx}(index_break2_before_end:index_break2_before_start,13),1);
        linearFit2_before = polyval(linearCoef2_before,10*log10(new_distances2(index_break2_before_end:index_break2_before_start)));
        semilogx(new_distances2(index_break2_before_end:index_break2_before_start),data2{idx}(index_break2_before_end:index_break2_before_start,13),'bx',new_distances2(index_break2_before_end:index_break2_before_start),linearFit2_before,'b-')
        %display(sprintf('Run %d :slope 2.6GHz before: %f',idx,linearCoef2_before(1)))
        
        title(sprintf('Run %d: With the data before the passing of the train',idx))
        legend('UHF','UHF:linear fitting','2.6GHz card 1','2.6GHz card 1:linear fitting');
        xlabel('distance [km]')
        ylabel('RSSI [dBm]')
        
        subplot(2,1,2)
        
        hold off
        
        
        linearCoef1_after = polyfit(10*log10(new_distances1(index_break1_after_start:index_break1_after_end)),data1{idx}(index_break1_after_start:index_break1_after_end,13),1);
        linearFit1_after = polyval(linearCoef1_after,10*log10(new_distances1(index_break1_after_start:index_break1_after_end)));
        semilogx(new_distances1(index_break1_after_start:index_break1_after_end),data1{idx}(index_break1_after_start:index_break1_after_end,13),'rx',new_distances1(index_break1_after_start:index_break1_after_end),linearFit1_after,'r-')
        %display(sprintf('Run %d :slope UHF after: %f',idx,linearCoef1_after(1)))
        hold on
        
        linearCoef2_after = polyfit(10*log10(new_distances2(index_break2_after_start:index_break2_after_end)),data2{idx}(index_break2_after_start:index_break2_after_end,13),1);
        linearFit2_after = polyval(linearCoef2_after,10*log10(new_distances2(index_break2_after_start:index_break2_after_end)));
        semilogx(new_distances2(index_break2_after_start:index_break2_after_end),data2{idx}(index_break2_after_start:index_break2_after_end,13),'bx',new_distances2(index_break2_after_start:index_break2_after_end),linearFit2_after,'b-')
        %display(sprintf('Run %d :slope 2.6GHz after: %f',idx,linearCoef2_after(1)))
        title(sprintf('Run %d: With the data after the passing of the train',idx))
        legend('UHF','UHF:linear fitting','2.6GHz card 1','2.6GHz card 1:linear fitting');
        xlabel('distance [km]')
        ylabel('RSSI [dBm]')
        
    end
Byiringi's avatar
 
Byiringi committed
419
    
Byiringi's avatar
 
Byiringi committed
420 421 422 423 424 425 426
    
    
    
    
    
    
    
Florian Kaltenberger's avatar
 
Florian Kaltenberger committed
427
end