![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1433058/image.png)
accelerometer data shows nothing in FFT
2 次查看(过去 30 天)
显示 更早的评论
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)')
ylabel('Amplitude')
title('FFT - Frequency Domain Analysis')
0 个评论
回答(3 个)
Dirk Engel
2023-7-12
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1433058/image.png)
0 个评论
dpb
2023-7-12
d=readmatrix('usb_data_100hz2.17th.txt');
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)]
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...
2 个评论
dpb
2023-7-12
编辑:dpb
2023-7-13
d=readmatrix('usb_data_100hz2.17th.txt');
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
2023-7-12
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)]
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'})
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.
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!