FFT spectral leak?

23 views (last 30 days)
Yi-xiao Liu
Yi-xiao Liu on 9 Nov 2022
Commented: Yi-xiao Liu on 10 Nov 2022
I find that in the power spectrum returned by fft the amplitude of peaks are much smaller than expected, even for artifical signals. This is in contrast to the examples given in documation
I wonder what can be done to improve? Increasing sampling rate seem to have very little effect.
%should make peaks at 70 and 300 with amplitude of 1 and 2
function [omega,P1]=fft1D(t,x)
xfft = fft(x);
P2 = abs(xfft/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
omega = Fs*(0:(L/2))/L*2*pi;
  1 Comment
Marcel Kreuzberg
Marcel Kreuzberg on 9 Nov 2022
in the example 'matlab/FFTOfNoisySignalExample' the intervall parameters are defined first.
if you play in your example with the line t=linspace(0,10,1e4) you will get different peak values as the fft is not the exact analytic result

Sign in to comment.

Accepted Answer

Mathieu NOE
Mathieu NOE on 9 Nov 2022
the amplitude accuracy depends if your signal frequency matches or not the fft frequency vector bins . If not your estimated amplitudes will be slghtly off, depending of the frequency mismatch between fft bins and actual signal frequency and also what king of window you are using (or none).
you can play with example below to see the effects (mismatch, window)
to make it simple I choose fs = samples = 500 so df = 1 Hz.
if your signals have integer frequencies, amplitudes are exact , if not... see by yourself and try with hanning window for improved amplitude computation.
samples = 500;
dt = 2e-3; % fs = 500 Hz
x=1*cos(2*pi*40*t)+2*cos(2*pi*70*t); % case 1 : signal frequencies are exact match with fft bins (fft freq points are separated by df = fs/nfft and nfft = samples)
% x=1*cos(2*pi*40.2*t)+2*cos(2*pi*70.3*t); % case 2 : signal frequencies are not exact match with fft bins
% FFT plot
[f1,fft_spectrum1] = do_fft(t,x);
title('Scheme 1')
function [freq_vector,fft_spectrum] = do_fft(time,data)
time = time(:);
data = data(:);
dt = mean(diff(time));
Fs = 1/dt;
nfft = length(data); % maximise freq resolution => nfft equals signal length
%% use windowing or not at your conveniance
% no window
fft_spectrum = abs(fft(data))*2/nfft;
% % hanning window
% window = hanning(nfft);
% window = window(:);
% fft_spectrum = abs(fft(data.*window))*4/nfft;
% one sidded fft spectrum % Select first half
if rem(nfft,2) % nfft odd
select = (1:(nfft+1)/2)';
select = (1:nfft/2+1)';
fft_spectrum = fft_spectrum(select,:);
freq_vector = (select - 1)*Fs/nfft;
Yi-xiao Liu
Yi-xiao Liu on 10 Nov 2022
Yes, many of them compare different window in terms of spectral accuracy and amplitude accuracy.
I wonder, however, why don't people use uniform window (no window) to identify frequencies first then flat top to determine the amplitude of these frequencies to get the best of both worlds?

Sign in to comment.

More Answers (0)





Community Treasure Hunt

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

Start Hunting!