correct way for Zero padding
This line seems suspicious to me:

f = fs/2*linspace(0,1,nfft/2+1);  


Your frequency bins should be:

$$f_k = \frac{f_s}{\tt nfft} k$$

so 

$$ \begin{array}{rcl}
f_{{\tt nfft}/2 + 1} &amp;=&amp; \frac{f_s}{\tt nfft} ({\tt nfft}/2 + 1)\\
&amp;=&amp; \frac{f_s}{2} + \frac{f_s}{\tt nfft} 
\end{array}$$

whereas your linspace setting has it mapping to just $\frac{f_s}{2}$.