I am trying to determine my sampling rate, or the delay between each sample, but I am a little unsure if my math is correct.

I have generated a sine wave

f = 1000 Hz

which gives me T = 1 ms

I am sampling the sine wave and imported the data into matlab.

From the graph I can see that I have 51 samples per period.

I then calculated the time between the samples to:

T / 51 = 19.6 us

But I am wondering whether this is the correct way to do so?

Thank you in advance.

Sine wave

  • 1
    $\begingroup$ There are many different ways of doing this. What's your criteria for "correct"? As far as I can tell, it's a bit unusual but not wrong. $\endgroup$
    – Hilmar
    Commented Apr 13, 2021 at 11:34
  • $\begingroup$ Strictly speaking you found the sampling interval; that is, the time between two samples. The sampling rate is given by 51/T. $\endgroup$
    – MBaz
    Commented Apr 13, 2021 at 13:14
  • $\begingroup$ Thank you for your replies. Great, I was looking for the sampling interval, but confused myself whether or not it actually was true. I have a Teensy connected and in the code I have a delay of 10 microseconds, so I wanted to determine if it in fact is around 10 microseconds. $\endgroup$
    – Napzapper
    Commented Apr 13, 2021 at 13:37

1 Answer 1


The assumption here is the sine wave being samples is a known and assumed accurate reference, and the sampling rate is the unknown.

An algorithm that utilizes every sample with equal weight would provide for the best estimate assuming a white noise process. The approach the OP uses, and any similar "edge-detection" methods where we are making a decision on a cycle boundary and then measuring the distance between two such decisions, are prone to significantly higher errors under lower SNR conditions due to the sensitivity of noise on just the two decisions used; as done the noise effecting the result is the rms of the noise for each of the two decisions so is additive as well.

Such algorithms for determining the frequency of a single tone are well documented (see Question regarding estimation of signal tone parameters (frequency, amplitude, and phase) using Macleods algorithm). The approach would be to use these techniques with a scaled frequency designating the tone frequency to be determined as a frequency ratio relative to the sampleing rate $(f/f_s)$ rather than absolute frequency. Thus once $f/f_s$ is determined with such estimators, and with $f$ known, $f_s$ can be accurately determined.

The FFT is one such algorithm that uses every sample to provide a best estimate (under white noise conditions), but for the case of a single tone, the above references would provide more optimized solutions. See https://www.dsprelated.com/showarticle/1284.php where @CedronDawg worked through the math to derive the precise frequency estimate from two adjacent bins in the FFT result (for all the likely cases when the actual frequency is not centered on a bin), so that could be combined with the Goertzel algorithm which efficiently solves for a smaller subset of all DFT bins for a reasonable solution.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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