I am trying to calculate the cross-spectral density for a voltage signal using Matlab. I am using the fft function to do the Fourier transform. The fft function is Y=fft(X,n). But I donot know how to pick the points n. My voltage signal Y is 2seconds long. dt is 0.0001s. so sampling frequency is 1/0.0001s=10KHz. I donot know what value I should use for the fft in my case?
Anyone can help? Thanks.
Just put the whole point into the fft - it should take them and calculate the transform. In fact, if you don't support a number of points, equal to an axact power of 2 (2 powered of n) fft must add some points to receive it (the exact power of 2). You can do it youself, of course.
Thanks. I am still confused about how to choose the point is best. Can you explain why choose the exact point is OK? In my case, if I use the exact point, n=2second/0.0001s=20000points. While for the default, Matlab uses 2^n=2^20000. That's a huge difference. So which one is better? By what standard, I choose the points when using fft in Matlab?
BTW, two more questions? 1) how to calculate the frequency resolution? In my case, if I use the exact n=20000, freq resoluition is 1?
2) When I plot the psd vs freq? how can I convert back to the frequency for the x-axis? In my case, is it: freq=Fs*(0:n-1)/n=10000*(0 : 19999)/20000? so no matter which n i choose, the freq resolution is always 1?
dmk said:
Just put the whole point into the fft - it should take them and calculate the transform. In fact, if you don't support a number of points, equal to an axact power of 2 (2 powered of n) fft must add some points to receive it (the exact power of 2). You can do it youself, of course.
Well,
It's about the FFT and DFT. The answer is neither easy nor short. Anyway, the FFT is a DFT at power of 2 (so called butterflys). You must read something more about Digital Signal Processing, Discrete Forrier Transform and Fast Furrier Transform.
A good book is Steven Smith's "The Scientist and Engineer's Guide to DSP": https://www.dspguide.com/
You can download the chapters and read them.
Regards
The number of points is how long your vector X is. In your case 20000. You don't have to specify N. If your vector is not a multiple of 2, then the algorithm may not be particularly fast, but should still be accurate.
- the spacing between your FFT points will be 1/(2 seconds) = 0.5 hz. What you mean by resolution can be a little trickier.... have to think about whether your sample is windowed, whether two frequencies occur close together, whether there is noise.
2) "When I plot the psd vs freq? how can I convert back to the frequency for the x-axis? In my case, is it: freq=Fs*(0:n-1)/n=10000*(0 : 19999)/20000? so no matter which n i choose, the freq resolution is always 1?"