Python Forum
What am I doing wrong with this FFT?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What am I doing wrong with this FFT?
#5
(Jul-28-2022, 01:50 PM)Gribouillis Wrote:
(Jul-28-2022, 09:57 AM)pyhill00 Wrote: Do you know by chance why the FFT amplitudes are the not the same for the four?
I think it is the same effect. If you take the DFT of x[k] = exp(2 pi i k / N), you get spikes that all have the same amplitude, but if you take the DFT of x[k] = exp(i omega k) where omega is not a multiple of 2 pi / N, you get a "smooth spike" which amplitude varies. You can actually compute the DFT by hand and get a closed formula for the result and you will see that the amplitude varies. The conserved quantity is the L^2 norm (Plancherel theorem), not the maximal amplitude.



Ah ok thank you I will look into it. Last issue I am having (and the biggest issue) is that I cannot distinguish the frequencies I have in the code below. Is there a way to distinguish the peaks without changing the tmax time of 1.76 and the frequencies?

    import numpy as np
    import scipy.fftpack
    from scipy.fftpack import fftfreq
    from scipy.fft import fft
    import matplotlib.pyplot as plt


    t = np.linspace(0,1.76,2400) 
    f = [400e-3, 500e-3, 600e-3, 700e-3] # these are the frequencies
    yy = 0

    for i in f:
        y = 0.5*np.cos(2*np.pi*i*t)
        yy = yy + y

    plt.figure(0)
    plt.plot(t, yy)


    f = fftfreq(len(t), np.diff(t)[0])
    yf = fft(yy)
    plt.figure(1)
    plt.plot(f[:t.size//2], np.abs(yf[:t.size//2]))
    plt.show()
Reply


Messages In This Thread
What am I doing wrong with this FFT? - by pyhill00 - Jul-27-2022, 09:50 PM
RE: What am I doing wrong with this FFT? - by pyhill00 - Jul-28-2022, 02:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 3,027 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  python gives wrong string length and wrong character thienson30 2 3,170 Oct-15-2019, 08:54 PM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020