Python
1def fft(data, N, fs, fc1, fc2, numtaps): 2 spectrum_list = [] 3 freq01_list = [] 4 dt = 1 / fs # サンプリング間隔 5 t = np.arange(0, N*dt, dt) # 時間軸 6 nyq = 1 / (2*dt) # ナイキスト周波数 7 freq = np.linspace(0, 1.0/dt, N) # 周波数軸 8 9 b = scipy.signal.firwin(numtaps, [fc1, fc2], pass_zero=False, nyq=nyq) 10 11 # scipyによるFIRフィルタ 12 data = scipy.signal.lfilter(b, 1, data) 13 14 sample_freq = fftpack.fftfreq(data.size, d=dt) # Hz:フーリエ変換の横軸 15 data_fft = fftpack.fft(data) # フーリエ変換 16 s_power = np.abs(data_fft) 17 pidxs = np.where(sample_freq > 0) # プラスだけ抽出 18 freqs, power = sample_freq[pidxs], np.abs(data_fft)[pidxs] 19 freq_list = freq[23:146:4] 20 spe = s_power[23:146:4] # 特徴量 21 22 theta01 = s_power[22:36] 23 alpha01 = s_power[45:55] 24 beta01 = s_power[78:94] 25 26 spectrum = [theta01,alpha01,beta01] 27 28 return(spectrum) 29 30def show_selection(x, y): 31 for i in lb.curselection(): 32 if i == 0: 33 one = sum(x) 34 zero = len(x) - sum(x) 35 if one < zero: 36 label.config(text="OK") 37 elif i == 1: 38 one = sum(y) 39 zero = len(y) - sum(y) 40 if one > zero: 41 label.config(text="BAD") 42 43if __name__ == '__main__': 44 root = Tk() 45 root.title('Scrollbar 1') 46 47 # Frame 48 frame1 = ttk.Frame(root, padding=10) 49 frame1.grid() 50 51 # Listbox 52 currencies = ("A", "B") 53 v1 = StringVar(value=currencies) 54 lb = Listbox(frame1, listvariable=v1,height=3) 55 lb.grid(row=0, column=0) 56 57 # Label (新規追加) 58 label = Label(frame1, width=18) 59 label.grid(row=1, column=0, columnspan=2) 60 61 # Scrollbar 62 scrollbar = ttk.Scrollbar( 63 frame1, 64 orient=VERTICAL, 65 command=lb.yview) 66 lb['yscrollcommand'] = scrollbar.set 67 scrollbar.grid(row=0,column=1,sticky=(N,S)) 68 69 a = [0,0,0,0,1,1,1] 70 b = [1,1,1,1,1,0,0] 71 72 a = fft(a,len(a), 125, 4, 30, 255) 73 74 #Button 75 button1 = ttk.Button(frame1, text='OK', command=lambda: show_selection(a,b)) 76 button1.grid(row=2, column=0, columnspan=2) 77 78 root.mainloop()
以上のコードを実行すると、エラーがでました。
2017-12-15 17:20:20.425 python[27614:569403] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7fa882dd7da0 2017-12-15 17:20:20.433 python[27614:569403] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x7fa882dd7da0' *** First throw call stack: ( 0 CoreFoundation 0x00007fffb68a32cb __exceptionPreprocess + 171 1 libobjc.A.dylib 0x00007fffcb6bb48d objc_exception_throw + 48 2 CoreFoundation 0x00007fffb6924f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132 3 CoreFoundation 0x00007fffb6815755 ___forwarding___ + 1061 4 CoreFoundation 0x00007fffb68152a8 _CF_forwarding_prep_0 + 120 5 Tk 0x00000001019b1c02 TkpInit + 471 6 Tk 0x000000010192d2a9 Tk_Init + 1794 7 _tkinter.cpython-36m-darwin.so 0x0000000101806da4 Tcl_AppInit + 84 8 _tkinter.cpython-36m-darwin.so 0x0000000101806a7b _tkinter_create + 1115 9 libpython3.6m.dylib 0x00000001011014b1 _PyCFunction_FastCallDict + 497 10 libpython3.6m.dylib 0x00000001011831e7 call_function + 439 11 libpython3.6m.dylib 0x000000010117f992 _PyEval_EvalFrameDefault + 27346 12 libpython3.6m.dylib 0x0000000101183c4f _PyEval_EvalCodeWithName + 2447 13 libpython3.6m.dylib 0x0000000101184802 _PyFunction_FastCallDict + 738 14 libpython3.6m.dylib 0x00000001010b8cf7 _PyObject_FastCallDict + 247 15 libpython3.6m.dylib 0x00000001010b8e15 _PyObject_Call_Prepend + 149 16 libpython3.6m.dylib 0x00000001010b8b30 PyObject_Call + 96 17 libpython3.6m.dylib 0x000000010111959d slot_tp_init + 125 18 libpython3.6m.dylib 0x00000001011158d9 type_call + 313 19 libpython3.6m.dylib 0x00000001010b8cc5 _PyObject_FastCallDict + 197 20 libpython3.6m.dylib 0x00000001011830e8 call_function + 184 21 libpython3.6m.dylib 0x000000010117f992 _PyEval_EvalFrameDefault + 27346 22 libpython3.6m.dylib 0x0000000101183c4f _PyEval_EvalCodeWithName + 2447 23 libpython3.6m.dylib 0x0000000101178e04 PyEval_EvalCode + 100 24 libpython3.6m.dylib 0x00000001011aeab1 PyRun_FileExFlags + 209 25 libpython3.6m.dylib 0x00000001011ae263 PyRun_SimpleFileExFlags + 851 26 libpython3.6m.dylib 0x00000001011c70d9 Py_Main + 3529 27 python 0x00000001010a7df8 main + 232 28 libdyld.dylib 0x00007fffcbfa1235 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException Abort trap: 6
上記のエラーの内容がなにが間違っているのかわかりません。
fft関数をmainの中で実行しようとするとでてきます。
tkinterと関数を使うときは、注意しなければいけない点があるのでしょうか。
よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/18 06:59
2017/12/18 07:04
2017/12/18 07:06
2017/12/18 07:28
2017/12/18 07:35
2017/12/18 09:04
2017/12/18 09:08
2017/12/18 09:15
2017/12/18 14:08
2017/12/19 02:49
2017/12/19 08:42
2017/12/19 09:10
2017/12/19 11:12
2017/12/20 02:11