From: Denis on 28 Jul 2010 04:51 "Jos " <j.g.h.haarman(a)student.utwente.nl> wrote in message <i2okji$7k1$1(a)fred.mathworks.com>... > Walter Roberson <roberson(a)hushmail.com> wrote in message <bxD3o.44134$f_3.42154(a)newsfe17.iad>... > > Jos wrote: > > > I still got a question concerning the fft. > > > Is it correct if I apply the following lines? > > > > > nfft = 2^^nextpow2(length(H)); > > > Pxx = abs(fft(H,nfft)).^2/length(H); > > > > Matlab does not have a ^^ operator. > > > > The result of nextpow2 is already a power of 2. It is not clear why you > > would want to take 2 to that value. > > Typo. Should be; nfft = 2^nextpow2(length(H)). > > At this moment I cannot give you an answer to the question why I'm taking 2 to that value, I'll get back on you, but as far as I know, this is common. This is due to the fact that FFT is faster if you use NFFT with a number of 2^[1...n]. For example: 2^15, 2^16, etc. Normally it would be a basic idea to make DFT for each point in your time value. Lets say you have 100 values (y) as a time signal. This would lead to fft(y, 100). But because of this NFFT value "restriction" it is better to have a value like 2^7 (=128) instead of 100. This is the only reason. Advanced: If your timesignal is only 100 values long then fft(y, 128) would pad your timesignal with zeros. Bye.
From: Walter Roberson on 28 Jul 2010 10:36 Denis wrote: > "Jos " <j.g.h.haarman(a)student.utwente.nl> wrote in message > <i2okji$7k1$1(a)fred.mathworks.com>... >> Walter Roberson <roberson(a)hushmail.com> wrote in message >> <bxD3o.44134$f_3.42154(a)newsfe17.iad>... >> > Jos wrote: >> > > I still got a question concerning the fft. >> > > Is it correct if I apply the following lines? >> > > > nfft = 2^^nextpow2(length(H)); >> > > Pxx = abs(fft(H,nfft)).^2/length(H); >> > > Matlab does not have a ^^ operator. >> > > The result of nextpow2 is already a power of 2. It is not clear >> why you > would want to take 2 to that value. >> >> Typo. Should be; nfft = 2^nextpow2(length(H)). >> >> At this moment I cannot give you an answer to the question why I'm >> taking 2 to that value, I'll get back on you, but as far as I know, >> this is common. > > > This is due to the fact that FFT is faster if you use NFFT with a number > of 2^[1...n]. For example: > > 2^15, 2^16, etc. Grrr, documentation of nextpow2() is not well written!
From: Wayne King on 28 Jul 2010 10:56 Walter Roberson <roberson(a)hushmail.com> wrote in message <EfX3o.2330$F%7.1952(a)newsfe10.iad>... > Denis wrote: > > "Jos " <j.g.h.haarman(a)student.utwente.nl> wrote in message > > <i2okji$7k1$1(a)fred.mathworks.com>... > >> Walter Roberson <roberson(a)hushmail.com> wrote in message > >> <bxD3o.44134$f_3.42154(a)newsfe17.iad>... > >> > Jos wrote: > >> > > I still got a question concerning the fft. > >> > > Is it correct if I apply the following lines? > >> > > > nfft = 2^^nextpow2(length(H)); > >> > > Pxx = abs(fft(H,nfft)).^2/length(H); > >> > > Matlab does not have a ^^ operator. > >> > > The result of nextpow2 is already a power of 2. It is not clear > >> why you > would want to take 2 to that value. > >> > >> Typo. Should be; nfft = 2^nextpow2(length(H)). > >> > >> At this moment I cannot give you an answer to the question why I'm > >> taking 2 to that value, I'll get back on you, but as far as I know, > >> this is common. > > > > > > This is due to the fact that FFT is faster if you use NFFT with a number > > of 2^[1...n]. For example: > > > > 2^15, 2^16, etc. > > Grrr, documentation of nextpow2() is not well written! Hi Walter, what don't you like about it? Wayne
From: Walter Roberson on 30 Jul 2010 13:07 Wayne King wrote: >> Grrr, documentation of nextpow2() is not well written! > Hi Walter, what don't you like about it? It says, "p = nextpow2(A) returns the smallest power of two that is greater than or equal to the absolute value of A" Let us take A=5 as an example. The smallest power of 2 that is greater than or equal to 5 is 8, so by that description the function should return 8 directly, not 3. If someone were to argue that in this case 8 would not be the *power* of 2, then the argument would fail because if you are talking about exponents, since 5 itself is a value that is greater than or equal to the absolute value of 5, the value returned would have to be 5. Likewise if the input were 5.813 then if the "power" refers to exponents, since 5.813 is greater than or equal to the absolute value of 5.813, then the return value for that case would have to be 5.813, and the function would under that interpretation be identical to abs(A) . The textual description confuses the exponent and the result of taking 2 to the exponent. Neither the textual description nor the formula do not restrict the return values to be integers. And nothing in the text or formula prepares for the fact that nextpow2(0) returns 0 rather than -inf or -1074 (denormalized) or -1022 (normalized numbers). After all, nextpow2(1/1024) does return -10 and 2^(-10) > 0 and -10 < 0, so clearly 0 cannot be a correct result for "the smallest" value such that 2 to the value is greater than or equal to the absolute value of 0. The documentation would also benefit from an explicit example showing a negative result. In every case other than 0, the return value of the function is ceil(log2(abs(A)) If that formula is used, the return value for A = 0 would be -Inf which would be a more consistent value than 0!
From: Steven_Lord on 3 Aug 2010 15:54
"Walter Roberson" <roberson(a)hushmail.com> wrote in message news:qFD4o.38398$lS1.17175(a)newsfe12.iad... > Wayne King wrote: > >>> Grrr, documentation of nextpow2() is not well written! > >> Hi Walter, what don't you like about it? > > It says, *snip* Thanks for the explanation of what you found confusing or unhelpful, Walter. I've sent this feedback to the documentation staff for consideration. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com |