What is different between FFT and SHIFTFFT

26 ビュー (過去 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 Center および File ExchangeTransforms についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by