clear all, close all

file_20MHz_mcs8_2Mbps_toAP ={'20MHz_mcs8_25_2Mbps_toAP.dat', '20MHz_mcs8_50_2Mbps_toAP.dat', '20MHz_mcs8_75_2Mbps_toAP.dat', '20MHz_mcs8_100_2Mbps_toAP.dat', '20MHz_mcs8_125_2Mbps_toAP.dat', '20MHz_mcs8_150_2Mbps_toAP.dat'};
file_40MHz_mcs8_2Mbps_toAP ={'40MHz_mcs8_25_2Mbps_toAP.dat', '40MHz_mcs8_50_2Mbps_toAP.dat', '40MHz_mcs8_75_2Mbps_toAP.dat', '40MHz_mcs8_100_2Mbps_toAP.dat', '40MHz_mcs8_125_2Mbps_toAP.dat', '40MHz_mcs8_150_2Mbps_toAP.dat'};
file_80MHz_mcs8_2Mbps_toAP ={'80MHz_mcs8_25_2Mbps_toAP.dat', '80MHz_mcs8_50_2Mbps_toAP.dat', '80MHz_mcs8_75_2Mbps_toAP.dat', '80MHz_mcs8_100_2Mbps_toAP.dat', '80MHz_mcs8_125_2Mbps_toAP.dat', '80MHz_mcs8_150_2Mbps_toAP.dat'};
file_160MHz_mcs8_2Mbps_toAP ={'160MHz_mcs8_25_2Mbps_toAP.dat', '160MHz_mcs8_50_2Mbps_toAP.dat', '160MHz_mcs8_75_2Mbps_toAP.dat', '160MHz_mcs8_100_2Mbps_toAP.dat', '160MHz_mcs8_125_2Mbps_toAP.dat', '160MHz_mcs8_150_2Mbps_toAP.dat'};

file_20MHz_mcs8_2Mbps ={'20MHz_mcs8_25_2Mbps.dat', '20MHz_mcs8_50_2Mbps.dat', '20MHz_mcs8_75_2Mbps.dat', '20MHz_mcs8_100_2Mbps.dat', '20MHz_mcs8_125_2Mbps.dat', '20MHz_mcs8_150_2Mbps.dat'};
file_40MHz_mcs8_2Mbps ={'40MHz_mcs8_25_2Mbps.dat', '40MHz_mcs8_50_2Mbps.dat', '40MHz_mcs8_75_2Mbps.dat', '40MHz_mcs8_100_2Mbps.dat', '40MHz_mcs8_125_2Mbps.dat', '40MHz_mcs8_150_2Mbps.dat'};
file_80MHz_mcs8_2Mbps ={'80MHz_mcs8_25_2Mbps.dat', '80MHz_mcs8_50_2Mbps.dat', '80MHz_mcs8_75_2Mbps.dat', '80MHz_mcs8_100_2Mbps.dat', '80MHz_mcs8_125_2Mbps.dat', '80MHz_mcs8_150_2Mbps.dat'};
file_160MHz_mcs8_2Mbps ={'160MHz_mcs8_25_2Mbps.dat', '160MHz_mcs8_50_2Mbps.dat', '160MHz_mcs8_75_2Mbps.dat', '160MHz_mcs8_100_2Mbps.dat', '160MHz_mcs8_125_2Mbps.dat', '160MHz_mcs8_150_2Mbps.dat'};

