x=x-0.0397; %shift for x axis (I neglect the first CC cycle as the system wouldn't have reached steady state yet)
yy1 = smooth(x,y,0.03,'loess'); % smoothing the curve to get better readability later. I'm aware this affects the total realized impedance.
figure
plot(x,y,x,yy1,'--')
legend('CCF','filtered CCF')
xlabel('time')
ylabel('V')
n=length(yy1);
z=fft(yy1)/n;
fs=10e3;
f=fs/2*linspace(0,1,n/2+1);
z=z(1:n/2+1);
R=real(z);
i=imag(z);
mag=abs(z);
phase=angle(z);
figure
plot(R,i)
ylabel('Imaginary');
xlabel('Real')
legend('Nyquist plot')
figure
subplot(2,1,1)
semilogx(f,mag)
legend('Magnitude')
xlabel('f')
ylabel('mag')
subplot(2,1,2)
semilogx(f,phase)
legend('Phase')
xlabel('f')
ylabel('degree')