I have an input signal in the ( 0 - 20 kHz ) frequency range . When i sample this signal maximum sampling frequency is around 40 kHz . When i calculate the FFT using 1024 points i got resolution of 39 Hz ( resolution = fs/N) . But i need a resolution of 5 Hz . How can i get better resolution?
People interpret the term "resolution" more than one way. One way is the ability to separate closely spaced frequency lines, and another is to estimate the the "true" frequency of a single tone. Most DFT interpolators fall into the true value of a tone category. The problems are not independent of each other but you should understand the problem you are trying to solve.
There is more than one way to interpolate intermediate frequencies from the DFT.
From Peter K's web page, the Fourier Coefficient section links to a survey prepared by Eric Jacobsen.
which is a complex interpolator with good result
The basic idea is that there is a largest bin that contains the frequency of interest and the bin leakage is asymmetric. One uses a "fit" to some formula as an interpolation. THis implies that you need a nominal "high" SNR, and a few bins of separation. Macleod's technique assumes that you used a boxcar window which can be a problem where the noise is far from flat.
You might want to post plots for your problem for further advice.
The other categories on Peter K's page are also worth looking at.
The resolution of a FFT can be described as FS/N , where FS is the sampling frequency and N is number of points. If you want more resolution in your case just take aquire more data before running FFT function.. 40k/8192 gives ~5Hz per bin.