Hey guys, I’m learning how to use this sensor with my Arduino trying to learn the basics. So at stationary, I’ll be streaming raw, accelerometer and gyroscope data from each axis. How would I integrate the gyro data and fft the accelerometer data?

I can’t seem to find things that do this.

FFT? While it's (barely) possible to do FFT on an Arduino, it's a better idea to do signal processing like this on an RPi or on a PC (post-processing).

What exactly are you trying to do?

I can't imagine why you would want to do that. What is the FFT for?

But if you must, do things stepwise.

- Learn to collect and interpret the data.
- Learn to process the gyro data, and how to interpret the result.
- Learn how an FFT works, how to apply it to accelerometer data, and how to interpret the result. It won't be "streaming".

Agree with the previous replies. There is C-code out there to calculate an FFT if you really need that. What exactly are you after? Calculate a spectrum (average of FFTs) and then display it on a screen? … That's a lot to ask of an Arduino. It might be best to somehow transfer the data to a host computer, and have such computer do all the calculations/graphing. The Raspberry Pi is definitely an option.

As to integration, my experience is that there is always a random non-constant drift if you integrate the time sequence. Depending on how broadband the signal is, you might opt to do integration followed by a sharp high-pass filter, to precisely remove the drift.

I do all my DSP (Digital Signal Processing) with specialized packages such as MATLAB and ArtemiS … there are other packages out there, but it all depends on how deep you want to get into DSP.

Sorry I wasn’t very clear. Hm if that’s the case, I think it’s better for me to collect the data and save it into a .csv file and then analyse the data.

Any ideas in how I can save data into a csv file and perform fft and it?

All this is just part of my learning curve

You will need an SD card module or shield, and the associated library. Learn how to use it by studying the library examples and documentation.

jremington:

You will need an SD card module or shield, and the associated library. Learn how to use it by studying the library examples and documentation.

Could you recommend me a shield ? Also does it work if I use a Bluetooth module to transmit and save the data? If you can, mind telling me about that(Bluetooth module recommendation would be perfect as well)? Thank you!

The usual USB connection to the serial monitor works fine for collecting and saving data.

Instead of the serial monitor, use a terminal program like TeraTerm or Putty to log Arduino output to a .csv file on a PC.

Python's serial library will also work for this.

But it will really help you to explain what you think you are attempting to do - it may you are going

about it all wrong, "xyproblem"

MarkT:

Python's serial library will also work for this.

pySerialTransfer is another good Python library for this application

MarkT:

Python's serial library will also work for this.But it will really help you to explain what you think you are attempting to do - it may you are going

about it all wrong, "xyproblem"

Hm, not too sure how to use the python library thing? But ideas are very welcome as I'm still figuring things out. So I will look further into it.

However, I've saved a logged file of my sensor and saved it onto Excel showing raw data. How would I be able to use this data I have and convert it into a FFT or some kind of integration?

Here is my logged file if you would like to see it.

here is my data in excel (which includes date and time) with a baudrate of 115200

anony97:

How would I be able to use this data I have and convert it into a FFT or some kind of integration?

What are you actually trying to achieve via an FFT or "some kind of integration"? This absolutely

crucial background info we need to make any sense of your problem.

MarkT:

What are you actually trying to achieve via an FFT or "some kind of integration"? This absolutely

crucial background info we need to make any sense of your problem.

For the accelerometer data, how would I be able to transform the raw data into the frequency domain by using fft, so processed data could be clearly represented ( vibration and acceleration level)

As for the gyroscope data, maybe by calculating the current tilt angle by by taking a reading at a set frequency, calculating how many degrees we have turned in that period and then summing these values up - which is basically integration right?

Only problem is I’m not too sure how I’m able to do it using my raw values which I’ve linked

The FFT transforms time series data into the frequency domain, if the data are collected at known, regular time intervals. The sample frequency must equal or exceed twice the maximum frequency of any signal in the data set.

Integrating rate gyro data with respect to time gives you the relative turn angle, at least over a short period of time. Again, the time interval must be known and regular.

Have you learned how to interpret the data raw values? If not, that is an extremely important first step.

Thanks jremington!

Also , could i have a bit of guidance in interpreting the raw data i have?

So for my accelerometer, I am using +—16g so what i did to get my data was accelerometer(x/y/z) value divided by 2048(LSB/g) which is in the data sheet

For gyroscope, i used 2000 degrees per sec

