close all
clear all
clc

% %% BW = 20 MHz
Tcp = 400e-9;
Tsymbol = 3.6e-6+Tcp;
Ndata = 52;
Fs = 20e6;
Nfft = 64;
%% Throughput coded data
% hard
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS0_LENGTH00100_shortCP_1000_repeat_2016-06-03_074454.mat')
figure
plot(SNR,results.throughput_coded_data)
max1(1,:) = results.throughput_coded_data;
hold all, grid on
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS1_LENGTH00100_shortCP_1000_repeat_2016-06-03_075049.mat')
plot(SNR,results.throughput_coded_data)
max1(2,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS2_LENGTH00100_shortCP_1000_repeat_2016-06-03_075647.mat')
plot(SNR,results.throughput_coded_data)
max1(3,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS3_LENGTH00100_shortCP_1000_repeat_2016-06-03_080238.mat')
plot(SNR,results.throughput_coded_data)
max1(4,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS4_LENGTH00100_shortCP_1000_repeat_2016-06-03_080843.mat')
plot(SNR,results.throughput_coded_data)
max1(5,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS5_LENGTH00100_shortCP_1000_repeat_2016-06-03_081431.mat')
plot(SNR,results.throughput_coded_data)
max1(6,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS6_LENGTH00100_shortCP_1000_repeat_2016-06-03_082033.mat')
plot(SNR,results.throughput_coded_data)
max1(7,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS7_LENGTH00100_shortCP_1000_repeat_2016-06-03_082646.mat')
plot(SNR,results.throughput_coded_data)
max1(8,:) = results.throughput_coded_data;
legend('MCS0','MCS1','MCS2','MCS3','MCS4','MCS5','MCS6','MCS7','Location','northwest')
xlabel('SNR [dB]')
ylabel('Coded data throughput [bps]')
% axis([SNR(1) SNR(end) 10^(-4) 1])

maxx1 = max(max1);
plot(SNR,maxx1,'r-','LineWidth',1.5)
% 
% 
% % soft
figure
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS0_LENGTH00100_shortCP_1000_repeat_2016-06-03_092303.mat')
plot(SNR,results.throughput_coded_data,'-')
max2(1,:) = results.throughput_coded_data;
hold all, grid on
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS1_LENGTH00100_shortCP_1000_repeat_2016-06-03_092939.mat')
plot(SNR,results.throughput_coded_data,'-')
max2(2,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS2_LENGTH00100_shortCP_1000_repeat_2016-06-03_093609.mat')
plot(SNR,results.throughput_coded_data,'-')
max2(3,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS3_LENGTH00100_shortCP_1000_repeat_2016-06-03_094257.mat')
plot(SNR,results.throughput_coded_data,'-')
max2(4,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS4_LENGTH00100_shortCP_1000_repeat_2016-06-03_094943.mat')
plot(SNR,results.throughput_coded_data,'-')
max2(5,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS5_LENGTH00100_shortCP_1000_repeat_2016-06-03_095653.mat')
plot(SNR,results.throughput_coded_data,'-')
max2(6,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS6_LENGTH00100_shortCP_1000_repeat_2016-06-03_100415.mat')
plot(SNR,results.throughput_coded_data,'-')
max2(7,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS7_LENGTH00100_shortCP_1000_repeat_2016-06-03_101148.mat')
plot(SNR,results.throughput_coded_data,'-')
max2(8,:) = results.throughput_coded_data;
legend('MCS0','MCS1','MCS2','MCS3','MCS4','MCS5','MCS6','MCS7','Location','northwest')
xlabel('SNR [dB]')
ylabel('Coded data throughput [bps]')

maxx2 = max(max2);
plot(SNR,maxx2,'r-','LineWidth',1.5)

figure
plot(SNR,maxx1,'r-','LineWidth',1.5)
hold on, grid on
plot(SNR,maxx2,'r--','LineWidth',1.5)

B = Ndata*Fs/Nfft;
F = (Tsymbol-Tcp)/Tsymbol;

C = F*B*log2(1+(10.^(SNR/10)));
% C2 = 20e6*log2((1+(10.^(SNR/10))));
plot(SNR,C,'k-','LineWidth',1.5)
% plot(SNR,C2,'r--')
xlabel('SNR [dB]')
ylabel('Maximum coded data throughput [bps]')
legend('Hard output demodulation','Soft output demodulation','System capacity','Location','northwest')
axis([SNR(1) SNR(end) 0 8e7])
% 
%% BER PSDU
% soft
figure
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS0_LENGTH00100_shortCP_1000_repeat_2016-06-03_092303.mat')
semilogy(SNR,results.ber_PSDU,'-')
% max2(1,:) = results.throughput_coded_data;
hold all, grid on
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS1_LENGTH00100_shortCP_1000_repeat_2016-06-03_092939.mat')
semilogy(SNR,results.ber_PSDU,'-')
% max2(2,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS2_LENGTH00100_shortCP_1000_repeat_2016-06-03_093609.mat')
semilogy(SNR,results.ber_PSDU,'-')
% max2(3,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS3_LENGTH00100_shortCP_1000_repeat_2016-06-03_094257.mat')
semilogy(SNR,results.ber_PSDU,'-')
% max2(4,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS4_LENGTH00100_shortCP_1000_repeat_2016-06-03_094943.mat')
semilogy(SNR,results.ber_PSDU,'-')
% max2(5,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS5_LENGTH00100_shortCP_1000_repeat_2016-06-03_095653.mat')
semilogy(SNR,results.ber_PSDU,'-')
% max2(6,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS6_LENGTH00100_shortCP_1000_repeat_2016-06-03_100415.mat')
semilogy(SNR,results.ber_PSDU,'-')
% max2(7,:) = results.throughput_coded_data;
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS7_LENGTH00100_shortCP_1000_repeat_2016-06-03_101148.mat')
semilogy(SNR,results.ber_PSDU,'-')
% max2(8,:) = results.throughput_coded_data;
legend('MCS0','MCS1','MCS2','MCS3','MCS4','MCS5','MCS6','MCS7','Location','northeast')
xlabel('SNR [dB]')
ylabel('BER PSDU [-]')
axis([SNR(1) SNR(end) 1e-4 1])
% 
% 
% %% Throughput PSDU data
% % hard
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS0_LENGTH00100_shortCP_1000_repeat_2016-06-03_074454.mat')
% figure
% plot(SNR,results.throughput_PSDU)
% hold all, grid on
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS1_LENGTH00100_shortCP_1000_repeat_2016-06-03_075049.mat')
% plot(SNR,results.throughput_PSDU)
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS2_LENGTH00100_shortCP_1000_repeat_2016-06-03_075647.mat')
% plot(SNR,results.throughput_PSDU)
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS3_LENGTH00100_shortCP_1000_repeat_2016-06-03_080238.mat')
% plot(SNR,results.throughput_PSDU)
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS4_LENGTH00100_shortCP_1000_repeat_2016-06-03_080843.mat')
% plot(SNR,results.throughput_PSDU)
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS5_LENGTH00100_shortCP_1000_repeat_2016-06-03_081431.mat')
% plot(SNR,results.throughput_PSDU)
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS6_LENGTH00100_shortCP_1000_repeat_2016-06-03_082033.mat')
% plot(SNR,results.throughput_PSDU)
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_HD_MCS7_LENGTH00100_shortCP_1000_repeat_2016-06-03_082646.mat')
% plot(SNR,results.throughput_PSDU)
% legend('MCS0','MCS1','MCS2','MCS3','MCS4','MCS5','MCS6','MCS7')
% xlabel('SNR [dB]')
% % axis([SNR(1) SNR(end) 10^(-4) 1])
% 
% % soft
% figure
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS0_LENGTH00100_shortCP_1000_repeat_2016-06-03_092303.mat')
% plot(SNR,results.throughput_PSDU,'--')
% hold all, grid on
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS1_LENGTH00100_shortCP_1000_repeat_2016-06-03_092939.mat')
% plot(SNR,results.throughput_PSDU,'--')
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS2_LENGTH00100_shortCP_1000_repeat_2016-06-03_093609.mat')
% plot(SNR,results.throughput_PSDU,'--')
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS3_LENGTH00100_shortCP_1000_repeat_2016-06-03_094257.mat')
% plot(SNR,results.throughput_PSDU,'--')
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS4_LENGTH00100_shortCP_1000_repeat_2016-06-03_094943.mat')
% plot(SNR,results.throughput_PSDU,'--')
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS5_LENGTH00100_shortCP_1000_repeat_2016-06-03_095653.mat')
% plot(SNR,results.throughput_PSDU,'--')
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS6_LENGTH00100_shortCP_1000_repeat_2016-06-03_100415.mat')
% plot(SNR,results.throughput_PSDU,'--')
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_BCC_LLR_MCS7_LENGTH00100_shortCP_1000_repeat_2016-06-03_101148.mat')
% plot(SNR,results.throughput_PSDU,'--')
% legend('MCS0','MCS1','MCS2','MCS3','MCS4','MCS5','MCS6','MCS7')
% xlabel('SNR [dB]')
% 
% 
% %% BW = 40 MHz
% 
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_HD_MCS0_LENGTH00100_shortCP_1000_repeat_2016-06-03_083256.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_HD_MCS1_LENGTH00100_shortCP_1000_repeat_2016-06-03_083855.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_HD_MCS2_LENGTH00100_shortCP_1000_repeat_2016-06-03_084507.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_HD_MCS3_LENGTH00100_shortCP_1000_repeat_2016-06-03_085111.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_HD_MCS4_LENGTH00100_shortCP_1000_repeat_2016-06-03_085730.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_HD_MCS5_LENGTH00100_shortCP_1000_repeat_2016-06-03_090335.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_HD_MCS6_LENGTH00100_shortCP_1000_repeat_2016-06-03_090952.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_HD_MCS7_LENGTH00100_shortCP_1000_repeat_2016-06-03_091619.mat')
% % 
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_LLR_MCS0_LENGTH00100_shortCP_1000_repeat_2016-06-03_101836.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_LLR_MCS1_LENGTH00100_shortCP_1000_repeat_2016-06-03_102516.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_LLR_MCS2_LENGTH00100_shortCP_1000_repeat_2016-06-03_103158.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_LLR_MCS3_LENGTH00100_shortCP_1000_repeat_2016-06-03_103843.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_LLR_MCS4_LENGTH00100_shortCP_1000_repeat_2016-06-03_104530.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_LLR_MCS5_LENGTH00100_shortCP_1000_repeat_2016-06-03_105244.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_LLR_MCS6_LENGTH00100_shortCP_1000_repeat_2016-06-03_110010.mat')
% % load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW40_from-10to30_dB_BCC_LLR_MCS7_LENGTH00100_shortCP_1000_repeat_2016-06-03_110748.mat')
% 
% % soft
% 
% 
% 
% % Fcorr = 1;
% % C = Fcorr*20e6*log2(1+10.^(SNR/10));
% % plot(SNR,C,'k')
% 
% % legend('MCS0','MCS1','MCS2','MCS3','MCS4','MCS5','MCS6','MCS7')
% % axis([SNR(1) SNR(end) 10^(-4) 1])
% axis([SNR(1) SNR(end) 0 1e8])

%% LDPC
figure;

load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS0_LENGTH30001_shortCP_10_repeat_2016-06-03_192104.mat')
semilogy(SNR,results.ber_PSDU)
hold all
grid on
axis([SNR(1) SNR(end) 1e-6 1])
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS1_LENGTH30001_shortCP_10_repeat_2016-06-03_194535.mat')
semilogy(SNR,results.ber_PSDU)
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS2_LENGTH00031_shortCP_10_repeat_2016-06-03_152827.mat')
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS2_LENGTH00100_shortCP_1000_repeat_2016-06-03_140130.mat')
% load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS2_LENGTH30001_shortCP_10_repeat_2016-06-03_171335.mat')
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS2_LENGTH30001_shortCP_10_repeat_2016-06-03_200633.mat')

a = [0.376995766807773,...
    0.369797673410886,...
    0.362066264457851,...
    0.354681510616313,...
    0.345914719509350,...
    0.337726242458585,...
    0.327809906336455,...
    0.318676460784641,...
    0.308823872537582,...
    0.298412136262125,...
    0.287398336722109,...
    0.276353704876504,...
    0.264440768641045,...
    0.252425335822139,...
    0.240082413919536,...
    0.226762441251958,...
    0.213309556348122,...
    0.199974584180527,...
    0.186243375220826,...
    0.172497166761108,...
    0.158583880537315,...
    0.144033532215593,...
    0.130199826672444,...
    0.116382370587647,...
    0.102963651211626,...
    0.089639512016266,...
    0.074043265224493,...%0.077043265224493,...
    0.055145328489050,...
    0.015867371087630,...
    0.005467301089964,...
    0.000813026232459,...%
    0.00007,...
    0.00000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
    0.000,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0,...
                   0]
semilogy(SNR,a)
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS3_LENGTH30001_shortCP_10_repeat_2016-06-03_204016.mat')
semilogy(SNR,results.ber_PSDU)
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS4_LENGTH30001_shortCP_10_repeat_2016-06-03_210411.mat')
semilogy(SNR,results.ber_PSDU)
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS5_LENGTH30001_shortCP_10_repeat_2016-06-03_213512.mat')
semilogy(SNR,results.ber_PSDU)
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS6_LENGTH30001_shortCP_10_repeat_2016-06-03_220238.mat')
semilogy(SNR,results.ber_PSDU)
load('D:\Work_SVN\trunk\WIFIsim\results\wifi_802dot11n_HT_CBW20_from-10to30_dB_LDPC_LLR_MCS7_LENGTH30001_shortCP_10_repeat_2016-06-03_222828.mat')
semilogy(SNR,results.ber_PSDU)

xlabel('SNR [dB]')
ylabel('BER PSDU [-]')

legend('MCS0','MCS1','MCS2','MCS3','MCS4','MCS5','MCS6','MCS7')
axis([SNR(1) SNR(end) 1e-4 1])