%Describing function for an AFM in tapping mode
% kja 070505
aminit					% MATLAB initialization

% Parameter definitions normalized for with the frequency z*w0
% renormalized in plot
z=0.002;                % Relative damping 
n=20;                   % Number of periods for averaging
Tn=2*pi*n*z; 
N=10000;
%Pure integrating control
kipure=1/(2+Tn)

% Normalized averaging time

%Transfer function
w=logspace(-2,2,N);
one=ones(size(w));
s=i*w;
P='(1-exp(-s*Tn))./(s.*Tn.*(s+1))'
Pv=eval(P);

%Inverse describing function
xx=-0.3:0.01:0;
yy=-0.2*ones(size(xx));

%Nyquist plot
figure(1); clf; subplot(221);
pl=plot(real(Pv),imag(Pv), 'b-',xx,yy,'b--');
set(pl,'LineWidth', AM_data_linewidth);
xlabel('real');ylabel('imag');hold on
axis([-0.3 0.3 -0.5 0.1]);axis square;
text(0.1,-0.3,'L');
text(-0.15,-0.25,'N');