for i=1:6
%% mcs8     
    %% 20MHz
    clear throughput20; clear Packets20;
        fileID = fopen(file_20MHz_mcs8_2Mbps_toAP{1,i},'rt');
    datacell = textscan(fileID,'%f', 'CollectOutput',1);
    fclose(fileID);
    dat_20MHz_toAP = datacell{1};
    n=dat_20MHz_toAP(1,:);
    for j=1:n
        throughput20(j)=dat_20MHz_toAP(2*j+1,:);
        Packets20(j)=dat_20MHz_toAP(2*j,:);
    end  
    MHz20_mcs8_2Mbps_toAP(1,i)=mean(throughput20); 
    MHz20_mcs8_2Mbps_toAP(2,i)=max(throughput20);  
    MHz20_mcs8_2Mbps_toAP(3,i)=min(throughput20);  
    MHz20_mcs8_2Mbps_toAP_Aggr(i)=((sum(Packets20)*1472*8)/(10*1024*1024));
    
    %% 40MHz
    clear throughput40; clear Packets40;
    fileID = fopen(file_40MHz_mcs8_2Mbps_toAP{1,i},'rt');
    datacell = textscan(fileID,'%f', 'CollectOutput',1);
    fclose(fileID);
    dat_40MHz_toAP = datacell{1};
    n=dat_40MHz_toAP(1,:);
    for j=1:n
        throughput40(j)=dat_40MHz_toAP(2*j+1,:);
        Packets40(j)=dat_40MHz_toAP(2*j,:);
    end  
    MHz40_mcs8_2Mbps_toAP(1,i)=mean(throughput40); 
    MHz40_mcs8_2Mbps_toAP(2,i)=max(throughput40);  
    MHz40_mcs8_2Mbps_toAP(3,i)=min(throughput40);  
    MHz40_mcs8_2Mbps_toAP_Aggr(i)=((sum(Packets40)*1472*8)/(10*1024*1024));
     %% 80MHz
    clear throughput80; clear Packets80;
    fileID = fopen(file_80MHz_mcs8_2Mbps_toAP{1,i},'rt');
    datacell = textscan(fileID,'%f', 'CollectOutput',1);
    fclose(fileID);
    dat_80MHz_toAP = datacell{1};
    n=dat_80MHz_toAP(1,:);
    for j=1:n
        throughput80(j)=dat_80MHz_toAP(2*j+1,:);
        Packets80(j)=dat_80MHz_toAP(2*j,:);
    end  
    MHz80_mcs8_2Mbps_toAP(1,i)=mean(throughput80); 
    MHz80_mcs8_2Mbps_toAP(2,i)=max(throughput80);  
    MHz80_mcs8_2Mbps_toAP(3,i)=min(throughput80);  
    MHz80_mcs8_2Mbps_toAP_Aggr(i)=((sum(Packets80)*1472*8)/(10*1024*1024));
     %% 160MHz
    clear throughput160; clear Packets160;
    fileID = fopen(file_160MHz_mcs8_2Mbps_toAP{1,i},'rt');
    datacell = textscan(fileID,'%f', 'CollectOutput',1);
    fclose(fileID);
    dat_160MHz_toAP = datacell{1};
    n=dat_160MHz_toAP(1,:);
    for j=1:n
        throughput160(j)=dat_160MHz_toAP(2*j+1,:);
        Packets160(j)=dat_160MHz_toAP(2*j,:);
    end  
    MHz160_mcs8_2Mbps_toAP(1,i)=mean(throughput160); 
    MHz160_mcs8_2Mbps_toAP(2,i)=max(throughput160);  
    MHz160_mcs8_2Mbps_toAP(3,i)=min(throughput160);  
    MHz160_mcs8_2Mbps_toAP_Aggr(i)=((sum(Packets160)*1472*8)/(10*1024*1024));
%     
%% mcs8 
    %% 20MHz
    clear throughput20; clear Packets20;
    fileID = fopen(file_20MHz_mcs8_2Mbps{1,i},'rt');
    datacell = textscan(fileID,'%f', 'CollectOutput',1);
    fclose(fileID);
    dat_20MHz = datacell{1};
    n=dat_20MHz(1,:);
    for j=1:n
        throughput20(j)=dat_20MHz(2*j+1,:);
        Packets20(j)=dat_20MHz(2*j,:);
    end  
    MHz20_mcs8_2Mbps(1,i)=mean(throughput20); 
    MHz20_mcs8_2Mbps(2,i)=max(throughput20);  
    MHz20_mcs8_2Mbps(3,i)=min(throughput20);  
    MHz20_mcs8_2Mbps_Aggr(i)=((sum(Packets20)*1472*8)/(10*1024*1024));
    
    %% 40MHz
    clear throughput40; clear Packets40;
    fileID = fopen(file_40MHz_mcs8_2Mbps{1,i},'rt');
    datacell = textscan(fileID,'%f', 'CollectOutput',1);
    fclose(fileID);
    dat_40MHz = datacell{1};
    n=dat_40MHz(1,:);
    for j=1:n
        throughput40(j)=dat_40MHz(2*j+1,:);
        Packets40(j)=dat_40MHz(2*j,:);
    end  
    MHz40_mcs8_2Mbps(1,i)=mean(throughput40); 
    MHz40_mcs8_2Mbps(2,i)=max(throughput40);  
    MHz40_mcs8_2Mbps(3,i)=min(throughput40);  
    MHz40_mcs8_2Mbps_Aggr(i)=((sum(Packets40)*1472*8)/(10*1024*1024));
     %% 80MHz
    clear throughput80; clear Packets80;
    fileID = fopen(file_80MHz_mcs8_2Mbps{1,i},'rt');
    datacell = textscan(fileID,'%f', 'CollectOutput',1);
    fclose(fileID);
    dat_80MHz = datacell{1};
    n=dat_80MHz(1,:);
    for j=1:n
        throughput80(j)=dat_80MHz(2*j+1,:);
        Packets80(j)=dat_80MHz(2*j,:);
    end  
    MHz80_mcs8_2Mbps(1,i)=mean(throughput80); 
    MHz80_mcs8_2Mbps(2,i)=max(throughput80);  
    MHz80_mcs8_2Mbps(3,i)=min(throughput80); 
    MHz80_mcs8_2Mbps_Aggr(i)=((sum(Packets80)*1472*8)/(10*1024*1024));
     %% 160MHz
    clear throughput160; clear Packets160;
    fileID = fopen(file_160MHz_mcs8_2Mbps{1,i},'rt');
    datacell = textscan(fileID,'%f', 'CollectOutput',1);
    fclose(fileID);
    dat_160MHz = datacell{1};
    n=dat_160MHz(1,:);
    for j=1:n
        throughput160(j)=dat_160MHz(2*j+1,:);
        Packets160(j)=dat_160MHz(2*j,:);
    end  
    MHz160_mcs8_2Mbps(1,i)=mean(throughput160); 
    MHz160_mcs8_2Mbps(2,i)=max(throughput160);  
    MHz160_mcs8_2Mbps(3,i)=min(throughput160);  
    MHz160_mcs8_2Mbps_Aggr(i)=((sum(Packets160)*1472*8)/(10*1024*1024)); 
