diff --git a/targets/PROJECTS/CORRIDOR/log_read.m b/targets/PROJECTS/CORRIDOR/log_read.m index acc78059e5..437d8dbac4 100644 --- a/targets/PROJECTS/CORRIDOR/log_read.m +++ b/targets/PROJECTS/CORRIDOR/log_read.m @@ -1,7 +1,12 @@ -top_dir = 'E:\EMOS\corridor\trials2 train'; +clear all +close all + +top_dir = 'P:\florian\CORRIDOR\trials2 train'; % needs to be updated according to your computer d1 = dir(fullfile(top_dir,'UHF','*.log')); d2 = dir(fullfile(top_dir,'2.6GHz','*.log')); + + start_time = [1.400489088000000e+09 1.400493112000000e+09 1.400499696000000e+09 1.400506864000000e+09]; for idx=1:length(d1) @@ -19,7 +24,7 @@ for idx=1:length(d1) rtime1 = data1{idx}(:,1) - data1{idx}(1,1); rtime2 = data2{idx}(:,1) - data2{idx}(1,1); - + %% plot gps coordinates figure(idx*10+1); hold off @@ -29,19 +34,8 @@ for idx=1:length(d1) xlabel('lat [deg]'); ylabel('lon [deg]') legend('UHF','2.6GHz') + title(sprintf('Run %d',idx)); - %% compute distance - distances1=zeros(1,size(data1{idx},1)); - distances2=zeros(1,size(data2{idx},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 - - %% plot RSSI % TODO: convert time (in unix epoch) into something more meaninful figure(idx*10+2); @@ -56,26 +50,232 @@ for idx=1:length(d1) ylabel('RSSI [dBm]') title(sprintf('Run %d',idx)); - %% - figure(idx*10+3) - hold off - plot(rtime1,distances1,'r') - hold on - plot(rtime2,distances2,'b') - xlabel('time [seconds]') - ylabel('dist [km]') - legend('UHF','2.6GHz') - %% - figure(idx*10+4) - hold off - plot(distances1,data1{idx}(:,13),'rx') - hold on - plot(distances2,data2{idx}(:,13),'bx') - plot(distances2,data2{idx}(:,19),'cx') - plot(distances2,data2{idx}(:,25),'mx') - xlabel('dist [km]') - ylabel('RSSI [dBm]') - legend('UHF','2.6GHz card 1','2.6GHz card 2','2.6GHz card 3'); + + %% 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 + + + if (idx==2)%For Run 2, there is an anomalous peak for the RSSI at the end. Here we ignore it + [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]'); + + + + + + + + + + + %% rssi(dBm) versus distance (log scale) + % We will plot the rssi versus the distance with the data before the passing of the train, and with the data after the passingof the train + + % we heuristically determine a starting point and a ending point for the linear fitting + if idx==1 + + distance_before_break1_start=0.3913;%in km + distance_before_break1_end=27.71; + distance_before_break2_start=0.3282; + distance_before_break2_end=15.24; + + distance_after_break1_start=0.85;%in km + distance_after_break1_end=9; + distance_after_break2_start=0.2911; + distance_after_break2_end=9; + end + + if idx==2 + distance_before_break1_start=0.8468;%in km + distance_before_break1_end=9; + distance_before_break2_start=0.4822; + distance_before_break2_end=7.099; + + distance_after_break1_start=0.5812;%in km + distance_after_break1_end=18.76; + distance_after_break2_start=0.4402; + distance_after_break2_end=10; + end + + if idx==3 + distance_before_break1_start=4.258;%in km + distance_before_break1_end=29.46; + distance_before_break2_start=8.375; + distance_before_break2_end=29.66; + + 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; + + distance_after_break1_start=0.3793;%in km + distance_after_break1_end=9; + distance_after_break2_start=0.5443; + distance_after_break2_end=9; + end + + % 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; + + %starting points + while (index_break1_before_startdistance_before_break1_start) + index_break1_before_start=index_break1_before_start+1; + end + while (index_break2_before_startdistance_before_break2_start) + index_break2_before_start=index_break2_before_start+1; + end + %ending points + while (index_break1_before_enddistance_before_break1_end) + index_break1_before_end=index_break1_before_end+1; + end + while (index_break2_before_enddistance_before_break2_end) + index_break2_before_end=index_break2_before_end+1; + end + + + %starting points + while (index_break1_after_start