Frequency resolution using pwelch
Show older comments
Hi everyone,
i want to analyze the frequency domain of accelerometer data sets sampled at 500 kHz.

(figure: comparing different window-functions using pwelch with (in this case) windowlength=1024, nfft=1024, fs=500.000Hz, data length=100.000 samples)
When using the pwelch function in MATLAB i can use the windowlength (and a certain windowfunction of course) and the FFT-length as parameters affecting the frequency resolution. Looking at the figure above i'm facing two problems:
1) When changing these parameters in such way, that the frequency resolution is high i feel like it comes with high spectral leakage and therefore automatically becomes obsolete.
2) The system monitored with the accelerometer is a metal-to-metal contact, excited by a shock using a hammer. I am wondering why there is a peak at 0 Hz. In such systems i would expect high-frequency components rather than the spectrum seen in the figure.
Appreciate every help or idea on how to handle any of the two problems mentioned above!
Thanks in advance!
17 Comments
Mathieu NOE
on 17 May 2023
hello
do you have the possibility to measure the hamer force signal ? i am simply trying to figureout why we would not rather use a transfer function estimate (with tfestimate) rather than just the output spectrum ?
seems to me (IMHO) a better way to characterize a system unles the input is very stable and repetitive. But I also wonderwhy your spectrum can show narrow peaks and wide peaks at the same time. So measuring the force would eliminate spurious signals (EMI) if we could average the TF estimate over multiple hits
Oskar Kilgus
on 19 May 2023
Mathieu NOE
on 22 May 2023
hello again
can you share your data (hammer + response time signals) may be for several hits so we can average them ?
Oskar Kilgus
on 22 May 2023
Mathieu NOE
on 26 May 2023
I can make you a demo if you want to share some data
Oskar Kilgus
on 30 May 2023
Mathieu NOE
on 31 May 2023
here we go
you have the choice to use tfestimate or my equivalent function mytfe_and_coh
now I have to admit the time signals gave me some headache...
I see on the force signal a min pulse folowed by some ringing , sometimes another hit appears- are you using a force sensor or are you computing the force indirectly from some acceleration signal ?
the acceleration response signal shows sometimes like delayed replications , but I assume this comes not from the input itself but is a exogeneous perturbation
here your data , limited to the first 50,000 samples (far enough)
set 1

set 2

to avoid those issues I computed the FRFs using only the first 5000 samples
the two individual FRF from each data set are quite appart in term of magnitude. This is not something I usually see when I do modal analysis with hammer testing.
so yes you can get an averaged curve, and again, my experience is that normally each hit should generate more or less the same FRF plot; averaging make simply the result better looking (smoother)
the bode plot below I limited the x axis to 100 kHz, as it gets even worse above.

Code used so far :
load('example.mat');
samples = 5000; % restrict data to first valid samples
fs = 500000; % sampling frequency (Hz)
dt = 1/fs;
t = (0:samples-1)*dt;
fmax = 100e3; % must be < fs/2
% main loop
for set = 1:2
x = example{2,set}; %input
y = example{1,set}; %output
% restrict to first valid samples
x = x(1:samples);
y = y(1:samples);
figure
subplot(2,1,1),plot(t,x,'b')
title(['Set #' num2str(set)]);
xlabel('Time (s)')
ylabel('Force')
subplot(2,1,2),plot(t,y,'r')
title(['Set #' num2str(set)]);
xlabel('Time (s)')
ylabel('Acceleration')
% FFT parameters
NFFT = samples;
NOVERLAP = round(0*NFFT); % 0 percent overlap
%% solution 1 with tfestimate (requires Signal Processing Tbx)
[Txy,F] = tfestimate(x,y,ones(NFFT,1),NOVERLAP,NFFT,fs);
%% alternative with supplied sub function
% [Txy,Cxy,F] = mytfe_and_coh(x,y,NFFT,fs,ones(NFFT,1),NOVERLAP);
% Txy = transfer function (complex), Cxy = coherence, F = freq vector
% Bode plots
ind = (F>fmax);
F(ind) = [];
Txy(ind) = [];
figure,
subplot(2,1,1),semilogy(F,abs(Txy));
title(['FRF Set #' num2str(set)]);
xlabel('Frequency (Hz)');
ylabel('Mag');
subplot(2,1,2),plot(F,180/pi*(angle(Txy)));
xlabel('Frequency (Hz)');
ylabel('Phase (°)');
Txy_all(:,set) = Txy;
leg{set} = ['set #' num2str(set)];
end
% averaged Txy
Txy_avg = mean(Txy_all,2);
leg{set+1} = ['average'];
figure,
subplot(2,1,1),semilogy(F,abs(Txy_all),F,abs(Txy_avg),'k');
title('FRFs');
xlabel('Frequency (Hz)');
ylabel('Mag');
legend(leg);
subplot(2,1,2),plot(F,180/pi*(angle(Txy_all)),F,180/pi*(angle(Txy_avg)),'k');
xlabel('Frequency (Hz)');
ylabel('Phase (°)');
legend(leg);
% %%% damping ratioes for modes
% N = 2 ; % number of (dominant) modes to identify
% [fn,dr] = modalfit(Txy,F,fs,N,'FitMethod','pp');
% T = table((1:N)',fn,dr,'VariableNames',{'Mode','Frequency','Damping'})
%%%%%%%%%%%%%%%%%%%%%%%
function [Txy,Cxy,f] = mytfe_and_coh(x,y,nfft,Fs,window,noverlap)
% Transfer Function and Coherence Estimate
% compute PSD and CSD
window = window(:);
n = length(x); % Number of data points
nwind = length(window); % length of window
if n < nwind % zero-pad x , y if length is less than the window length
x(nwind)=0;
y(nwind)=0;
n=nwind;
end
x = x(:); % Make sure x is a column vector
y = y(:); % Make sure y is a column vector
k = fix((n-noverlap)/(nwind-noverlap)); % Number of windows
% (k = fix(n/nwind) for noverlap=0)
index = 1:nwind;
Pxx = zeros(nfft,1);
Pyy = zeros(nfft,1);
Pxy = zeros(nfft,1);
for i=1:k
xw = window.*x(index);
yw = window.*y(index);
index = index + (nwind - noverlap);
Xx = fft(xw,nfft);
Yy = fft(yw,nfft);
Xx2 = abs(Xx).^2;
Yy2 = abs(Yy).^2;
Xy2 = Yy.*conj(Xx);
Pxx = Pxx + Xx2;
Pyy = Pyy + Yy2;
Pxy = Pxy + Xy2;
end
% Select first half
if ~any(any(imag([x y])~=0)) % if x and y are not complex
if rem(nfft,2) % nfft odd
select = [1:(nfft+1)/2];
else
select = [1:nfft/2+1]; % include DC AND Nyquist
end
Pxx = Pxx(select);
Pyy = Pyy(select);
Pxy = Pxy(select);
else
select = 1:nfft;
end
Txy = Pxy ./ Pxx; % transfer function estimate
Cxy = (abs(Pxy).^2)./(Pxx.*Pyy); % coherence function estimate
f = (select - 1)'*Fs/nfft;
end
Oskar Kilgus
on 19 Jun 2023
Mathieu NOE
on 20 Jun 2023
hello again
can you describe a bit more your physical set up ?
I am not sure to understand where is placed the force sensor in your case
when I do FRF measurement on a piece of structure , the force sensor is in the hammer and the response sensor is a accelerometer glued on the structure
Oskar Kilgus
on 20 Jun 2023
Mathieu NOE
on 21 Jun 2023
you say :
its exactly like that. I do have a force sensor in the hammer and the acceleration is measured with a sensor glued on the structure.
then I don't understand what is this record and how you obtained that data

Oskar Kilgus
on 21 Jun 2023
Mathieu NOE
on 21 Jun 2023
your comment :
Shouldnt be the frequency spectrum of the FRF and that of another FFT/pwelch analysis be similar?
well we are comparing apples to oranges here
fft is the underlying "brick" for all frequency domain analysis of course
pwelch and alike are "single channel" fft operations that tells you about the spectral content of your signals. A hammer impact (pulse) should have a decaying fft amplitude as we move in the higher frequencies
FRF is a "dual channel" fft operations that computes cross and auto spectra from where you get the FRF estimate , but an FRF is not a spectrum as it has not relevance to a particuliar type of signal, it describes what is the magnitude / phase intrinsic characteristics of any device or structure from one input to one (or several) outputs.
FYI, there is lots of articles about modal analysis (with a hammer)
Mathieu NOE
on 21 Jun 2023
another good reference / reading :
Oskar Kilgus
on 22 Jun 2023
Mathieu NOE
on 23 Jun 2023
my pleasure
do no hesitate to come back when you have new data to share !
Answers (1)
Gokul Nath S J
on 23 May 2023
0 votes
Hi Oskar,
Changing the window length and FFT length in the pwelch function can impact the frequency resolution and spectral leakage of the resulting power spectral density (PSD) estimate. It is often a trade-off between these two factors, where increasing the window length improves the frequency resolution but also increases spectral leakage, and vice versa.
To minimize spectral leakage, it is important to choose an appropriate window function that can reduce the sidelobe levels of the FFT. Common window functions include the Hamming, Blackman, and Kaiser windows, among others. Choosing an appropriate window function and applying it properly can help you achieve a good balance between frequency resolution and spectral leakage.
Regarding the presence of a peak at 0 Hz in the spectrum, it is possible that this peak is due to the baseline, DC offset, or bias in the signal caused by some extraneous factors such as instrument noise, bias voltage, or other disturbances. This peak can also be related to the displacement or other non-linear properties of the system being monitored, especially if it is a mechanical or vibrational system.
To resolve this issue, you may want to consider subtracting the baseline or DC offset from the signal before performing the PSD estimation, or use high-pass filtering or other techniques to remove the low frequency components. You may also want to investigate the properties and behavior of the system being monitored, including its input-output relationship, the effects of boundary conditions, and other factors that may contribute to the observed low-frequency peak in the spectrum.
with regards,
Gokul Nath S J
3 Comments
Oskar Kilgus
on 24 May 2023
Mathieu NOE
on 26 May 2023
you could use detrend to remove dc offset and maybe also a linear drift (then use detrend with 'linear' option)
Oskar Kilgus
on 30 May 2023
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!