Skip to content
Tactiverge

✦ Signal processing · discrete Fourier transform

Find the vibration frequency

Compute a DFT magnitude spectrum and report the dominant vibration frequency of a motor.

  • Level 5 · Research Engineer
  • 5 tests
  • technically checked

Your task

A motor's vibration sensor records N samples at fs samples per second. The discrete Fourier transform measures how much of each frequency is present. For bin k:

X_k = Σₙ x[n] · (cos(2πkn/N) − i·sin(2πkn/N)), and its magnitude is √(re² + im²).

Write:

  • dftMagnitudes(xs): magnitudes for k = 0 … floor(N/2).
  • dominantFrequency(xs, fs): the frequency in Hz (k × fs / N) of the largest magnitude, ignoring k = 0 (the constant offset).

Hints (0 of 3 shown)

    What gets checked

    • dftMagnitudes([0, 1, 1.224646799e-16, -1, -2.449293598e-16, 1, …) → [0, 0, 4, 0, 0]
    • dominantFrequency([0, 1, 1.224646799e-16, -1, -2.449293598e-16, 1, …, 8) → 2

    Plus 3 hidden tests for edge cases. They run in the sandbox like the others; only the result is shown.

    Tab indents · Esc then Tab leaves the editor · Ctrl/⌘ Enter runs · Ctrl/⌘ Shift Enter checks · Ctrl/⌘ / comments

    Starting the sandbox…

    Press Run to see what your program prints.

    Your code runs only in this browser, inside an isolated sandbox with no network access, and stops after 3 s. Nothing you type is sent to Tactiverge; drafts and progress are saved in this browser only.