What is different between FFT and SHIFTFFT

16 次查看(过去 30 天)
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 .

请先登录,再进行评论。

采纳的回答

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