|
|
import math
|
|
|
import numpy as np
|
|
|
from bin16 import *
|
|
|
from fft import *
|
|
|
import matplotlib.pyplot as plt
|
|
|
|
|
|
nb_points = 256
|
|
|
nb_periods = 10
|
|
|
amplitude = 1000
|
|
|
|
|
|
time_vec = np.arange(0, nb_points, 1)
|
|
|
teta = nb_periods * time_vec * 2 * np.pi/ nb_points
|
|
|
|
|
|
Afloat = 10000 * np.sin( teta )
|
|
|
|
|
|
Aint = np.zeros(len(time_vec))
|
|
|
for i in range(len(time_vec)):
|
|
|
Aint[i] = quant16( Afloat[i], -pow(2,16)/2, +pow(2,16)/2 )
|
|
|
|
|
|
plt.figure(1)
|
|
|
plt.plot(time_vec,Afloat,'b.')
|
|
|
plt.plot(time_vec,Aint,'r.')
|
|
|
plt.show()
|
|
|
|
|
|
Afloat_FFT = np.fft.fft(Afloat)/len(time_vec)
|
|
|
|
|
|
# plt.figure(2)
|
|
|
# plt.plot(abs(Afloat_FFT[0:100]),'g')
|
|
|
# plt.show()
|
|
|
|
|
|
# plt.figure(3)
|
|
|
# plt.plot(time_vec,Aint,'r')
|
|
|
# plt.show()
|
|
|
|
|
|
Aint_FFT = fft_CT(Aint)
|
|
|
|
|
|
plt.figure(4)
|
|
|
plt.plot(abs(Afloat_FFT[0:100]),'g')
|
|
|
plt.scatter(range(100),1.0 * abs(Aint_FFT[0:100])/16384)
|
|
|
plt.title("Comparing the FFT's")
|
|
|
plt.show()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|