accelerometer data shows nothing in FFT

3 views (last 30 days)
tje_b on 12 Jul 2023
Edited: dpb on 13 Jul 2023
I upload the data and the code but when I run it, nothing show up.
the accelerometer was connected to a shaker and sampled at 100Hz but the accelerometer sampling frequency was 1000Hz.
I have attached the data, the first column is accelerometer timestamp and the second column is the Z-axis data.
I would appreciate any inputs or assistance. Thanks
% Load data from the file
% Extract z-axis data
z_data = data(:, 2);
% Perform FFT
Fs = 100; % Sampling frequency (replace with your actual sampling frequency)
N = length(z_data); % Number of samples
frequencies = Fs*(0:(N/2))/N;
fft_data = abs(fft(z_data)/N);
fft_data = fft_data(1:N/2+1);
% Plot FFT
plot(frequencies, fft_data)
xlabel('Frequency (Hz)')
ylabel('Amplitude')
title('FFT - Frequency Domain Analysis')

Dirk Engel on 12 Jul 2023
Please check your plot again. The data DOES show up, but you have to zoom in on the values. Since the first y-value is 4 orders of magnitude larger than the other 177956 y-values, they are barely visible at around y=0.

dpb on 12 Jul 2023
N=100;
t=d(:,1)-d(1,1);
plot(t(1:N),d(1:N,2))
xlim([t(1) t(N)])
dt=diff(t);
[mean(dt) min(dt) max(dt)]
ans = 1×3
1.0e+04 * 0.0604 0.0156 4.5513
plot(dt)
xlim([0 500])
L=size(d,1);
y=fft(d(:,2));
P2=abs(y);
P1=P2([1:L/2]);
P1=2*P1(2:end-1);
plot(P1)
The time history is not at all smooth; it's going to create all kinds of artifacts at all those square corners.
Whatever units the timestamp are in, they don't relate to 1kHz sampling rate that is claimed and certainly the time trace doesn't appear to be anything close to a 10X oversampled signal if the excitation frequency of the shaker were 100 Hz.
Then, looking at the time stamps themselves, the sampling rate is so variable as to make a total mockery of any resemblance to a constant sampling rate.
Not much to be said other than the data collection process needs fixing first...
tje_b on 12 Jul 2023
Many thanks, I think the sensor is bad. I will go get another.
dpb on 12 Jul 2023
Edited: dpb on 13 Jul 2023
t=d(:,1)-d(1,1);
dt=diff(t);
histogram(dt)
hAx=gca;hAx.XScale='log';hAx.YScale='log';
ylim([1e-1 1E6])
title('Number time intervals vs time interval')
ylabel('Counts')
xlabel('Sample delta-t')
The problem isn't the sensor, I think, but however the collection is being scheduled/called. The above shows there's a difference of something like 10^4 in the sampling interval (whatever the sample timestamp units are). It would be one thing if there were a little variation in sampling, but gross differences like this make interpolation as @Star Strider illustrated pretty risky; you're making more data than you've really collected.
We "know nuthnk!" a la Sgt Schultz about the experimental setup and data acq, but there's where the biggest issue lies imo; I suspect the accelerometer itself is just fine.

Star Strider on 12 Jul 2023
Perhaps something like this —
x = data(:,1);
y = data(:,2);
xstats = [mean(diff(x)); std(diff(x)); nnz(diff(x)<0)]
xstats = 3×1
603.7760 845.0621 0
Ts = round(mean(diff(x))); % Mean Sampling Interval
Fs = 1/Ts; % Derived Common Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
[yr,xr] = resample(y,x,Fs); % Resample To Constant Sampling Intervals
figure
plot(xr, yr)
grid
xlabel('X')
ylabel('Y')
title('Resampled Data')
% xlim([min(xr) max(xr)])
L = numel(xr);
NFFT = 2^nextpow2(L);
FTyr = fft((yr-mean(yr)).*hann(L), NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
[pks,locs] = findpeaks(abs(FTyr(Iv))*2, 'MinPeakProminence',0.01);
Peaks = table(Fv(locs).',pks, 'VariableNames',{'Frequency','MAgnitude'})
Peaks = 12×2 table
Frequency MAgnitude __________ _________ 0.00018731 0.014701 0.00018743 0.019301 0.00018763 0.01118 0.00035563 0.038953 0.00038744 0.010767 0.0005 0.012595 0.00055563 0.019418 0.00058731 0.013127 0.00058744 0.015026 0.00075563 0.010539 0.00078731 0.013073 0.00078744 0.018322
figure
plot(Fv, abs(FTyr(Iv))*2, 'DisplayName','Data')
hold on
plot(Fv(locs), pks, '^r', 'DisplayName','Identified Peaks')
hold off
grid
xlabel('Frequency ($\frac{cycles}{x\ unit}$)', 'Interpreter','latex')
ylabel('MAgnitude (y units)')
title('Fourier Transform')
legend('Location','best')
xlim([0 max(Fv)])
With the exception of the nufft function, Fourier transforms require that the data be regularly sampled, the reason for using resample here. There is broadband noise with some apparently random frequency spikes, so I am not certain what sort of processing might be best for it. It might be best to simply design IIR bandpass filters for the spike frequencies, and be happy with those results.
There are three groups of peaks that appear to be very close together.
.