Problem 338068 · medium · Level 03 Linear Management & Searching

Is the Gearbox Logger Fast Enough?

sampling theorem · aliasing · Nyquist frequency · sets · sorting

A wind turbine's gearbox makes several tones at once (the shaft, each gear mesh, the bearings). An engineer knows their frequencies, tones, in whole hertz, and must choose the sample rate fs of a vibration logger.

The sampling theorem says that samples taken fs times per second hold everything about a signal whose tones are all below fs / 2. A tone at or above fs / 2 aliases: it shows up folded to the apparent frequency r or fs - r, where r = tone % fs (whichever lies between 0 and fs / 2), as in "The Propeller Hum the Logger Gets Wrong". Two different tones can then land on the same apparent frequency and become one peak.

Write rate_check(tones, fs) that returns a tuple:

  1. True if every tone is strictly below fs / 2, else False,
  2. the smallest whole-number sample rate that would make the first answer True (the smallest integer greater than twice the highest tone),
  3. the sorted list of the distinct apparent frequencies the logger's spectrum would show at fs.

Examples

Input:  tones = [50, 120, 300], fs = 1000
Output: (True, 601, [50, 120, 300])
Explanation: all three are below 500 Hz. Any rate above 600 samples per second would do.

Input:  tones = [50, 120, 300, 700], fs = 1000
Output: (False, 1401, [50, 120, 300])
Explanation: 700 Hz folds to 1000 - 700 = 300 Hz, on top of the real 300 Hz tone.

Input:  tones = [40, 80], fs = 80
Output: (False, 161, [0, 40])
Explanation: 40 Hz is exactly fs / 2, which is not enough (sampled at the zero crossings it
would read as silence). 80 Hz is sampled at the same point of its cycle each time and looks constant.

Constraints

  • every tone is a whole number of hertz; fs is a whole number

Goals

  • Apply the sampling theorem: every tone must lie below fs / 2
  • Find the smallest whole sample rate that captures every tone
  • Predict which peaks a too-slow logger shows, and which tones collide
Starting Python…