How to do a fast Fourier transform (fft) in MATLAB to calculate the spectrum of data from a mat file
Channel: Mathias Magdowski
Date: 2021-12-17

In this short video, I explain how to import a given mat file with raw data in MATLAB, how to extract time steps and numerical function values from the given matrices, and how to plot the time domain data. After checking the validity of the data (no NaN values), setting the first time step to zero, and making sure that all time steps are equidistant, I show how to calculate the frequency spectrum and the corresponding frequency values using the given 'fourier' function. Finally, I demonstrate how to plot the amplitude spectrum with a linear and logarithmic axes scaling.

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

In the video, I forgot to show how to check for equidistant time steps. If you run

plot(diff(t))

you should get a constant line, which is the case here.

Chapter marks:
0:00 Loading the first matrix
2:01 Loading the second matrix
3:34 Removing the time offset
4:41 Adding axis labels
5:27 Looking at the time function
7:00 Fast Fourier transform
9:40 Looking at the spectrum
10:53 Double-logarithmic axes scaling
12:31 Some more advice