Q:

How to pick a sampling frequency for Matlab fft

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 ?

A:

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;
}

