%% =================================================================
%% DIPOLOS EQUIVALENTES CON UN ÚNICO CERO
%% =================================================================

clear;
clf;

W = -pi:pi/100:pi; % vector frec. ang. dig.
Z = exp(-1i*W);    % vector Z para evaluar H(Z)

% Ingresando a,b:
a  = 2;
b  = 1;
H1 = a + b*Z;
H2 = conj(b) + conj(a)*Z;

% Ingresando Z0:
Z0 = -2;
H1 =  Z - Z0;
H2 = -conj(Z0)*(Z-1/conj(Z0)); 

% Calculo espectros
AMP1 = abs(H1);
FAS1 = -angle(H1);
AMP2 = abs(H2);
FAS2 = -angle(H2);

% Preparo los tics para los gráficos
xt         = -pi:pi/2:pi;
xtlabel    = ['{/Symbol -p}';'{/Symbol -p/2}';'0';'{/Symbol p/2}';'{/Symbol p}'];
ytAMP      = 0:4;
ytFAS      = -pi:pi:pi;
ytFASlabel = ['{/Symbol -p}';'0';'{/Symbol p}'];

subplot(2,2,1)
plot(W,AMP1,'b-')
title('H_1(Z) = a + bZ')
ylabel('Espectro de amplitud')
axis([-pi pi 0 4])
set(gca,"xtick",xt,"xticklabel",xtlabel,"ytick",ytAMP);

subplot(2,2,2)
plot(W,AMP2,'r-')
title('H_2(Z) = b^* + a^*Z')
axis([-pi pi 0 4])
set(gca,"xtick",xt,"xticklabel",xtlabel,"ytick",ytAMP);

subplot(2,2,3)
plot(W,FAS1,'b-')
xlabel('Frecuencia')
ylabel('Espectro de fase')
axis([-pi pi -pi pi])
set(gca,"xtick",xt,"xticklabel",xtlabel,"ytick",ytFAS,"yticklabel",ytFASlabel);

subplot(2,2,4)
plot(W,FAS2,'r-')
xlabel('Frecuencia')
axis([-pi pi -pi pi])
set(gca,"xtick",xt,"xticklabel",xtlabel,"ytick",ytFAS,"yticklabel",ytFASlabel);

%print('dipolos_eqv.eps','-depsc'); % guardo el gráfico
