- Dividing the spectra by the sum of the window function (sum(w)) is a common practice in FFT calculations. This normalization is done to ensure that the amplitude values are consistent across different window lengths and types. By normalizing, the amplitudes are scaled relative to the window function, which helps in comparing different spectra. However, the choice of presenting the results in dB is subjective and depends on the context. If you prefer to present the amplitudes in linear units, you can skip the normalization step. The negative dB values you observe in the pwelch method are a result of the logarithmic scaling used in the conversion to dB. In the logarithmic scale, values below 0 dB are represented as negative dB values. It's important to note that the negative dB values do not indicate negative amplitudes but rather lower amplitudes relative to the reference level.
- The Short-Time Fourier Transform (STFT) is commonly used for analyzing non-stationary signals where time information is important. Since you mentioned that your signal is stationary and you don't require time information, using STFT may not be necessary in your case. The STFT provides a time-frequency representation by dividing the signal into short segments and calculating the FFT for each segment. If you only need the frequency domain information, using a regular FFT may be more appropriate and computationally efficient.
- To obtain a smoother line in the frequency domain, you can average the results from the STFT or FFT. This averaging can be done by taking multiple segments of the signal and calculating the FFT or STFT for each segment. Then, you can average the spectra across these segments to obtain a smoother representation. Averaging helps to reduce the effects of random variations and noise, providing a more reliable estimate of the underlying frequency content.
- The pwelch function is called with the input signal acc_MEMS1, the Hanning window w, the overlap length (wlen-hop), the number of FFT points nfft, and the sampling frequency fs_m.
- The output includes the power spectral density (Sxx) and the corresponding frequency values (f_welch).
- The absolute value of Sxx is calculated (abs_Sxx).
- The magnitudes of the positive frequencies up to nfft/2+1 are extracted (abs_mag).
- The magnitudes are converted to dB using the formula 20*log10(abs_Sxx) to obtain SxxdB.
- The stft function is called with the input signal acc_MEMS1, the sampling frequency fs_m, and additional parameters including the Hanning window w, the overlap length (wlen-hop), and the number of FFT points nfft.
- The STFT function divides the input signal into overlapping segments of length wlen with the specified overlap.
- The Hanning window is applied to each segment.
- The FFT is performed on each windowed segment to obtain the frequency spectrum for that segment.
- The resulting spectra for each segment are stored in s.
- The corresponding frequency values are stored in f, and the time values are stored in t.
- The function fft_analysis_Hann is called with parameters including the number of samples (Nsamples1), the time vector (timeVector1), the input signal acc_MEMS1, and the sampling frequency fs_m.
- Inside the function, the number of samples is checked to ensure it is even. If it is not, the last sample is removed.
- A Hanning window of length N is created.
- The frequency values for the FFT output are calculated using f_accH.
- The input signal is multiplied by the Hanning window to apply the windowing.
- The FFT is performed on the windowed signal, and the resulting spectrum is stored in fft_y_komp.
- The amplitude spectrum is normalized by dividing it by the sum of the Hanning window.
- The absolute value of fft_y_komp is calculated to obtain the windowed spectrum (abs_hwindow).
- The magnitudes of the positive frequencies up to N/2+1 are extracted and stored in fft_y_Hann.
- The magnitudes are converted to dB using the formula 20*log10(fft_y_Hann) to obtain fft_y_HanndB.