clear all;
close all;
clc;
clf;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                                                                                %
%                Vyrovnani skupinoveho zpozdeni pomoci fazovacich clanku 2øadu                   %
%                                                                                                %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

%---------------------------- Parametry fázovacích èlánkù --------------------------------

Qr = 0.5;
wr = 2*pi*1.4e+6;
pr = wr/Qr;

Qr1 = 1.2;
wr1 = 2*pi*2.2e+6;
pr1 = wr1/Qr1;

Qr2 = 2.0;
wr2 = 2*pi*3.7e+6;
pr2 = wr2/Qr2;

%-------------------------------- Skupinove zpozdeni --------------------------------------

%-------------------------------------- CauerB6 -------------------------------------------

% Koeficienty prenosove funkce daneho filtru

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];

% Koeficienty prenosove funkce fazovacich clanku druheho radu

A1 = [1 pr wr.^2];     % Jmenovatel
B1 = [1 -pr wr.^2];    % Citatel

A2 = [1 pr1 wr1.^2];
B2 = [1 -pr1 wr1.^2];

A3 = [1 pr2 wr2.^2];
B3 = [1 -pr2 wr2.^2];


delay  = grdelays(B ,A ,imag(p));    % Funkce pro výpocet skupinového zpozdeni z koeficientu 		
delay1 = grdelays(B1,A1,imag(p));    % prenosove funkce 		
delay2 = grdelays(B2,A2,imag(p));     		
delay3 = grdelays(B3,A3,imag(p));     		


figure(1);
plot(imag(p)/(2*pi),delay,'k'); 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 on;
plot(imag(p)/(2*pi),(delay+delay1+delay2+delay3),'k'); hold on;

text(3.8e+6,4.7e-7,'CauerB6');
text(0.02e+6,6.8e-7,'Kom.sk.zp');

axis([0 4500000 0 10e-7]); hold on;
title('       Vyrovnání skupinového zpoždìní pomocí fázovacích èlánkù 2 øádu');
xlabel('--> f[Hz]');
ylabel('--> t[s]');
grid;
hold off;

