fourier transform of smart-phone accelerometer in matlab

I'm new to matlab. I want to process my smart-phone accelerometer data in matlab. I know Matlab let's you connect your phone via USB cable to see accelerometer data in realtime. But according to some reasons I don't want to use this method. Instead I've developed an application that saves accelerometer data. I want this application to produce a ".m" file and use this file to represent x-y-z signals. The problem is that the accelerometer data rate is not constant. for example: "data-1" corresponds to time "0.1", "data-2" corresponds to time "0.2", and "data-3" corresponds to time "0.8". You can see the time interval can change. I need to get fourier transform of these signals, so I can not use the simple matlab vector to represent them. How can I represent these signals? How can I get the correct fourier transform of these signals?

• Don't use Arduino it is simpler way USB ACCELEROMETER ;) 🢂 tindie.com/products/10373 🢀 Feb 5, 2019 at 23:48

Two methods occur to me.

1. Perform a non-uniform DFT. You can use Google to find MATLAB implementations of it, or try to write one on your own. This file seems to be legit, although I haven't tried it myself.
2. If you have the Signal Processing Toolbox, then you can use the resample() function to interpolate your non-uniformly sampled vector linearly onto a vector of uniformly spaced instants, and then perform the usual DFT on the latter.
• y = resample(x,tx) resamples the values, x, of a signal sampled at the instants specified in vector tx. The function interpolates x linearly onto a vector of uniformly spaced instants with the same endpoints and number of samples as tx. NaNs are treated as missing data and are ignored. Feb 16, 2018 at 7:11

Creating a .m file with all your data explicitly assigned is not really efficient if you have more than a few tens of data points. You really just want to get the data into your memory space. Once you get it in your memory the way you want, you can save it as a .mat file using save and use load to bring it back in.

It sounds like your data from your phone will be in a text file and matlab has several methods including a data import tool, which isn’t hard to use.

A particularly easy way to represent data with irregular time samples is to use a timeseries object and use timeseries methods to manipulate the data. As suggested in @Tenderos answer, there is a resample method. timeseries objects have a lot of overloaded methods that are straightforward to apply.

Another advantage is that a timeseries object can be vector valued.