%% Opak a repro
clear all;
close     all;
filename = 'matlab_data.xlsx';
sheet = 11;

%% LOAD DATA

freq = xlsread(filename, sheet, 'A3:A67');

DIF_SAR__H = xlsread(filename, sheet, 'C3:C67');
DIF_SAR__V = xlsread(filename, sheet, 'D3:D67');
DIF_FAR__H = xlsread(filename, sheet, 'E3:E67');
DIF_FAR__V = xlsread(filename, sheet, 'F3:F67');

STDEV_SAR__H = xlsread(filename, sheet, 'H3:H67');
STDEV_SAR__V = xlsread(filename, sheet, 'I3:I67');
STDEV_FAR__H = xlsread(filename, sheet, 'J3:J67');
STDEV_FAR__V = xlsread(filename, sheet, 'K3:K67');

%% Make_it_fine func


 O = 1;
for Q = 1:1:length(freq)
    for i = 1:1:7
        freqs(O) = freq(Q);
        DIF_SAR__Hs(O) = DIF_SAR__H(Q);
        DIF_SAR__Vs(O) = DIF_SAR__V(Q);
        DIF_FAR__Hs(O) = DIF_FAR__H(Q);
        DIF_FAR__Vs(O) = DIF_FAR__V(Q);
          
        
        STDEV_SAR__Hs(O) = STDEV_SAR__H(Q);
        STDEV_SAR__Vs(O) = STDEV_SAR__V(Q);
        STDEV_FAR__Hs(O) = STDEV_FAR__H(Q);
        STDEV_FAR__Vs(O) = STDEV_FAR__V(Q);
         
         
       O = O+1;
    end
end
   W = window(@hann, 10);
   
   freqn = filtfilt(W, 4.5, freqs);
   
   DIF_SAR__Hn = filtfilt(W, 4.5, DIF_SAR__Hs);
   DIF_SAR__Vn = filtfilt(W, 4.5, DIF_SAR__Vs);
   DIF_FAR__Hn = filtfilt(W, 4.5, DIF_FAR__Hs);
   DIF_FAR__Vn = filtfilt(W, 4.5, DIF_FAR__Vs);

   STDEV_SAR__Hn = filtfilt(W, 4.5, STDEV_SAR__Hs);
   STDEV_SAR__Vn = filtfilt(W, 4.5, STDEV_SAR__Vs);
   STDEV_FAR__Hn = filtfilt(W, 4.5, STDEV_FAR__Hs);
   STDEV_FAR__Vn = filtfilt(W, 4.5, STDEV_FAR__Vs);

   
   
%% Print results

figure(1)
set(gcf, 'color', [1 1 1])

subplot(2,1,1)
plot(freqn, STDEV_SAR__Hn, 'b', 'LineWidth',2)
hold on;
plot(freqn, STDEV_SAR__Vn,'g', 'LineWidth',2)
hold on;
plot(freqn, STDEV_FAR__Hn,'r', 'LineWidth',2)
hold on;
plot(freqn, STDEV_FAR__Vn,'k', 'LineWidth',2)
hold on;

set(gca,'FontSize',25)
title('Opakovavatelnost');
legend( 'SAR (H)', 'SAR (V)', 'FAR (H)', 'FAR (V)', 'Location','northwest','Orientation','vertical')
xlabel('Frekvence [MHz]');
ylabel('Odchylka [dB]');
xlim([30 1000])
% ylim([0 6])
set(gca,'FontSize',20)
 
subplot(2,1,2)
plot(freqn, DIF_SAR__Hn, 'b', 'LineWidth',2)
hold on;
plot(freqn, DIF_SAR__Vn,'g', 'LineWidth',2)
hold on;
plot(freqn, DIF_FAR__Hn,'r', 'LineWidth',2)
hold on;
plot(freqn, DIF_FAR__Vn,'k', 'LineWidth',2)
hold on;

set(gca,'FontSize',25)
title('Reprodukovatelnost');
legend( 'SAR (H)', 'SAR (V)', 'FAR (H)', 'FAR (V)', 'Location','southwest','Orientation','vertical')
xlabel('Frekvence [MHz]');
ylabel('Odchylka [dB]');
xlim([30 1000])
% ylim([0 6])
set(gca,'FontSize',20)
   