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?
Two methods occur to me.
- 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.
- 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.
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.