clear all;
close all;
clc;
clf;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                                                %
%                Vyrovnani skupinoveho zpozdeni pomoci zprisneni kmitoctu fp                     %
%                                                                                                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


p = j*(10:10000:100000000);  % Vektor komplexní frekvence


%------------------------------- Koeficienty prenosových funkcí ---------------------------------

%------------------------------------ Cauerova B6 4.5MHz ----------------------------------------
A = [1 41169680 2.159544E+15 5.410112E+22 1.210116E+30 1.579738E+37 1.258806E+44];
B = [29894420000000 0 1.255416E+29 0 1.230152E+44];
%------------------------------------- Cauerova B8 5Mhz -----------------------------------------
A1 = [1 45104200 3.258557E+15 1.012341E+23 3.411147E+30 6.969306E+37 1.250542E+45 ...
      1.385761E+52 9.341844E+58];
B1 = [9499079000000 0 6.523124E+28 0 1.374309E+44 0 9.129199E+58];
%----------------------------------- Cauerova B8 5.2 MHz ---------------------------------------- 
A2 = [1 46854160 3.570035E+15 1.159987E+23 4.129303E+30 8.890186E+37 1.69613E+45 ...
      2.005136E+52 1.481216E+59];
B2 = [16384690000000 0 1.085172E+29 0 2.225799E+44 0 1.447499E+59];
%----------------------------------- Cauerova B10 5.5 MHz ---------------------------------------
A3 = [1 49326390 4.833158E+15 1.785843E+23 8.464802E+30 2.298921E+38 6.501085E+45 ...
      1.216153E+53 2.007141E+60 2.115582E+67 1.40161E+74];
B3 = [7169304000000 0 6.582875E+28 0 2.099424E+44 0 2.823385E+59 0 1.369705E+74];


% Vypocet skupinového zpozdeni z koeficientu

delay = grdelays(B,A,imag(p));      		% Cauer B6 4.5MHz   		
delay1 = grdelays(B1,A1,imag(p));     		% Cauer B8 5MHz   		
delay2 = grdelays(B2,A2,imag(p));			% Cauer B8 5.2MHz
delay3 = grdelays(B3,A3,imag(p));			% Cauer B10 5.5MHz


figure(1);
plot(imag(p)/(2*pi),delay,'k');
xlabel('--> f[Hz]');
ylabel('--> t[s]');
title('                Korigování skup. zp. zpøísnìním fp na 5MHz, 5.2MHz, 5.5MHz - Cauer');
hold on;
plot([4500000 4500000],[0 2e-6],'k');
hold on;
axis([0 4500000 1e-7 6e-7]);
grid; hold on;
plot(imag(p)/(2*pi),delay1,'k');hold on;
plot(imag(p)/(2*pi),delay2,'k');hold on;
plot(imag(p)/(2*pi),delay3,'k');
hold off;

figure(2);
plot(imag(p)/(2*pi),delay,'k');
xlabel('--> f[Hz]');
ylabel('--> t[s]');
title('                Korigování skup. zp. zpøísnìním fp na 5MHz, 5.2MHz, 5.5MHz - Cauer');
hold on;
plot([4500000 4500000],[0 2e-6],'k');
hold on;
axis([0 10000000 0 16e-7]);
grid; hold on;
plot(imag(p)/(2*pi),delay1,'k');hold on;
plot(imag(p)/(2*pi),delay2,'k');hold on;
plot(imag(p)/(2*pi),delay3,'k');
hold off;
