-1

Suppose we have sinusoidal with frequency 100Hz and sampling frequency of 1000Hz. It means that our signal has 100 periods in a second and we are taking 1000 samples in a second. Therefore, in order to select a complete period I'll have to take fs/f=10 samples. Right? What if the sampling period is not a multiple of the frequency of the signal (like 550Hz)? Do I have to find the minimum multiple M of f and fs, and than take M samples? My goal is to select an integer number of periods in order to be able to replicate them without changes.

SleuthEye
  • 13,074
  • 2
  • 28
  • 56
user1315621
  • 1,928
  • 5
  • 27
  • 48
  • Not a programming question - try http://dsp.stackexchange.com ? – Paul R Mar 02 '17 at 15:18
  • I'm voting to close this question as off-topic because it's about [dsp.se] instead of directly about programming or coding. – Pang Mar 03 '17 at 02:22

2 Answers2

1

You have f periods a second, and fs samples a second.

If you take M samples, it would cover M/fs part of a second, or P = f * (M/fs) periods. You want this number to be integer.

So you need to take M = fs / gcd(f, fs) samples.

For your example P = 1000 / gcd(100, 1000) = 1000 / 100 = 10.

If you have 60 Hz frequency and 80 Hz sampling frequency, it gives P = 80 / gcd(60, 80) = 80 / 20 = 4 -- 4 samples will cover 4 * 1/80 = 1/20 part of a second, and that will be 3 periods.

If you have 113 Hz frequency and 512 Hz sampling frequency, you are out of luck, since gcd(113, 512) = 1 and you'll need 512 samples, covering the whole second and 113 periods.

avysk
  • 1,883
  • 10
  • 17
0

In general, an arbitrary frequency will not have an integer number of periods. Irrational frequencies will never even repeat ever. So some means other than concatenation of buffers one period in length will be needed to synthesize exactly periodic waveforms of arbitrary frequencies. Approximation by interpolation for fractional phase offsets is one possibility.

hotpaw2
  • 68,014
  • 12
  • 81
  • 143