Time + Acceleration Fourier transform into Amplitude + Frequency

16 views (last 30 days)
I am trying to transform measured data from time and accelerations into amplitude and frequency, but I really dont understand the process. I have this:
g=9.81
A = importdata('220927_1.txt')
A = A.data
% Front Left sprung mass
B = [A(:,1),A(:,3).*g]
N = pow2(nextpow2(length(B)));
y = fft(B,N);
plot(1:N,abs(y))
Time = B(:,1); % Time (s)
Acceleration = B(:,2); % Acceleration (m/s^2)
n = length(Acceleration);
Ts = Time(n)-Time(1); % Sample Time
Fs = 1/Ts; % Sampling Frequency
NFFT = 2^nextpow2(n); % Next power of 2 from length of data
Y = fft(Acceleration,NFFT)/n;
f = Fs/2*linspace(0,1,NFFT/2+1);
plot(f,abs(Y))
xlabel('Frequency (Hz)')
ylabel('Amplitude (m)')
I copied the script for Fourier transform from another support but I dont know how to fix it for my application.
Additionally I was recommended to reduce the noise which I didnt search yet, but its not neccessary to answer that here.
I attached the measurement file. For sprung mass (vehicle body) there should be natural frequency somewhere around 1 to 2 Hz, so there should be peak value in ploted result. (for unsprung its around 10 Hz)

Accepted Answer

Star Strider
Star Strider on 30 Sep 2022
The ‘Time’ values are not unique (they likely need an additional digit of precision) so they had to be processed by taking the mean of the unique values for both variables. The rest of the code needed a bit of tweaking to get it to work correctly. The signal has broadband noise, so a frequency-selective filter will not remove much of it. I experimented by filtering it with the sgolayfilt function since you mentioned filtering, however filtering may not be necessary if yoiu are only interested in the spectral qualities of the signal.
Try something like this —
Uz = unzip('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1141115/220927_1.zip');
T1 = readtable(Uz{1}, 'VariableNamingRule','preserve')
T1 = 104550×15 table
Time Vehicle Speed FL Sprung acceleration FR Sprung acceleration RL Sprung acceleration RR Sprung acceleration FL Unsprung acceleration FR Unsprung acceleration RL Unsprung acceleration RR Unsprung acceleration Bellow pressure RL Bellow pressure RR Acceleration X Acceleration Y Acceleration Z _____ _____________ ______________________ ______________________ ______________________ ______________________ ________________________ ________________________ ________________________ ________________________ __________________ __________________ ______________ ______________ ______________ 0 0 -0.089 -0.034 -0.034 0.126 1.156 0.755 0.736 1.528 2.341 2.275 -0.594 -0.183 -1.857 0 0 -0.089 -0.035 -0.036 0.129 1.137 0.753 0.749 1.543 2.338 2.275 -0.595 -0.185 -1.857 0 0 -0.089 -0.037 -0.037 0.13 1.148 0.76 0.762 1.555 2.337 2.271 -0.596 -0.185 -1.857 0.001 0 -0.091 -0.039 -0.038 0.132 1.139 0.747 0.792 1.569 2.344 2.264 -0.597 -0.186 -1.858 0.001 0 -0.091 -0.04 -0.037 0.133 1.145 0.754 0.78 1.567 2.334 2.27 -0.596 -0.182 -1.856 0.001 0 -0.092 -0.043 -0.032 0.135 1.138 0.743 0.781 1.534 2.344 2.271 -0.595 -0.183 -1.858 0.001 0 -0.092 -0.043 -0.029 0.133 1.147 0.752 0.783 1.542 2.345 2.269 -0.595 -0.181 -1.857 0.001 0 -0.094 -0.046 -0.024 0.132 1.136 0.762 0.784 1.531 2.335 2.272 -0.594 -0.184 -1.86 0.002 0 -0.095 -0.047 -0.021 0.13 1.126 0.775 0.771 1.526 2.334 2.267 -0.595 -0.181 -1.857 0.002 0 -0.095 -0.047 -0.017 0.131 1.119 0.807 0.76 1.552 2.329 2.269 -0.595 -0.181 -1.856 0.002 0 -0.096 -0.048 -0.011 0.129 1.118 0.799 0.761 1.559 2.348 2.275 -0.593 -0.179 -1.853 0.002 0 -0.094 -0.05 -0.008 0.128 1.127 0.803 0.78 1.54 2.337 2.266 -0.597 -0.178 -1.856 0.002 0 -0.095 -0.05 -0.007 0.128 1.092 0.786 0.75 1.566 2.336 2.272 -0.597 -0.176 -1.856 0.003 0 -0.094 -0.049 -0.006 0.126 1.098 0.772 0.739 1.549 2.336 2.276 -0.597 -0.175 -1.856 0.003 0 -0.095 -0.049 -0.003 0.128 1.111 0.777 0.713 1.555 2.332 2.274 -0.597 -0.174 -1.855 0.003 0 -0.095 -0.049 -0.004 0.126 1.082 0.792 0.678 1.562 2.337 2.272 -0.597 -0.172 -1.856
g=9.81;
t = T1{:,1};
FLSA = T1{:,3}*g;
[Ut,~,ix] = unique(t, 'stable');
C = accumarray(ix, (1:numel(t)), [], @(x){mean([t(x),FLSA(x)])}); % Aggregate Repeated 'Time' Values
M = cell2mat(C);
ta = M(:,1);
FLSAa = M(:,2);
Ts = mean(diff(ta));
Fs = 1/Ts
Fs = 1.0000e+03
% Tssd = std(diff(ta))
figure
plot(t,FLSA)
grid
xlabel('t')
ylabel('FLSA')
title('Original')
figure
plot(ta,FLSAa)
grid
xlabel('t')
ylabel('FLSA')
title('Aggregated')
FLSAa_filt = sgolayfilt(FLSAa, 3, 51); % Optional
figure
plot(ta,FLSAa_filt)
grid
xlabel('t')
ylabel('FLSA')
title('Aggregated & Filtered')
Time = ta; % Time (s)
Acceleration = FLSAa_filt; % Acceleration (m/s^2)
n = numel(Acceleration);
Ts = Time(n)-Time(1); % Sample Time
Fs = 1/Ts; % Sampling Frequency
NFFT = 2^nextpow2(n); % Next power of 2 from length of data
Y = fft(Acceleration-mean(Acceleration),NFFT)/n;
f = Fs/2*linspace(0,1,NFFT/2+1);
Iv = 1:numel(f);
figure
plot(f,abs(Y(Iv))*2)
grid
xlim([0 0.005])
xlabel('Frequency (Hz)')
ylabel('Amplitude (m)')
Experiment to get the desired result.
.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!