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
data = load("usb_data_100hz2.17th.txt");
% 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)')
title('FFT - Frequency Domain Analysis')

Answers (3)

Dirk Engel
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
xlim([t(1) t(N)])
[mean(dt) min(dt) max(dt)]
ans = 1×3
1.0e+04 * 0.0604 0.0156 4.5513
xlim([0 500])
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
ylim([1e-1 1E6])
title('Number time intervals vs time interval')
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.

Sign in to comment.

Star Strider
Star Strider on 12 Jul 2023
Perhaps something like this —
data = readmatrix('usb_data_100hz2.17th.txt');
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
plot(xr, yr)
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
plot(Fv, abs(FTyr(Iv))*2, 'DisplayName','Data')
hold on
plot(Fv(locs), pks, '^r', 'DisplayName','Identified Peaks')
hold off
xlabel('Frequency ($\frac{cycles}{x\ unit}$)', 'Interpreter','latex')
ylabel('MAgnitude (y units)')
title('Fourier Transform')
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!