% satellites.m
clc
clear

% load variables for given day
load 2014-03-24/monday_24_03.mat;

% gps coordinates of Vienna north-east corner
ne_x = 48.292079905275806;
ne_y = 16.56538598632801;
% gps coordinates of Vienna south-west corner
sw_x = 48.09216946074534;
sw_y = 16.195977050781266;

% define needed variables
sat = zeros(1,13);
p = 0;
ds = 0;

% loop through the whole data set for the given day
for i = 1:length(m_id)
    
    % check whether the vehicle's gps coordinates are within Vienna region
    if (m_x(i) >= sw_y && m_x(i) <= ne_y) && (m_y(i) >= sw_x && m_y(i) <= ne_x)
        
        % increase counter
        p = p + 1;
        
        % add number of visible satellites to cumulative value
        ds = ds + m_sat(i);
        
        % store the number of given satellites
        if m_sat(i) == 0
            sat(1) = sat(1) + 1;
        else
            sat(m_sat(i)+1) = sat(m_sat(i)+1) + 1;
        end
        
    end
    
end

% average of visible satellites
ds/p

% calculate relative frequency
sat_p = zeros(1,13);
for i=1:13
    sat_p(i) = sat(i)/sum(sat)*100;
end

% plot histogram
bar(0:12,sat_p)
xlabel('Number of satellites');
ylabel('The proportion of the total sample size (%)');
set(gca,'XTick',[0:1:12]);
set(gca,'YTickMode','manual');
set(gca,'YGrid','on');
set(gca, 'FontSize', 12)
set(gca,'YTickLabel',num2str(get(gca,'YTick')'));
set(gca,'XTickLabel',{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'});
set(gca,'XLim',[-1 13]);