2
$\begingroup$

I am recording vibration data using an adxl335 accelerometer.I have ~50ms delay before i save a reading from this sensor so most probably each second i have ~20 readings. I verified that by checking the difference between two consecutive readings since i am recording the time of reading, however since my pc is not real time i guess matlab is varying but i found that the average time between two consecutive readings is 0.0517 so my sampling should be ~19 hz ? is this the value that should be chosen ?

$\endgroup$
  • $\begingroup$ Hi. Is there any chance to accept the answer if it satisfy your needs? Thanks to that your question won't come back to the main page as unanswered. $\endgroup$ – jojek Apr 8 '16 at 14:03
1
$\begingroup$

The sensor is analogue and being input to Arduino for analogue to digital conversion. Arduino has a function Micros() which Returns the number of microseconds since the Arduino board began running the current program, I suggest using this to accurately save the time of analogue read on Arduino. Calculate the difference as shown in the code below and send it through with the sensor reading to Matlab. Then just average the values of the time difference calculated by t2-t1 which will be almost constant, and you will have as accurate as possible the sampling time/Sampling frequency used and so you can very accurately do an FFT analysis using this information. Hope this will be helpful.

//Define Analogue Ports for Sensor input
const int xpin1 = A2; // x-axis of the accelerometer 1

//Define variable t1 for timing
unsigned long t1 = micros();

void loop()
{
  int x1 = analogRead(xpin1);  //read x from 1

  Serial.print(x1);  //print x1 value on serial monitor
  Serial.print("\t");

  unsigned long t2 = micros();
  Serial.print(t2-t1);
  Serial.print("\t");
  t1 = t2;
}
| improve this answer | |
$\endgroup$
0
$\begingroup$

Sampling rate = samples per second. Since your fft frame will be several samples long, you could think about:

  1. recording the time when you read the first sample of the frame
  2. reading in a certain number of samples
  3. querying the time again
  4. computing time difference in seconds
  5. then, divide number of recorded samples by the time difference to find average sampling rate
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.