Fourier transform (fft) in MATLAB from accelerometer data for acceleration, velocity and position
Channel: Mathias Magdowski
Date: 2023-01-05

In this short video, I explain how to import a given txt file with raw data from some accelerometer in MATLAB, how to extract time steps (in the unit s) and the linear acceleration (in the unit m/s²) into a certain direction from the given matrix, and how to plot this time domain data. The velocity (in the unit m/s) and the position (in the unit m) can be calculated from the acceleration by numerical integration using the 'cumtrapz' function from MATLAB. After checking the validity (setting the first time step to zero, and making sure that all time steps are equidistant) and detrending the data (using the 'detrend' function from MATLAB), I show how to calculate the frequency spectrum and the corresponding frequency values using the given 'fourier' function, and how to plot the amplitude spectrum with a logarithmic axes scaling. Finally, I show how to calculate the maximum change of position at a certain frequency from the maximum change of accelaration and velocity directly, and to compare the results with the initial calculation.

MATLAB source code of the example:
https://cloud.ovgu.de/s/iN85Gqs8MJx7dQm

Chapter marks:
0:00 Introduction
0:21 Load the data set
0:53 Plot the time function
2:54 Calculate the velocity and position
5:51 Look at the time function
7:18 Window and detrend the data
11:16 Check for equidistant time steps and set the first time step to zero
12:28 Fourier transform of the position
13:24 Plot and look at the spectrum of the position
16:08 Find the maximum amplitude and corresponding frequency
19:10 Intermediate summary
19:40 Alternative solution from the spectrum of the acceleration
20:32 Plot and look at the spectrum of the acceleration
21:31 Calculate the velocity and position
26:15 Compare the results
26:37 Fourier transform of the velocity
27:58 Summary and discussion
28:55 Final advice