def draw_440Hz_fft_fast(x, min_f, max_f, skip): global sample_N global f_s f_int = f_s / sample_N min_range = round(min_f / f_int) max_range = round(max_f / f_int) + 1 fft_buffer = [None] * sample_N #0-99 fft_buffer = (' '.join("%5.3f" % abs(f) for f in fft(x))) fft_buffer = fft(x) tft.fillrect((60, 0), (tft.size()[0], tft.size()[1] - (sysfont["Height"] * 2)), TFT.BLACK) v = sysfont["Height"] for i in range(min_range, max_range, skip): if round(abs(fft_buffer[i])) <= 0.5: color = TFT.GREEN elif round(abs(fft_buffer[i])) <= 1: color = TFT.YELLOW else: color = TFT.RED tft.fillrect((60, v), ((round(abs(fft_buffer[i] * 50))), sysfont["Height"]), color) v += sysfont["Height"]
def draw_440Hz_fft(x): global sample_N global f_s f_int = f_s / sample_N min_range = round(415 / f_int) max_range = round(475 / f_int) + 1 fft_buffer = [None] * sample_N #0-99 fft_buffer = (' '.join("%5.3f" % abs(f) for f in fft(x))) fft_buffer = fft(x) tft.fill(TFT.BLACK) v = 0 fft_print = "FFT:" tft.text((0, v), fft_print, TFT.WHITE, sysfont, 1) v += sysfont["Height"] color = TFT.RED for i in range(min_range, max_range): freq = i * (f_s / sample_N) fft_print = "Freq:%4.0f" % (freq) tft.text((0, v), fft_print, TFT.WHITE, sysfont, 1) if round(abs(fft_buffer[i])) <= 0.5: color = TFT.GREEN elif round(abs(fft_buffer[i])) <= 1: color = TFT.YELLOW else: color = TFT.RED tft.fillrect((60, v), ((round(abs(fft_buffer[i] * 50))), sysfont["Height"]), color) v += sysfont["Height"]
def fft(x): N = len(x) if N <= 1: return x even = fft(x[0::2]) odd = fft(x[1::2]) T = [exp(-2j * pi * k / N) * odd[k] for k in range(N // 2)] return [even[k] + T[k] for k in range(N//2)] + \ [even[k] - T[k] for k in range(N//2)]
def print_sel_fft(x): global sample_N global f_s #print( ' '.join("%5.3f" % abs(f) for f in fft([1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0])) ) #a = [None] * 16 #a = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] fft_buffer = [None] * sample_N #0-99 fft_buffer = (' '.join("%5.3f" % abs(f) for f in fft(x))) #print(fft_buffer) fft_buffer = fft(x) for i in range(5, 15): freq = i * (f_s / sample_N) print("Freq: %6.1f Val: %5.3f" % (freq, abs(fft_buffer[i])))
def resize_image(image, factor): image = zero_seperate(image) new_image = [] for row in image: vec = [1] * factor + [0] * (len(row) - factor) new_row = ifft(hadamard(fft(row), fft(vec))) new_image.append(new_row) image = transpose(new_image) new_image = [] for col in image: vec = [1] * factor + [0] * (len(col) - factor) new_col = ifft(hadamard(fft(col), fft(vec))) new_image.append(new_col) image = transpose(new_image) return convert_int(image)
def fft_analyze_cam(camlist, cal_list, filename=None): if filename is None: # data = E200.E200_load_data(filename='nas/nas-li20-pm00/E200/2015/20150602/E200_17712/E200_17712.mat') data = E200.E200_load_data_gui() else: data = E200.E200_load_data(filename) num_cams = np.size(camlist) blobs = np.empty(num_cams, dtype=object) # ipdb.set_trace() for i, (cam, cal) in enumerate(zip(camlist, cal_list)): # ====================================== # UIDs in common # ====================================== imgstr = getattr(data.rdrill.data.raw.images, cam) uids = imgstr.UID uids_wanted = uids[uids > 1e5] blobs[i] = BlobAnalysis(imgstr, imgname=cam, cal=cal, reconstruct_radius=1, uids=uids_wanted) # this = np.append(blob.centroid.transpose(), [blob._timestamps], axis=0) # np.savetxt('series_{}.csv'.format(cam), this.transpose(), delimiter=', ') # ipdb.set_trace() freq = data.rdrill.data.raw.metadata.E200_state.EVNT_SYS1_1_BEAMRATE.dat[0] fig = fft(blobs, camlist, freq=freq) # NOQA plt.show()
def print_440Hz_fft(x): global sample_N global f_s f_int = f_s / sample_N min_range = round(415 / f_int) max_range = round(475 / f_int) + 1 fft_buffer = [None] * sample_N #0-99 fft_buffer = (' '.join("%5.3f" % abs(f) for f in fft(x))) fft_buffer = fft(x) tft.fill(TFT.BLACK) v = 0 fft_print = "FFT:" tft.text((0, v), fft_print, TFT.WHITE, sysfont, 1) v += sysfont["Height"] for i in range(min_range, max_range): freq = i * (f_s / sample_N) fft_print = "Freq:%3.0f Val:%2.2f" % (freq, abs(fft_buffer[i])) tft.text((0, v), fft_print, TFT.WHITE, sysfont, 1) v += sysfont["Height"]
import matplotlib.pyplot as plt import numpy as fft import numpy as np from scipy.fftpack import fft noise_size = 1400 noise_array = np.random.normal(0, 2, noise_size) adc_value = [] for i in range(noise_size): adc_value.append(0) y = np.array(adc_value) + noise_array yy = fft(y) #快速傅里叶变换 yf = abs(fft(y)) # 取模 yf1 = abs(fft(y)) / ((len(y) / 2)) #归一化处理 yf2 = yf1[range(int(len(y) / 2))] #由于对称性,只取一半区间 #混合波的FFT(双边频率范围) xf = np.arange(len(y)) plt.figure(1) plt.plot(xf, yf, 'r') #显示原始信号的FFT模值 plt.title('FFT of Mixed wave(two sides frequency range)', fontsize=7, color='#7A378B') #注意这里的颜色可以查询颜色代码表 yy = fft(y) #快速傅里叶变换 yreal = yy.real # 获取实数部分 yimag = yy.imag # 获取虚数部分 test_y = yy
def test_fft_0(self): y = fft(fft_test.x_ref) for i in range(8): self.assertAlmostEqual(y[i], fft_test.y_ref[i], 4)
def test_fft_and_dft_return_the_same(self): n = 64 x = rnd_data(n) y0, y1 = dft(x), fft(x) for i in range(n): self.assertAlmostEqual(y0[i], y1[i], 5)