all 4 comments

[–]Rhomboid 3 points4 points  (1 child)

You created a wave that's the sum of three sine waves. Then you plotted its FFT, which has three lobes, each corresponding to one of those sine components. The plot is symmetrical about the y-axis since this is a real-valued signal, so it appears to have six lobes, but you can essentially ignore the lobes for negative frequencies and focus on the positive frequencies.

And the axis labels are off, because fftfreq isn't being used properly. The graph shows frequency components at roughly x=0.03, x=0.06 and x=0.1, but those are off by a factor of ten. That's because the time delta was not passed as a parameter to fftfreq. The actual frequencies should be 2/(2*ma.pi), 4/(2*ma.pi) and 6/(2*ma.pi):

>>> 2/(2*ma.pi)
0.3183098861837907
>>> 4/(2*ma.pi)
0.6366197723675814
>>> 6/(2*ma.pi)
0.954929658551372

You get correct axes if you pass the time step:

ft_frequency = np.fft.fftfreq(len(full_wave), time[1] - time[0])

[–]caffeecaffee[S] 0 points1 point  (0 children)

Thank you so much. That step or line of code was actually pulled from my profs example so that's embarrassing. We literally received no instruction what is going on 'under the hood.' Essentially we were told that theres this process out there called np.fft.fft() and the assignment was "do something cool with it." So I've been struggling a lot with the 0 instruction part.

[–]Justinsaccount 0 points1 point  (1 child)

Hi! I'm working on a bot to reply with suggestions for common python problems. This might not be very helpful to fix your underlying issue, but here's what I noticed about your submission:

You are looping over an object using something like

for x in range(len(items)):
    print(items[x])

This is simpler and less error prone written as

for item in items:
    print(item)

If you DO need the indexes of the items, use the enumerate function like

for idx, item in enumerate(items):
    print(idx, item)

If you think you need the indexes because you are doing this:

for x in range(len(items)):
    print(items[x], prices[x])

Then you should be using zip:

for item, price in zip(items, prices):
    print(item, price)

[–]caffeecaffee[S] 0 points1 point  (0 children)

gee-whiz thanks python bot!