# correct way for Zero padding

I am doing simulation of FMCW radar. I am applying signal processing chain on raw radar data. Here in the code below, I am taking fft of data and plotting it. Moreover, I am doing zero padding by multiplying the signal length by 1000. I should be getting beat frequency at 2.020 MHz instead I am getting at 2.019MHz. There is something little probelem but I do not know what.

Is it the correct way for Zero padding? Moreover, am I defining frequency axes correctly? Thanks everyone in advance

% second-order butterworth
[b, a] = butter(2, [w1 w2], 'bandpass');

x = fb2030(30,:);
% filtering
y_filt = filter(b,a,x);                           % filtering the received signal
nfft = length(y_filt)*1000;                       %%%% Zero Padding
res = fft(y_filt,nfft)/ nfft;                     % normalizing the fft

f = fs/2*linspace(0,1,nfft/2+1);                  % choosing correct frequency axes
res = res(1:nfft/2+1);                            % amplitude of fft(taking the half length of nfft)
figure,plot(f,2*abs(res));
xlabel('Frequency in MHz');ylabel('amp')

• Nothing looks obviously wrong. You should elaborate on "not getting the desired output." – Jason R Aug 31 '15 at 12:10
• Thanks Jason for your answer. I mean, I am applying fft on radar data. At the end, I shoud be getting beat frequency at 2.020MHz instead I am getting at 2.019MHz. Therefore, i am thinking that may be I am applying zero padding wrong or defining wrong frequency axes. – Urban_Yogi Aug 31 '15 at 13:20
• @Urban_Yogi I think you should include this info into your question. This will help giving a better answer to your question. – Gilles Aug 31 '15 at 14:01
• Done @ Gilles. Thansk for your comment. – Urban_Yogi Aug 31 '15 at 14:32

This line seems suspicious to me:

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


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

so

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

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

• Or you meant $f_{{\tt nfft}/2 + 1} = \frac{f_s}{2} + \frac{f_s}{\tt nfft}$ ? And I think the choice of linspace is on purpose so as to only have a single side amplitude spectrum. – Gilles Aug 31 '15 at 15:03
• ahh ok. let me try. Thanks for your answer Peter K. – Urban_Yogi Aug 31 '15 at 15:04
• @Gilles: Yes, I have corrected my typo. Linspace is OK, but the range is wrong. And the range being wrong will mean the frequencies being plotted are wrong. – Peter K. Aug 31 '15 at 15:05
• @PeterK. The remaining range from $\frac{f_s}{2}$ to $f_s$ is an image of what is already from $0$ to $\frac{f_s}{2}$. I don't think this will help solve his problem. – Gilles Aug 31 '15 at 15:11
• That's the trouble: He's NOT doing 0 to $f_s/2$. He's doing 0 to $f_s/2 + f_s/{\tt nfft}$. So he's including part of the range from $f_s/2$ to $f_s$ in what he thinks is 0 to $f_s/2$. – Peter K. Aug 31 '15 at 16:04