Can sampling rate be a floating point number? - Electrical Engineering Stack Exchange most recent 30 from electronics.stackexchange.com 2019-08-17T15:05:00Z https://electronics.stackexchange.com/feeds/question/452566 http://www.creativecommons.org/licenses/by-sa/3.0/rdf https://electronics.stackexchange.com/q/452566 4 Can sampling rate be a floating point number? Ron Howard https://electronics.stackexchange.com/users/228595 2019-08-12T07:29:07Z 2019-08-13T11:46:07Z <p>Suppose we have a sampling frequency for a signal of 15.5 samples/sec and we take samples for a period of 7 seconds. This means total samples are 108.5, does this make any sense? </p> <p>Shouldn't the number of samples taken be an integer like 108 or 109? Or can the particular points in time from 0 second to 7 seconds on which to take the samples be determined in this case? How would one do that?</p> https://electronics.stackexchange.com/questions/452566/-/452567#452567 23 Answer by joribama for Can sampling rate be a floating point number? joribama https://electronics.stackexchange.com/users/217794 2019-08-12T07:37:24Z 2019-08-12T20:22:12Z <p>Forget sampling rate for a few seconds... Think about sampling period for a second, which is the time interval between two consecutive samples. This time can be an integer or any real number (as long as it’s positive, of course).</p> <p>Sampling rate is simply the inverse of sampling period. Does it make more sense this way?</p> https://electronics.stackexchange.com/questions/452566/-/452569#452569 14 Answer by jusaca for Can sampling rate be a floating point number? jusaca https://electronics.stackexchange.com/users/159456 2019-08-12T07:42:06Z 2019-08-12T07:51:57Z <p><strong>Yes, the sampling rate can be any number you want.</strong></p> <p>But you obviously would not get partial samples in the end, you just have to round down.<br> In your example the first sample is taken at <span class="math-container">\$\frac{1}{15.5}s \$</span> = 64.5 ms and then at every multiple from that. This means you get your last sample at 6,966 s. That is the 108's sample. So at 7 s you <em>still</em> have taken only 108 samples. And then at 7,0305 s you get the next sample.</p> <p>You can imagine the samples beeing taken in a way like this <a href="https://en.wikipedia.org/wiki/Dirac_comb" rel="noreferrer">dirac comb</a>: <a href="https://i.stack.imgur.com/C0We1.png" rel="noreferrer"><img src="https://i.stack.imgur.com/C0We1.png" alt="enter image description here"></a></p> <p>If you stop sampling between 3T and 4T you do not have partial samples. You just round down. T is the inverse of the sample frequency, or in your case 64.5 ms.</p> https://electronics.stackexchange.com/questions/452566/-/452571#452571 13 Answer by Neil_UK for Can sampling rate be a floating point number? Neil_UK https://electronics.stackexchange.com/users/50733 2019-08-12T07:47:45Z 2019-08-12T07:47:45Z <p>Some things are always an integer. Samples are always integer. You can take 108 or 109 samples.</p> <p>Sample rate can be a floating point number, or more generally a rational, or even a real.</p> <p>You calculate the sample rate by dividing the number of samples (less one to get the number of periods between samples) by the time it takes to obtain those samples.</p> <p>Generally a floating point number is an approximation to the real number you want. With double precision, it's a very good approximation, but it's usually inexact. </p> <p>If you're given a sample rate, and a time, the product might be an exact integer, if the numbers are chosen carefully, but it probably won't be. It might be in error a small amount, due to the approximation of floating point representation. It might be in error a lot, because the source of your information chose very approximate numbers, or even made up the numbers to start with.</p> https://electronics.stackexchange.com/questions/452566/-/452766#452766 3 Answer by Dave Tweed for Can sampling rate be a floating point number? Dave Tweed https://electronics.stackexchange.com/users/11683 2019-08-13T11:46:07Z 2019-08-13T11:46:07Z <blockquote> <p>This means total samples are 108.5, does this make any sense?</p> </blockquote> <p>Only in a limited sense. Since your sample interval of 7 seconds is not an integer multiple of the sampling period (1/15.5 Hz = 0.064516... s), it means that any arbitrary 7-second interval will contain either 108 samples or 109 samples, and the average across all possible 7-second intervals will be 108.5 samples.</p> <p>If you take a series of <em>contiguous</em> 7-second intervals, you'll find that the sample counts alternate between 108 and 109, again resulting in an average of 108.5.</p>