필터 지우기
필터 지우기

What is different between FFT and SHIFTFFT

조회 수: 23 (최근 30일)
University
University 2023년 10월 30일
댓글: University 2023년 11월 2일
Please can someone explain why this code :
fftshift(fft((x - mean(x)).*hann(L), NFFT)/sum(hann(L)))
is better than
fftshift(fft(x))?
Why not fftshift(fft(x))?
Why subtracting mean(x) from fftshift(fft(x))?
From matlab documentation Hann returns an L-point symmetric Hann window. Please does this mean?
Why sum(hann(L)) ? Why not hann(L)?
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 10월 30일
Subtracting the mean gets you an fft() in which the first bin is 0 . But it is not clear that is productive since hann() starts with a 0.
sum(hann(L)) appears to be (L-1)/2 for L > 2 -- for L = 2 exactly the "0 at the end" rule takes precidence. For L = 1 exactly hann() is 1 .
University
University 2023년 11월 2일
Thank you for this

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

채택된 답변

Chunru
Chunru 2023년 10월 31일
First, it is not correct to say which is better unless you define what is "better". fft(x) has better resolution but higher sidelobe levels than fft(x.*hann(L)).
The substraction of mean(x) from x is to remove the DC component so that the spectrum has 0 (approximately) at 0 frequency.
fftshift is to re-arrange the frequency axis. fft alone has frequency from 0-fs. fftshift has frequency range of (-fs/2, fs/2).
Division by sum(hann(L)) is a normalization factor. With this normalization a unit amplitude signal exp(2i*pi*f) will have a unit spectrum value:
f0 = 1/4;
L = 512;
w = hann(L);
x = exp(2i*pi*f0*(0:L-1)'); % unit amplitude
y = fft(x.*w./sum(w)); % unit spectrum at f0
plot(abs(y))
To recap:
Why not fftshift(fft(x))? ==> You can use it if you don't mind the side lobe level.
Why subtracting mean(x) from fftshift(fft(x))? ==> To remove DC from the signal and spectrum.
From matlab documentation Hann returns an L-point symmetric Hann window. ==> Normalization factor
  댓글 수: 3
Chunru
Chunru 2023년 10월 31일
편집: Chunru 2023년 10월 31일
It seems there is a confusion here. Even the hanning window has 0 for t=0 (assuming L>>1). Multiply x(t) with h(t) will make a modified signal s(t)=x(t)*w(t) and s(t=0)=0. But this will not make F(f=0)=0 in general.
However, subtracting mean, i.e. x(t)-mean(x) will ensure its Fourier Transform has 0 (up to round-off error) amplitude for DC (ie first bin). So it DOES matter to substract mean if one wants to remove DC, whether h(0)=0 or not. See the illustration below (paying attention to DC component).
==> combination fft(x) .* hann(L) then the result is going to be the same (to within round-off error) as fft(x-mean(x)) .* hann(L)
Note that we are concerned with time domain window, x.*h, instead of frequency domain window fft(x).*h.
fftshift(fft( (x - mean(x)) .*hann(L), NFFT)/sum(hann(L)))
The above is a time domain window instead of freq domain window.
f0 = 1/4;
L = 512;
w = hann(L);
x = exp(2i*pi*f0*(0:L-1)') + 1; % unit amplitude
y = fft(x.*w./sum(w)); % unit spectrum at f0
subplot(121)
plot(abs(y)); title('With DC')
y1= fft((x-mean(x)).*w./sum(w));
subplot(122)
plot(abs(y1)); title('DC Removed')
University
University 2023년 11월 2일
Thnak you so much. Your explanation really helped

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spectral Measurements에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by