Wp = 2*pi*5e3;  %31.4  % Passband and stopband edge frequencies, resp.
Ws = 2*pi*9.5e3; %59.7 
Rp = 2;         % Max passband ripple [dB]
Rs = 35;       % Min attenuation in stopband


% Chebyshev2
[n_cheb2,Ws_cheb2] = cheb2ord(Wp, Ws, Rp, Rs, 's')% Min order and cutoff freq Wn for analog Chebyshev2.


%% Chebyshev1
%%Zero-pole-gain form
[z,p,k] = cheby1(n_cheb1,Rp,Wn_cheb1,'s');
cheby1_poles = p;
figure
subplot(2,2,[1 3])
splane(z,p);grid on; axis square; title({'Poles on s-plane','Poles : ' length(p), 'Zeros : '  length(z)});xlabel Re; ylabel Im;
%% Polynomial-coefficients form
[b,a] = zp2tf(z,p,k);
[h,w]=freqs(b,a,100000);   
mag = abs(h);
phase = angle(h);
phasedeg = phase*180/pi;
%% Filter magnitude response
subplot(2,2,2)
semilogx(w, 20*log10(mag)), grid on
hold on
plot(Wp, -2, '*r'), plot(Ws, -35, '*b') % Verify that design parameters are met.
xlim([1e4 1e10])
xlabel 'Frequency (rad/s)', ylabel 'Magnitude [dB]'
subplot(2,2,4)
semilogx(w,phasedeg), grid on
xlabel 'Frequency (rad/s)', ylabel 'Phase (degrees)'
hold off
sgtitle 'Chebyshev1'

figure_configuration_IEEE_standard
figure 
xlim([1e4 1e10])
semilogx(w, 20*log10(mag), 'k'), grid on
hold on
xlabel 'Frequency (rad/s)', ylabel 'Magnitude [dB]'
%plot(Wp, -2, '*r'), plot(Ws, -35, '*r') % Verify that design parameters are met.
plot([1e3 Wp],[-Rp -Rp], '--k')
plot([Wp Wp],[-Rp -60], '--k')

plot([Ws 1e5],[-Rs -Rs], '--k')
plot([Ws Ws],[0 -Rs], '--k')