clear all, hold off

N=1024;
t=[0:N-1]; f1=15.6/N;
x=cos(2*pi*f1*t+pi/6);
X=fft(x); plot(abs(X),'.'); hold on, shg
f=[0:N-1]/N; f2=[0:2*N-1]/2/N; x2=[x,zeros(1,N)];
X2=fft(x2); plot(f2,abs(X2),'.g'); shg
X=fft(x); plot(f,abs(X),'.b'); set(gca,'xlim',[12,22]/N); shg

M=100;
fM=[0:M*N-1]/M/N;
xM=[x,zeros(1,(M-1)*N)];
plot(fM,abs(fft(xM))), shg
plot([min(f2),max(f2)],[N/2,N/2],':b')
plot([f1,f1],[0,N/2],':b')

X3=X2(31:33);
a=[1,1,1;f2(31:33);f2(31:33).^2]'\X3.';
pf=[0.0145:0.01/N:0.016];
pX=polyval(flipud(a),pf);
plot(pf,abs(pX),'r'), shg
ylim([0,1000])

X3=X2(31:33);
a=[1,1,1;f2(31:33);f2(31:33).^2]'\abs(X3).';
pf=[0.0145:0.01/N:0.016];
pX=polyval(flipud(a),pf);
plot(pf,abs(pX),'g'), shg
[pXmax,ind]=max(abs(pX));
plot(pf(ind(1)),abs(pX(ind(1))),'+g'), shg
ylim([0,600])

hold off