I need to analyze a real-valued time signal with a length of 300000 in the frequency domain. The sampling frequency is 100000Hz. In order to
increase the signal-to-noise ratio reduce the "fine-grain" fluctuation when your number of bins is too large I decided to split the whole signal in smaller blocks, calculate the FFT of the smaller blocks and average the spectra. I used Gnu Octave to implement this:
function A = fft_average(x, win_length, samp_freq) %overlapping samples step = win_length / 2; % calculate frequency range freq = 0:1/win_length*samp_freq:(win_length-1)/win_length*samp_freq; %fft_win = ones(win_length,1); %fft_win = hanning(win_length); %fft_win = hamming(win_length); fft_win = blackman(win_length); y = zeros(win_length,1); start = 1; stop = win_length; nsteps = 0; while (stop <= length(x)) nsteps = nsteps + 1; ytemp = abs(fft(x(start:stop).*fft_win)); start = start + step; stop = stop + step; % add (and scale) y = y + ytemp; end % average y = y./(nsteps); %copy to result array, omit negative frequencies A(:,1) = freq(1:win_length/2); A(:,2) = y(1:win_length/2); endfunction
Here are the results with 3 different block sizes of 1024, 4096 and 16384. Additionally, I tried 4 different window functions. I only post results for rectangle and Hann Window due to lack of reputation.
I did not apply any scaling to the amplitudes yet. What I would expect from a correct scaling is consistency of the results for different block sizes. Hence no offset like in the second image for the Hann window. If I scaled the amplitudes by the square root of the block size, the results for the Hann-windowed FFTs match. But I have 3 problems with this approach:
- What would be the mathematical foundation to scale by the square root of the block size? Or is it the square root of the block size because I made an obvious mistake?
- The amplitudes for the rectangle window do not match if I apply this scaling. Is this rather caused by spectral leakage?
- Do I have to apply an additional scaling to account for the shape of the window function, i.e. so the integral remains the same?