Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to choose the points when using fft in Matlab?

Status
Not open for further replies.

triquent

Full Member level 3
Full Member level 3
Joined
Oct 13, 2004
Messages
166
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
1,826
matlab fft power of 2

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.
 

frequency resolution matlab

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.
 

    triquent

    Points: 2
    Helpful Answer Positive Rating
fft points + freq resolution

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.
 

using fft in matlab

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
 

fft points to frequency

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.
1 - "How to calculate the frequency resolution"
- 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?"

Always one bin width. If you want a plot vs hz, I would use freq=(0:19999)./2

"While for the default, Matlab uses 2^n=2^20000"
No, that is wrong. Matlab prefers a power of 2. For example 2^14~16000, But not 2^20000. You can use 20000 as disucssed above.

Note I have posted some example FFTs using MATLAB in the last post in the thread on DSP interview questions.
 

    triquent

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top