end

X_axis = 25:25:150;

figure('name','Priemerná priepustnos� na klienta: ','Position', [50, 450, 790, 550])

plot(X_axis,MHz20_mcs8_2Mbps_toAP(1,:),'-o','LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz40_mcs8_2Mbps_toAP(1,:),'-v','LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz80_mcs8_2Mbps_toAP(1,:),'-d','LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz160_mcs8_2Mbps_toAP(1,:),'-s','LineWidth',2,'MarkerSize',6); hold on
leg=legend('kanál 20 MHz','kanál 40 MHz','kanál 80 MHz','kanál 160 MHz','Location','southwest');
set(leg,'FontSize',12 );
title('Priemerná priepustnos� na klienta: uplink, MCS 5','FontSize',14)
xlabel('Poèet asociovaných klientov','FontSize',14)
ylabel('Priepustnos� [Mbit/s]','FontSize',14)

figure('name','Priemerná priepustnos� na klienta:  ','Position', [50, 450, 790, 550])
plot(X_axis,MHz20_mcs8_2Mbps(1,:),'-o','LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz40_mcs8_2Mbps(1,:),'-v','LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz80_mcs8_2Mbps(1,:),'-d','LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz160_mcs8_2Mbps(1,:),'-s','LineWidth',2,'MarkerSize',6); hold on
leg=legend('kanál 20 MHz','kanál 40 MHz','kanál 80 MHz','kanál 160 MHz','Location','southwest');
set(leg,'FontSize',12 );
title('Priemerná priepustnos� na klienta: downlink, MCS 5','FontSize',14)
xlabel('Poèet asociovaných klientov','FontSize',14)
ylabel('Priepustnos� [Mbit/s]','FontSize',14)

%% Subplots
figure('name','Priemerná priepustnos� na klienta: MCS 8','Position', [50, 50, 1180, 870])
%% kanál 20 MHz
subplot(2,2,1);
plot(X_axis,MHz20_mcs8_2Mbps(1,:),'-o','Color',[1 0.4 0],'LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz20_mcs8_2Mbps_toAP(1,:),'-d','Color',[0.2 0.4 1],'LineWidth',2,'MarkerSize',6); hold on
ylim([0.25 2.25]);set(gca,'XTick',[25 50 75 100 125 150],'FontSize',12);
leg=legend('AP   -> STA','STA -> AP','Location','northeast');
set(leg,'FontSize',10); grid on
title('kanál 20 MHz','FontSize',12,'FontWeight','normal' )
xlabel('Poèet asociovaných klientov','FontSize',12)
ylabel('Priepustnos� [Mbit/s]','FontSize',12)
%% kanál 40 MHz
subplot(2,2,2);
plot(X_axis,MHz40_mcs8_2Mbps(1,:),'-o','Color',[1 0.4 0],'LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz40_mcs8_2Mbps_toAP(1,:),'-d','Color',[0.2 0.4 1],'LineWidth',2,'MarkerSize',6); hold on
ylim([0.25 2.25]);set(gca,'XTick',[25 50 75 100 125 150],'FontSize',12);
leg=legend('AP   -> STA','STA -> AP','Location','northeast');
set(leg,'FontSize',10); grid on
title('kanál 40 MHz','FontSize',12,'FontWeight','normal')
xlabel('Poèet asociovaných klientov','FontSize',12)
ylabel('Priepustnos� [Mbit/s]','FontSize',12)
%% kanál 80 MHz
subplot(2,2,3);
plot(X_axis,MHz80_mcs8_2Mbps(1,:),'-o','Color',[1 0.4 0],'LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz80_mcs8_2Mbps_toAP(1,:),'-d','Color',[0.2 0.4 1],'LineWidth',2,'MarkerSize',6); hold on 
ylim([0.25 2.25]);set(gca,'XTick',[25 50 75 100 125 150],'FontSize',12);
leg=legend('AP   -> STA','STA -> AP','Location','southwest'); 
set(leg,'FontSize',10); grid on
title('kanál 80 MHz','FontSize',12,'FontWeight','normal')
xlabel('Poèet asociovaných klientov','FontSize',12)
ylabel('Priepustnos� [Mbit/s]','FontSize',12)
%% kanál 160 MHz
subplot(2,2,4);
plot(X_axis,MHz160_mcs8_2Mbps(1,:),'-o','Color',[1 0.4 0],'LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz160_mcs8_2Mbps_toAP(1,:),'-d','Color',[0.2 0.4 1],'LineWidth',2,'MarkerSize',6); hold on
ylim([0.25 2.25]); set(gca,'XTick',[25 50 75 100 125 150],'FontSize',12);
leg=legend('AP   -> STA','STA -> AP','Location','southwest');
set(leg,'FontSize',10); grid on
title('kanál 160 MHz','FontSize',12,'FontWeight','normal')
xlabel('Poèet asociovaných klientov','FontSize',12)
ylabel('Priepustnos� [Mbit/s]','FontSize',12)
suptitle('Priemerná priepustnos� na klienta: MCS 8, aktívnych klientov 100%',14) ;

%% Subplots
figure('name','Agregovaná priepustnos�: MCS 8','Position', [50, 50, 1180, 870])
%% kanál 20 MHz
subplot(2,2,1);
plot(X_axis,MHz20_mcs8_2Mbps_Aggr,'-o','Color',[1 0.4 0],'LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz20_mcs8_2Mbps_toAP_Aggr,'-d','Color',[0.2 0.4 1],'LineWidth',2,'MarkerSize',6); hold on
set(gca,'XTick',[25 50 75 100 125 150],'FontSize',12);ylim([40 100])
leg=legend('AP   -> STA',...
           'STA -> AP','Location','southeast');
set(leg,'FontSize',10); grid on
title('kanál 20 MHz','FontSize',12,'FontWeight','normal' )
xlabel('Poèet asociovaných klientov','FontSize',12)
ylabel('Agregovaná priepustnos� [Mbit/s]','FontSize',12)
%% kanál 40 MHz
subplot(2,2,2);
plot(X_axis,MHz40_mcs8_2Mbps_Aggr,'-o','Color',[1 0.4 0],'LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz40_mcs8_2Mbps_toAP_Aggr,'-d','Color',[0.2 0.4 1],'LineWidth',2,'MarkerSize',6); hold on
set(gca,'XTick',[25 50 75 100 125 150],'FontSize',12);ylim([40 180])
leg=legend('AP   -> STA','STA -> AP','Location','southeast');
set(leg,'FontSize',10); grid on
title('kanál 40 MHz','FontSize',12,'FontWeight','normal')
xlabel('Poèet asociovaných klientov','FontSize',12)
ylabel('Agregovaná priepustnos� [Mbit/s]','FontSize',12)
%% kanál 80 MHz
subplot(2,2,3);
plot(X_axis,MHz80_mcs8_2Mbps_Aggr,'-o','Color',[1 0.4 0],'LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz80_mcs8_2Mbps_toAP_Aggr,'-d','Color',[0.2 0.4 1],'LineWidth',2,'MarkerSize',6); hold on 
set(gca,'XTick',[25 50 75 100 125 150],'FontSize',12);ylim([40 180])
leg=legend('AP   -> STA','STA -> AP','Location','southeast'); 
set(leg,'FontSize',10); grid on
title('kanál 80 MHz','FontSize',12,'FontWeight','normal')
xlabel('Poèet asociovaných klientov','FontSize',12)
ylabel('Agregovaná priepustnos� [Mbit/s]','FontSize',12)
%% kanál 160 MHz
subplot(2,2,4);
plot(X_axis,MHz160_mcs8_2Mbps_Aggr,'-o','Color',[1 0.4 0],'LineWidth',2,'MarkerSize',6); hold on
plot(X_axis,MHz160_mcs8_2Mbps_toAP_Aggr,'-d','Color',[0.2 0.4 1],'LineWidth',2,'MarkerSize',6); hold on
set(gca,'XTick',[25 50 75 100 125 150],'FontSize',12);ylim([40 180])
leg=legend('AP   -> STA','STA -> AP','Location','southeast');
set(leg,'FontSize',10); grid on
title('kanál 160 MHz','FontSize',12,'FontWeight','normal')
xlabel('Poèet asociovaných klientov','FontSize',12)
ylabel('Agregovaná priepustnos� [Mbit/s]','FontSize',12)
suptitle('Agregovaná priepustnos�: MCS 8, aktívnych klientov 100%',14) ;