%% read GPRMC in gps files
fid=fopen('gps_log.txt','r');
line=fgetl(fid);
while line~=-1
    if strncmp(line,'$GPRMC',6)
        virg=findstr(line,',');
        tm=line(virg(1)+1:virg(2)-1);
        lt=line(virg(3)+1:virg(4)-1);
        ln=line(virg(5)+1:virg(6)-1);
        dt=line(virg(9)+1:virg(10)-1);
        sg=line(virg(7)+1:virg(8)-1);
        cg=line(virg(8)+1:virg(9)-1);
        time=[time; tm];
        date=[date; dt];
        lat=[lat; lt];
        lon=[lon; ln];
        sog=[sog; sg]; 
        cog=[cog; cg];
    end
    line=fgetl(fid);
end
fclose(fid);


yy=str2num(date(:,5:6))+2000;
mm=str2num(date(:,3:4));
dd=str2num(date(:,1:2));
hh=str2num(time(:,1:2));
mn=str2num(time(:,3:4));
ss=str2num(time(:,5:6));
timegps=datenum(yy,mm,dd,hh,mn,ss);
lat=str2num(lat(:,1:2))+str2num(lat(:,3:4))/60+str2num(lat(:,6:8))/60000;%latitude decimal 
lon=str2num(lon(:,1:3))+str2num(lon(:,4:5))/60+str2num(lon(:,7:8))/6000;% longitude decimal 
sog=str2num(sog(:,1:4))*1852/36; % speed over ground in cm/s
cog=str2num(cog(:,1:3));% course over ground in degrees 

%filtering sog and cog : filtfilt with running average 25s for the polynome coefficients definition
windowsize = 25
sogfilt=filtfilt(ones(1,windowSize1)/windowSize1,1,sog);
cogfilt=filtfilt(ones(1,windowSize1)/windowSize1,1,cog);