In [12]:
import numpy as np
import scipy
import matplotlib.pyplot as plt
import math

In [66]:
# General wave formula -> x(t) = A cos(wt + theta)
# A -> Amplitude
# w -> Angular Frequency -> ordinal frequency = 2*(pi)*(ordinal frequency) 
# theta -> Phase

def xTWave(freq, time_step, amplitude=1, phase=0):
    return amplitude * math.cos((2 * math.pi * freq * time_step) + phase)

In [95]:
# Let's sample at 7K Hz. for 2 seconds
samples_x = [(x / 7000.0) for x in range(7000)]
samples_y = [xTWave(10, x) for x in samples_x]

In [96]:
plt.plot(samples_x, samples_y)
plt.show()



In [106]:
from scipy.signal import hamming, convolve

samples_x = [(x / 700.0) for x in range(700)]
samples_y = [xTWave(100, x) for x in samples_x]

# Let's plot the fourier transform
y_fft = scipy.fft(samples_y)

x_fft = np.linspace(0, 350 ,350)

plt.plot(x_fft, 2.0/700 * np.abs(y_fft[0:700//2]))
plt.show()

final_y = 2.0/700 * np.abs(y_fft[0:700//2])
print(final_y.argmax())
print(y_fft.argmax())


100
100

In [90]:
from scipy.fftpack import fft
# Number of sample points
N = 1000
# sample spacing
T = 1.0 / 1000.0
x = np.linspace(0.0, N*T, N)
y = np.sin(50.0 * 2.0*np.pi*x)
yf = fft(y)
xf = np.linspace(0.0, 1.0/(2.0*T), N//2)
import matplotlib.pyplot as plt
plt.plot(xf, 2.0/N * np.abs(yf[0:N//2]))
plt.grid()
plt.show()



In [110]:
import time
import sys
for i in range(100):
    sys.stdout.write("Download progress: %d%%   \r" % (i) )
    sys.stdout.flush()
    time.sleep(0.1)


Download progress: 99%   

In [ ]: