%% Lesson 6x: the S-plane
% If you happen to have an analog filter represented as a ratio of polynomials,
% MATLAB can analyze that too! `freqs()` will give you the analog frequency
% response evaluated at frequencies in the given vector, interpreted in rad/s.

%% a simple example
% What sort of filter is this?
a = [1 0.4 1];
b = [0.2 0.3 1];

w = logspace(-1, 1);
H = freqs(b, a, w);

Hdb = 20*log10(abs(H));
Hph = rad2deg(unwrap(angle(H)));

figure;
subplot(2, 1, 1);
semilogx(w, Hdb);
xlabel("Frequency (rad/s)");
ylabel("|H| (dB)");
title("Magnitude Response");

subplot(2, 1, 2);
semilogx(w, Hph);
xlabel("Frequency (rad/s)");
ylabel("Phase (deg)");
title("Phase Response");

%% some notes
% `zp2tf` and its associates also work in the analog domain, as they deal
% simply with  ratios of polynomials. The interpretation of the results will be
% different, though, as we're working with the *analog* plane rather than the
% digital one. `splane.m` gives an example visualization of the s-plane.
[z, p, k] = tf2zp(b, a);
figure;
splane(z, p);
