%Introduction to Complex Impedance

w_hz=logspace(-3,3); %Create vector of frequencies
w=w_hz*(2*pi);       %Convert to rad/s

%Resistor and Capacitor values
R1=30000;
C1=10*10^-6;

%%% low pass filter topology
Z1 = R1;             %%% impedance 1
Z2 = 1./(1j*w*C1);   %%% impedance 2

LP  =  Z2./(Z1+Z2);   %% Solution for the low pass filter using complex amplitude
A   = abs(LP);        %% magnitude of complex #
phi = angle(LP);      %% angle in radians

subplot(211)
semilogx(w_hz,20*log10(A),'b')
ylabel('Magnitude [dB]')

subplot(212)
semilogx(w_hz,phi*(180/pi),'b') %using the function "angle" gives the
ylabel('Phase [deg]')
xlabel('Frequency [Hz]')
