Skip to content
DeepForgeby svx
All problems
MediumCalculusca-174

DFT Leakage Lite

Problem

When a sinusoid lies delta bins away from an integer DFT bin, the peak bin magnitude of a rectangular window of length N is scaled by

L = |sin(pi*delta)| / (N * |sin(pi*delta / N)|)

Return L for N > 0 and delta >= 0, with L = 1.0 when delta is exactly 0.

Hint

This is the Dirichlet kernel magnitude divided by N; it decays away from integer bins.

Test cases

case 1
in: [8,0]
expected: 1
case 2
in: [8,0.5]
expected: 0.6407288619353766
case 3
in: [16,1]
expected: 0
case 4
in: [4,0.25]
expected: 0.9061274463528879
Starter codePython
def dft_leakage(n, delta):
    # Your code here
    pass

4 test cases · run your code against them in the editor