回答編集履歴
1
追加
test
CHANGED
@@ -13,3 +13,119 @@
|
|
13
13
|
```
|
14
14
|
|
15
15
|
の書き間違いではありませんか。
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
検証はしていませんが、以下のような感じで書けるはずです。
|
20
|
+
|
21
|
+
日本語のフォントの指定が必要ですので適当に入れてください。
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
```python
|
26
|
+
|
27
|
+
import numpy as np
|
28
|
+
|
29
|
+
import pandas as pd
|
30
|
+
|
31
|
+
import os
|
32
|
+
|
33
|
+
import matplotlib.pyplot as plt
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
file_name = input("Please input filename:")
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
Sampling_frequency = int(input("Please input Sampling_frequency: "))
|
42
|
+
|
43
|
+
Number_of_iterations = int(input("Please input Number_of_iterations:"))
|
44
|
+
|
45
|
+
color_list=["black","gray","lightcoral","brown","darkred","red","tomato","sienna","sandybrown","darkorange","tan","gold","darkkhaki"
|
46
|
+
|
47
|
+
,"yellowgreen","olivedrab","darkturquoise","lightblue"
|
48
|
+
|
49
|
+
,"steelblue","cornflowerblue","navy","blue","indigo","darkviolet","purple","magenta","crimson","lightpink"]
|
50
|
+
|
51
|
+
data=pd.read_csv(os.path.join(r"Z:/private/",file_name),header=None,usecols=list(range(1,n+1)),names=[f"{n}回目" for n in range(1,n+1)])
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
#データ数
|
56
|
+
|
57
|
+
N=len(data)
|
58
|
+
|
59
|
+
#サンプリング周波数
|
60
|
+
|
61
|
+
fs=Sampling_frequency
|
62
|
+
|
63
|
+
#窓関数
|
64
|
+
|
65
|
+
window=np.hamming(N)
|
66
|
+
|
67
|
+
#窓関数の補正値
|
68
|
+
|
69
|
+
acf=(1/(sum(window)/N))
|
70
|
+
|
71
|
+
#時間軸のデータ作成
|
72
|
+
|
73
|
+
t=np.arange(0,N*(1/fs),1/fs)
|
74
|
+
|
75
|
+
#周波数軸のデータ作成
|
76
|
+
|
77
|
+
fq=np.linspace(0,fs,N) #周波数軸 linspace(開始,終了,分割数)
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
fig = plt.figure(figsize=(6,4))
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
#for j in range(0,colorlist):
|
86
|
+
|
87
|
+
for n in range(1,Number_of_iterations+1):
|
88
|
+
|
89
|
+
# for j in range(0,Number_of_iterations+1):
|
90
|
+
|
91
|
+
#2次元配列から1次元配列に変更
|
92
|
+
|
93
|
+
data2=data[str(n)+"回目"].values
|
94
|
+
|
95
|
+
#窓関数後の信号
|
96
|
+
|
97
|
+
data_w=window*data2
|
98
|
+
|
99
|
+
#読み込んだデータをフーリエ変換
|
100
|
+
|
101
|
+
data_w_FFT=np.fft.fft(data_w)
|
102
|
+
|
103
|
+
#FFTの複素数結果を絶対値に変換
|
104
|
+
|
105
|
+
data_w_FFT_abs=abs(data_w_FFT)
|
106
|
+
|
107
|
+
#窓補正
|
108
|
+
|
109
|
+
Data=(data_w_FFT_abs)*acf
|
110
|
+
|
111
|
+
plt.plot(fq[:int(N/2)+1],Data[:int(N/2)+1],color=color_list[n],label=str(n)+"回目")
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
plt.xlabel("frequency[Hz]",fontsize=14)
|
116
|
+
|
117
|
+
plt.ylabel("signal intensity",fontsize=14)
|
118
|
+
|
119
|
+
#plt.xlim(0,2000)
|
120
|
+
|
121
|
+
plt.xlim(0,2)
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
ax = fig.add_subplot(111)
|
126
|
+
|
127
|
+
ax.legend()
|
128
|
+
|
129
|
+
plt.show()
|
130
|
+
|
131
|
+
```
|