import matplotlib.pyplot as plt from bin16 import * from fft import * import math #These are the first parameters for choosing the time step of our vector fs = 98304 time_step = 1.0/fs t_ini = 0 t_fin = 0.25 time_vec = np.arange(t_ini, t_fin, time_step) #The two frequences we're going to use for our different signals f1 = 4000 f2 = 800 #This ensures me of getting the higher value of N who's a power of 2 and smaller than the length of the time_vec N = int(math.pow(2,int(math.log(len(time_vec),2)))) x1 = 0.5 * np.cos(2 * np.pi * f1 * time_vec) x2 = 0.5 * np.cos(2 * np.pi * f2 * time_vec) liminf = -1 limsup = +1 #This will take our float-number signals, who were going from -0.5 to 0.5 (they were all sines), and quantize them into integers going from -32768 to 32767 #The liminf and limsup is what decides the maximum and minimum values for our quantizations #quant16 is a function from the bin16 library for i in range(len(time_vec)): x1[i] = quant16(x1[i],liminf,limsup) x2[i] = quant16(x2[i],liminf,limsup) #Now we obtain the values for the Fourier Transforms of both signals, with integer values as well (rounded in the function fft_CT) X1 = fft_CT(x1[0:N]) X2 = fft_CT(x2[0:N]) plt.figure(1) plt.plot(abs(X1),'r') plt.plot(abs(X2),'g') plt.show()