Differences between FFT methods
Show older comments
Hello everyone, I have been trying some different methods for computing the FFT of some accelerometer data I collected. The first method is a regular FFT with an Hamming window across all samples. The second and third methods are the STFT and welch method with the parameters that you can see below. Since these methods have differences in the way they perform the calculations, I was expecting some variation of the results. However, it appears that these are two big. I have to present these results and want to know which is the best method. I was wondering if anyone could help me better understand what is actually happening that causes these differences:
1 - Should I be diving the spectra by sum(w), honestly just saw that it was a good practice in FFT calculations so I am doing it. But to be honest it doesn't make much sense to me to present the results in -dB, so I'm not so sure about that. SInce this is vibration data wouldn't it make more sense that the peaks are, for example, 60dB, 100dB and so on? If I don't normalize the results (divide by sum(w)) the amplitudes increase but the pwelch method still has values below 0dB, which I don't understand as well.
2 - My signal is stationary, does it make sense to be using the STFT in such situation since I don't need time information?
3 - How could I average the results from the STFT or FFT to get a more smooth line like in the pwelch method?
I am trying to fully understand what happens in the background of these calculations and would be glad to have some insights from more experienced people on the topic. Thank you very much in advance.
% Signal Parameters
fs_m = 26700; % Sampling Frequency (MEMS)
Nsamples1 = 775862; % Number of Samples
% Window parameters
wlen = 2^14; % Window length (recommended to be power of two)
nfft = 2*wlen; % Number of fft points
overlap = 0.50; % Defining overlap as 75%
hop = wlen * (1-overlap); % Hop size
w = hanning(wlen, 'periodic'); % Hanning window
% Testing pwelch method [Pxx,F] = pwelch(X,WINDOW,NOVERLAP,NFFT,Fs)
[Sxx,f_welch] = pwelch(acc_MEMS1, w, wlen-hop, nfft, fs_m); % single-sided PSD
abs_Sxx = abs(Sxx);
abs_mag = 2*abs_Sxx(1:nfft/2+1);
SxxdB = 20*log10(abs_Sxx);
% Perform STFT
[s, f, t] = stft(acc_MEMS1, fs_m, "Window", w, "OverlapLength", wlen-hop, "FFTLength", nfft);
% Filter out frequencies less than 0
positive_f = f >= 0; f_pos = f(positive_f,:); s_positive = s(positive_f, :);
sf_w = s_positive/sum(w);
% sf_w = s_positive;
abs_sf = abs(sf_w); avg_mag_s = 2*abs_sf(1:nfft/2+1); avg_mag_sdB = 20*log10(avg_mag_s);
% FFT
[fft_y_Hann, fft_y_AccH] = fft_analysis_Hann(Nsamples1, timeVector1, acc_MEMS1, fs_m);
%% Inside the function fft_analysis_Hann
if mod(N,2)~=0 % da Berechnungsformeln nur mit N/2 integer ohne Warnung funktioniren (letzten Wert abschneiden)
N = N-1;
t = t(1:end-1);
y = y(1:end-1);
end
w = hanning(N); % Hanning window
f_accH =(0:(N/2))*f_s/N; % only frequency >0
y_window = y(:).*w(:);
fft_y_komp = fft(y_window)/sum(w); % Normalization of the Amplitude
% fft_y_komp = fft(y_window); % No normalization
abs_hwindow = abs(fft_y_komp); % Window
fft_y_Hann = 2*abs_hwindow(1:N/2+1);
%% End of the function
fft_y_HanndB = 20*log10(fft_y_Hann);
% FREQUENCIES OF INTEREST
fdesM = 3000; fdesP = fdesM;
%Plot
f1 = figure('Name', 'Measurement Results');
plot(fft_y_AccH, fft_y_HanndB, 'Color', [0.169 0.169 0.169 0.8], 'LineStyle', ':', 'LineWidth', 0.8); xlabel("Frequency"); ylabel("Amplitude (dB)"); pbaspect([4 1 1])
hold on;
plot(f_pos, avg_mag_sdB, 'Color', [1 0 0 0.6], 'LineStyle', '-', 'LineWidth', 1.2); xlabel("Frequency (Hz"); ylabel("Amplitude (dB)"); title("Frequency Domain Comparison Measurement N°1"); xticks(0:60:fdesM); xlim([0 fdesP]);
pbaspect([4 1 1]);
plot(f_welch, SxxdB, 'Color', [0 0 1 0.6], 'LineStyle', '-', 'LineWidth', 1.2); xlabel("Frequency (Hz"); ylabel("Amplitude (dB)"); title("Frequency Domain Comparison Measurement N°1"); xticks(0:60:fdesM); xlim([0 fdesP]);
pbaspect([4 1 1]); legend('Regular FFT', 'STFT', 'Welch Method')
hold off;

Accepted Answer
More Answers (0)
Categories
Find more on Spectral Estimation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!