So its gyroscope(x/y/z) value divided by 16.4(LSB[degrees/sec])

anony97:

For the accelerometer data, how would I be able to transform the raw data into the frequency domain by using fft, so processed data could be clearly represented ( vibration and acceleration level)

But this is 3D data, you probably only want one-dimensional signal for vibration analysis (is vibration analysis what you want?). You could look at x,y,z separately here.

As for the gyroscope data, maybe by calculating the current tilt angle by by taking a reading at a set frequency, calculating how many degrees we have turned in that period and then summing these values up - which is basically integration right?

You need to combine 3D accelerometer and 3D gyro data to get orientiation, this is called an IMU (inertial measurement unit). Basically at long time scales the gravity vector dominates the accelerometer data, and

this can then be used to correct for drift in the gyro estimate of orientation - MEMS gyros drift quite quickly,

easily noticably after a minute or even less.

Yes, you *do* integrate the gyro readings, but as quarternions(*), because you have to do everything

in 3D values as 3D rotation is not commutative (you cannot separate into x, y, z and recombine, that doesn't work at all as 1D rotation is commutative)

Read up on IMUs, quarternions and most importantly the libraries to do this for you(!). The MPU6050 can do most of this for you internally, providing a direct quarternion output as well as the raw value streams.

You'll need to know the sensitivity of the gyro as integrating needs to know the radians/second values so

you can scale by the time-step at each integration point. Real gyros have slightly different sensitivities in the

3 axes which can be measured to help get things as accurate as possible.

Alas real gyros are not completely linear, so that the error varies with rotation speed a bit - these are not the

most precise instruments, but they are very small and very cheap!

(*) More particularly unit quarternions which can represent 3D rotations. Integration has to re-normalize the result to stay as a unit quarternion.

MarkT:

But this is 3D data, you probably only want one-dimensional signal for vibration analysis (is vibration analysis what you want?). You could look at x,y,z separately here.You need to combine 3D accelerometer and 3D gyro data to get orientiation, this is called an IMU (inertial measurement unit). Basically at long time scales the gravity vector dominates the accelerometer data, and

this can then be used to correct for drift in the gyro estimate of orientation - MEMS gyros drift quite quickly,

easily noticably after a minute or even less.Yes, you

dointegrate the gyro readings, but as quarternions(*), because you have to do everything

in 3D values as 3D rotation is not commutative (you cannot separate into x, y, z and recombine, that doesn't work at all as 1D rotation is commutative)Read up on IMUs, quarternions and most importantly the libraries to do this for you(!). The MPU6050 can do most of this for you internally, providing a direct quarternion output as well as the raw value streams.

You'll need to know the sensitivity of the gyro as integrating needs to know the radians/second values so

you can scale by the time-step at each integration point. Real gyros have slightly different sensitivities in the

3 axes which can be measured to help get things as accurate as possible.Alas real gyros are not completely linear, so that the error varies with rotation speed a bit - these are not the

most precise instruments, but they are very small and very cheap!(*) More particularly unit quarternions which can represent 3D rotations. Integration has to re-normalize the result to stay as a unit quarternion.

very informative thank you!

Yes for the accelerometer part, I was going to look at them individually. and probably try to fft the xyz axis?

so with the gyros, I have to do quaternions in order integrate? there's no avoiding it for now or to start of with something easy? aha

Also, in my code, my raw data is measured in lsb/G or lsb(degrees/sec) units. My question is, how ami able to log what frequency and do I need to convert those raw data units into something else so I could fft it in excel?

Attached below is my code I used and my excel results

Codeee.pdf (118 KB)

One question you still have not answered yet ... Because, once we know what you plan to do with it, then we can brainstorm about the various processing steps needed. I've used a similar sensor to capture 3D motion of a vehicle (3 translations and 3 rotations) as a function of time. Then, I did my calculations then compared to the data I've collected with an iPad Pro (Using the Sensor Play App).

- What exactly do you want to do with the data?
- Do you really need the RAW data then plan to do all the processing by yourself?
- Why not use Data Fusion ... where you let the sensor 'process' the data and only output what you truly need.
- Need also to decide what sampling rates and record duration you need ... based on 'dynamics' of object you're measuring
- Is the data 'stationary' i.e., are the amplitudes of the various frequency peaks constant?
- If not, then the FFT is NOT the proper calculation, you might need an FFT vs. Time ... of the 6 degrees-of-freedom you're measuring.

So, again, the more you tell us about the intended application, the better we can help you.