fft_integerVsfloat.py
50 lines
| 889 B
| text/x-python
|
PythonLexer
/ SRC / fft_integerVsfloat.py
|
r0 | import math | ||
import numpy as np | ||||
from bin16 import * | ||||
from fft import * | ||||
import matplotlib.pyplot as plt | ||||
alfa = 8192.0/8000.0 | ||||
t_i = 0.0*alfa | ||||
t_f = 8.0*alfa | ||||
t_a = 3.5*alfa | ||||
t_b = 4.5*alfa | ||||
time_step = 1.0/1000 | ||||
time_vec = np.arange(t_i,t_f,time_step) | ||||
Afloat = np.zeros(len(time_vec)) | ||||
for i in range(int(t_a/time_step),int(t_b/time_step)): | ||||
Afloat[i] = 1.0 | ||||
# plt.figure(1) | ||||
# plt.plot(time_vec,Afloat,'r') | ||||
# plt.ylim(0,2) | ||||
# plt.show() | ||||
Afloat_FFT = np.fft.fft(Afloat)/len(time_vec) | ||||
# plt.figure(2) | ||||
# plt.plot(abs(Afloat_FFT[0:100]),'g') | ||||
# plt.show() | ||||
Aint = np.zeros(len(time_vec)) | ||||
for i in range(len(time_vec)): | ||||
Aint[i] = quant16(Afloat[i],-2,+2) | ||||
# 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() | ||||