# Relationship between baud rate and the frequency of vibration read using ADXL

I am doing a project using Arduino Uno and ADXL 345. I am quite new to this and I came across this post in the link" : https://www.sparkfun.com/tutorials/240. Here, a user had posted the below question in the forum.

"Im trying to use this accelerometer to test various frequencies of vibration on a cantilevered beam and I wanted to know what the maximum vibration frequency I could find with using this accelerometer, connected to a 16MHz processor, connected to my laptop. I’m mainly a mechanical person, but after doing some research I found the following: Accelerometer has a maximum of 3200Hz output data rate (so maximum frequency would be 1600Hz) Processor can execute 16,000,000 instructions/sec so this probably is okay Communication rate is 9600 bits/sec so in the program above we read at a minimum 6 bytes for each axis, so that’s 24 bits, leaving you able to read 9600/24 = 400 reads/sec resulting in a one to be capable of reading vibrations at 200Hz. If I bump up the baud rate to 115200, I should be able to then read 4800 times a second, thus measuring 2400Hz vibrations?"

But I do not see any replies to this question. I feel the above analysis mostly makes sense. It would be helpful if someone could confirm that the above analysis is right. If not right , then why isn't it right?

Thanks

Firstly, the datasheet for the accelerometer suggests using >=2Mhz SPI communication rate with 3200 or 1600 Hz output data rate operation.

Since the Arduino SPI library default clock is 4Mhz, the Arduino can handle 3200 Hz sampling, so the maximum frequency you could distinguish would be 1600 Hz.

So the Arduino and accelerometer can detect vibrations up to 1600Hz.

Next, you send the data to your laptop. At 9600 BAUD, you are correct in saying that since the data is 24 bits, it will only update your laptop with the Arduino's measured frequency at 9600/24 = 400 Hz. So 400 times a second the Arduino could tell the laptop what frequency it measures, the measurement having a maximum frequency of 1600 Hz.

For the Arduino to simply pass the raw data to the laptop at 3200 Hz, you would need 24 bits * 3200 Hz = 76800 BAUD minimum.

The measurement data is in any case limited by the accelerometer sampling rate of 3200Hz.

• Thanks for your response. But I don't understand the line "the Arduino can handle 3200 Hz sampling, so the maximum frequency you could distinguish would be 1600 Hz." Why is it 1600Hz when the sampling rate is 3200Hz. I am new to this. It would be helpful if you explain this. Thanks – priti Jun 18 '15 at 1:08
• According to the Nyquist Theorem, you need to sample twice as fast as the highest frequency you want to measure. For Ex, if the signal you wish to measre is a 1MHz sine wave, you have to sample at AT LEAST 2 M Samples per second (MS/s) to ensure that the 1MHz frequency component of the signal is detected. However, sampling at exactly 2 times the highest frequency is often unacceptable, especially where the shape of the signal is important. When sampling a pure sine wave, I generally make sure to sample at at least 10 times the frequency of that sine wave to see the shape of the signal. – tiggun Jun 18 '15 at 3:31
• Typical serial encoding is more like 10 bit periods per byte, so 24 bits becomes 30 byte times. But 3200 * 30 should just fit in 115200 baud, which is within the capability of a sound Arduino setup. It will mean using binary encoding though, and with a divisible-by-three size, which is ugly. I'd consider trying to pack the data to two bytes. – Chris Stratton Dec 12 '15 at 15:30