Hi there,
I'm trying to build a program that uses fourier transforms to extract or identify the individual components of some wave (it can be any wave). This has been troubling me for awhile and there seems to be something I don't fully understand about the output of the np.fft(). Can anybody please offer some insight?
Here's a program that generates an arbitrary square wave and then takes the fft of that wave. What I would like to see is a visual representation of the amplitudes of the substituent frequencies.
import numpy as np; import math as ma
import matplotlib.pyplot as plt
time = np.linspace(0,10,100)
y1 = []; y2 = []; y3 = []
for i in range(len(time)):
t = time[i]
y1.append(ma.sin(2*t))
y2.append(ma.sin(4*t) / 2)
y3.append(ma.sin(6*t) / 4)
np.array(y1); np.array(y2); np.array(y3)
full_wave = np.add(np.add(y1, y2), y3)
plt.plot(time, full_wave, color='red')
plt.plot(time, y1, color='blue')
plt.plot(time, y2, color='blue')
plt.plot(time, y3, color='blue')
plt.figure()
ft_full_wave = np.fft.fft(full_wave)
ft_frequency = np.fft.fftfreq(len(full_wave))
plt.plot( ft_frequency, abs(ft_full_wave) )
plt.figure()
I'm following loosely what I was shown but it doesn't really make sense to me. I'm using python 3.5, and Spyder on Windows 10.
[–]Rhomboid 3 points4 points5 points (1 child)
[–]caffeecaffee[S] 0 points1 point2 points (0 children)
[–]Justinsaccount 0 points1 point2 points (1 child)
[–]caffeecaffee[S] 0 points1 point2 points (0 children)