Signal Processing Toolbox™ provides several functions to power spectrum estimation, including pspectrum and stft. Although these functions are excellent and well-documented, they might be cumbersome in some engineering applications. These applications include estimating magnitudes of vibration, noise and other discrete-time signals in engineering units or a comparison of theoretical results with measurements.
In such applications, you can use autofft, a Matlab function for estimation of the discrete Fourier transform (DFT) which mimics options of the Brüel & Kjaer FFT analysers. Based on your input, autoFFT segments signal, applies window functions and spectral averaging. The resulting DFT can be returned in various engineering spectral units including magnitude, RMS, peak-to-peak and power spectral density (PSD). autofft can also estimate spectral derivation or spectral integral of DFT and even perform the short-time Fourier transform (STFT).
Note that autoFFT requires the Signal Processing Toolbox in order to generate window functions and estimate PSD accurately.
If you have any suggestions and comments or if you want to report a bug, feel free to contact me via e-mail carlist(at)ntis.zcu.cz.
Lubos Smolik (2020). autofft - FFT analyzer (https://www.mathworks.com/matlabcentral/fileexchange/69534-autofft-fft-analyzer), MATLAB Central File Exchange. Retrieved .
fftset = struct('nwin', nfft, ... % Specifies the number of DFT points
'unit', 'psd'); % Specifies the spectral unit
[s, freq] = autfft(x, fs, fftset);
Note that if If nfft is less than the signal length, autofft behaves differently than periodogram because autofft averages result in the frequency domain rather than time domain.
For example, the input signal [1 2 3 4 5 6 7 8] with nfft equal to 4 results in the periodogram of sum([1 5; 2 6; 3 7; 4 8],2). However, it results in the averaged power spectral density from segments [1 2 3 4], [3 4 5 6], [5 6 7 8] in the case of autofft. The overlapping percentage of individual segments can be controlled with 'overlap' parameter.
Thanks for sharing, looks great!
One question please. What's params for this function to get an equivalent of "periodogram(x, , nfft, fs, 'psd', 'onesided');" ?
An optional highpass filtering has been implemented.
Overlap length (in samples) returned in output variable setup is now correct. Previous versions incorrectly returned overlap percentage.
An error occurring during estimation of autospectrum has been fixed.
- Improved documentation.
- User can define frequency resolution of the analyser.