Impedance is always calculated as complex value, a magnitude with a phase value. The magnitude is the total equivalent resistance of the circuit and the phase angle shows whether current follows or leads the voltage signal.
For calculation of impedance we need two signals one is the voltage applied to the circuit and the next one is the current signal. This can be done in both digital or analog method.
We need to calculate the In-Phase component and Quadrature (90 deg Outofphase) component. This can be done by multiplication of sin component of the signal with it self to get the qudrature component and the cosine component with the signal to get the inphase component.
In analog systems we can achive the cosine part by phase shifting the signal and multiplication/dot product by modulators.
Magnitude=sqrroot((inphase component)^2+(Quadrature component)^2)