Python Forum

Full Version: Help using a pre-code for Discrete Fourier Transform
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

This is the pre-code I have

# Discrete Fourier Transform Fn
def dft(fk):
    Fn = []
    N = len(fk)
    for k in range(N):
        a = 0
        for n in range(N):
            a += fk[n]*np.exp(-2j*np.pi*k*n*(1/N))
        Fn.append(a)
    return Fn
# Inverse Discrete Fourier Transformation fk
def idft(Fn):
    fk = []
    N = len(Fn)
    for n in range(N):
        a = 0
        for k in range(N):
            a += Fn[k]*np.exp(2j*np.pi*k*n*(1/N))
        a /= N
        fk.append(a)
    return fk
I would like to use this code in a function x(t) = sin(w*t). My problem is that I do not know to define the time for the function. Also, I do not know how to plot the fourier transform, which will get me a plot with a delta in the frequency parameter w, which I can define.

Thanks in advance,