# How to properly take the one-sided fft in MATLAB?

조회 수: 82 (최근 30일)
L'O.G. 2022년 3월 22일
댓글: Star Strider 2022년 3월 22일
My understanding is that MATLAB's fft() function takes the two-sided FFT, and that the one-sided FFT has only positive frequency components and twice the amplitude of the two-sided FFT. I want the latter one here and then to take the real and imaginary components. So here are my questions to make sure I understand this because I don't want to do this without understanding it:
1. Why the form of fix() here? Should it be length(nfft) or length(f_t)? I have seen both used in examples.
2. Is the form of f_w correct (i.e., divide by length(f_t) and multiply by 2 to take the one-sided transform? If so, why divide by the length?
3. To take the real and imaginary components in this case, should I take the absolute value or take them as is? Taking them as is results in a negative value for the imaginary component in my case, which I don't understand.
t = linspace(0.01,100,10000);
nfft = 2^nextpow2(length(f_t));
dt = t(2) - t(1);
df = 1/dt;
Frequency = (df/2)*linspace(0,1,fix(length(f_t)/2)+1);
f_w = 2*ffft(f_t,nfft)/length(f_t);
Real_fw = real(f_w);
Imag_fw = imag(f_w);

댓글을 달려면 로그인하십시오.

### 채택된 답변

Star Strider 2022년 3월 22일
There appears to be missing information (specifically ‘G_t’ and ‘f_t’), so running the code is not possible.
Otherwise:
Frequency = (df/2)*linspace(0,1,fix(length(f_t)/2)+1); % why the form of fix() here?
The fix call is only necessary if ‘f_t’ has an odd number of elements, because the third argument to linspace must be an integer. Since this code snippet uses :
nfft = 2^nextpow2(length(G_t));
the length will always be even and the ‘Frequency’ vector can be wrritten:
Frequency = (df/2)*linspace(0,1,nfft/2+1);
Also, I have seen in some cases people divie the output of fft() by the length of the signal. Why is that done?
That is the recommended approach. It normalises the fft result by the length of the original time-domain vector length. The Fourier transform calculates the integral of the time domain signal, and dividing it by the length of the signal restores the correct amplitudes.
Finally, could somebody please explain the purpose behind line 2 defining nfft, and line 5 with the Nyquist criterion?
The nextpow2 function returns the first power of 2 that is larger than the argument, not the actual value for the length. The ‘2^’ converts it from that to the desired length of the fft.
.
##### 댓글 수: 4이전 댓글 2개 표시이전 댓글 2개 숨기기
L'O.G. 2022년 3월 22일
Thank you very much! I appreciate you walking me through this so that I can understand.
Star Strider 2022년 3월 22일
As always, my pleasure!
None of this is necessarily straightforward, and it takes time to appreciate all the complexities.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Fourier Analysis and Filtering에 대해 자세히 알아보기

R2021b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by