
clc;clear all;close all

%% BER comparison
%%  41
%{
SNR = 6:0.5:14;
Nsym = 10000;
count = 0;
for i = 1:length(SNR); 
    count = count + 1
    BER_QIM4QAM_41(i) = simu_OFDM_QIM_LLR_4QAM_41(256,SNR(i),4,4,1,Nsym);
    BER_QIM4QAM_41_DFT(i) = simu_OFDM_QIM_LLR_4QAM_41_DFT(256,SNR(i),4,4,1,Nsym);
    BER_SMIM16QAM_41(i) = simu_OFDM_SMIM_LLR_16QAM_41(256,SNR(i),16,4,1,Nsym);
    BER_SMIM16QAM_41_DFT(i) = simu_OFDM_SMIM_LLR_16QAM_41_DFT(256,SNR(i),16,4,1,Nsym);


end

figure(1)
h1 = semilogy(SNR,BER_QIM4QAM_41,'-ro',...
              SNR,BER_QIM4QAM_41_DFT,'--ro',...
              SNR,BER_SMIM16QAM_41,'-bo',...
              SNR,BER_SMIM16QAM_41_DFT,'--bo');
hold on
p = 6:0.01:14;
plot(p,0.001*ones(1,length(p)),':k','linewidth',1.5);
legend('OFDM-I/Q-IM,4QAM,C(4,1)','OFDM-I/Q-IM,4QAM,C(4,1),DFT','OFDM-IM,16QAM,C(4,1)','OFDM-IM,16QAM,C(4,1),DFT')
 axis([6 14 1e-5 1e-1])
xlabel('SNR (dB)','FontName','Times New Roman','FontSize',16,'FontWeight','bold');
ylabel('BER','FontName','Times New Roman','FontSize',16,'FontWeight','bold');
set(gca,'FontName','Times New Roman','FontSize',16,'FontWeight','bold');
set(gca,'linewidth',1.5); 
set(gca,'TickLength',[0.015;0.025]);
set(gcf,'Color',[1,1,1]);
set(h1,'MarkerSize',6,'linewidth',1.5)
%}
%% 42
%{
SNR = 4:0.5:12;
Nsym = 10000;
count = 0;
for i = 1:length(SNR); 
    count = count + 1
    BER_QIM4QAM_41(i) = simu_OFDM_QIM_LLR_4QAM_41(256,SNR(i),4,4,1,Nsym);
    BER_QIM4QAM_41_DFT(i) = simu_OFDM_QIM_LLR_4QAM_41_DFT(256,SNR(i),4,4,1,Nsym);
    BER_SMIM16QAM_41(i) = simu_OFDM_SMIM_LLR_16QAM_41(256,SNR(i),16,4,1,Nsym);
    BER_SMIM16QAM_41_DFT(i) = simu_OFDM_SMIM_LLR_16QAM_41_DFT(256,SNR(i),16,4,1,Nsym);
    
    BER_QIM4QAM_42(i) = simu_OFDM_QIM_LLR_4QAM_42(256,SNR(i),4,4,2,Nsym);
    BER_QIM4QAM_42_DFT(i) = simu_OFDM_QIM_LLR_4QAM_42_DFT(256,SNR(i),4,4,2,Nsym);
    BER_SMIM8QAM_42(i) = simu_OFDM_SMIM_LLR_8QAM_42(256,SNR(i),8,4,2,Nsym);
    BER_SMIM8QAM_42_DFT(i) = simu_OFDM_SMIM_LLR_8QAM_42_DFT(256,SNR(i),8,4,2,Nsym);

end

figure(1)
h1 = semilogy(SNR,BER_QIM4QAM_41,'-ro',...
              SNR,BER_QIM4QAM_41_DFT,'--g+',...
              SNR,BER_SMIM16QAM_41,'-bo',...
              SNR,BER_SMIM16QAM_41_DFT,'--bo',...
              SNR,BER_QIM4QAM_42,'-ro',...
              SNR,BER_QIM4QAM_42_DFT,'--ro',...
              SNR,BER_SMIM8QAM_42,'-bo',...
              SNR,BER_SMIM8QAM_42_DFT,'--bo');
hold on
p =4:0.01:12;
plot(p,0.0038*ones(1,length(p)),':k','linewidth',1.5);
legend('OFDM with QIM,(4,1)','DFT-S-OFDM with QIM,(4,1)','OFDM with IM,(4,1)','DFT-S-OFDM with IM,(4,1)','OFDM with QIM,(4,2)','DFT-S-OFDM with QIM,(4,2)','OFDM with IM,(4,2)','DFT-S-OFDM with IM,(4,2)','location','best')
 axis([4 12 1e-4 0.2])
xlabel('SNR (dB)','FontName','Times New Roman','FontSize',16,'FontWeight','bold');
ylabel('BER','FontName','Times New Roman','FontSize',16,'FontWeight','bold');
set(gca,'FontName','Times New Roman','FontSize',16,'FontWeight','bold');
set(gca,'linewidth',1.5); 
set(gca,'TickLength',[0.015;0.025]);
set(gcf,'Color',[1,1,1]);
set(h1,'MarkerSize',6,'linewidth',1.5)
%}

SNR = 4:0.5:14;
Nsym = 10000;
count = 0;
for i = 1:length(SNR); 
    count = count + 1
    
    BER_4QAM(i) = simu_OFDM(256,SNR(i),4,Nsym);
    BER_OFDM_DFT(i) = simu_OFDM_DFT(256,SNR(i),4,Nsym);

end

figure(1)
h1 = semilogy(SNR,BER_4QAM,'-r',...
              SNR,BER_OFDM_DFT,'--r');
hold on
p =4:0.01:14;
plot(p,0.0038*ones(1,length(p)),':k','linewidth',1.5);
legend('OFDM','DFT-S-OFDM','location','best')
 axis([4 14 1e-4 0.2])
xlabel('SNR (dB)','FontName','Times New Roman','FontSize',16,'FontWeight','bold');
ylabel('BER','FontName','Times New Roman','FontSize',16,'FontWeight','bold');
set(gca,'FontName','Times New Roman','FontSize',16,'FontWeight','bold');
set(gca,'linewidth',1.5); 
set(gca,'TickLength',[0.015;0.025]);
set(gcf,'Color',[1,1,1]);
set(h1,'MarkerSize',6,'linewidth',1.5)
