質問編集履歴

3

誤字の変更

2020/11/02 06:25

投稿

yamasandayo
yamasandayo

スコア6

test CHANGED
File without changes
test CHANGED
@@ -66,4 +66,4 @@
66
66
 
67
67
  plt.yscale('log')
68
68
 
69
- plt.show()
69
+ plt.show()'''

2

誤字の変更

2020/11/02 06:25

投稿

yamasandayo
yamasandayo

スコア6

test CHANGED
File without changes
test CHANGED
@@ -8,18 +8,62 @@
8
8
 
9
9
  ```python
10
10
 
11
+ #
12
+
11
- import numpy as np
13
+ import numpy as np #added by author
14
+
15
+ from scipy import signal
12
16
 
13
17
  import matplotlib.pyplot as plt
14
18
 
15
- import scipy.stats as sp
16
19
 
17
- import math
18
20
 
19
- from scipy import signal
21
+ #Generate a test signal, a 2 Vrms sine wave at 50Hz corrupted by 0.001 V**2/Hz of white noise sampled at 1024 Hz.
22
+
23
+ #テスト信号、1024 Hzでサンプリングされた0.001 V ** 2 / Hzのホワイトノイズで破損した50 Hzの2 Vrmsの正弦波を生成します
20
24
 
21
25
 
22
26
 
27
+ fs = 1024
28
+
29
+ N = 10*fs
30
+
31
+ nperseg = 512
32
+
33
+ amp = 2 * np.sqrt(2)
34
+
35
+ noise_power = 0.001 * fs / 2
36
+
37
+ time = np.arange(N) / float(fs)
38
+
39
+ carrier = amp * np.sin(2*np.pi*50*time)
40
+
41
+ noise = np.random.normal(scale=np.sqrt(noise_power),
42
+
43
+ size=time.shape)
44
+
45
+ x = carrier + noise
46
+
47
+ #Compute and plot the STFT’s magnitude.
48
+
49
+ #STFTの振幅を計算してプロットします
23
50
 
24
51
 
52
+
25
- ![イメージ説明](97b076a004c1896f470ddf39a7a34f70.png)
53
+ f, t, Zxx = signal.stft(x, fs=fs, nperseg=nperseg)
54
+
55
+ plt.figure()
56
+
57
+ plt.pcolormesh(t, f, np.abs(Zxx), vmin=0, vmax=amp)
58
+
59
+ plt.ylim([f[1], f[-1]])
60
+
61
+ plt.title('STFT Magnitude')
62
+
63
+ plt.ylabel('Frequency [Hz]')
64
+
65
+ plt.xlabel('Time [sec]')
66
+
67
+ plt.yscale('log')
68
+
69
+ plt.show()

1

誤字の変更

2020/11/02 06:24

投稿

yamasandayo
yamasandayo

スコア6

test CHANGED
File without changes
test CHANGED
@@ -20,96 +20,6 @@
20
20
 
21
21
 
22
22
 
23
- H, N, eta, frame, shift = 512, 81920, 0.002, 512, 256
24
-
25
- #タップ数、データ点数、ステップサイズ、フレームサイズ、フレームシフト
26
-
27
- M, T, C, fs, c = 319, 1500, 30, 16000., 340.
28
-
29
- #分割数、更新回数、第c周波数成分、サンプリング周波数、音速
30
23
 
31
24
 
32
-
33
-
34
-
35
- s1 = np.loadtxt('../data/a27.txt') #データの読み込み
36
-
37
- s2 = np.loadtxt('../data/a04.txt')
38
-
39
- s = np.array([[0 for i in range(N)] for j in range(2)],dtype=float)
40
-
41
- for i in range(N):
42
-
43
- if i < 80000:
44
-
45
- s[0][i] = s1[i]
46
-
47
- s[1][i] = s2[i]
48
-
49
- s[0] = sp.zscore(s[0]) #原信号の正規化
50
-
51
- s[1] = sp.zscore(s[1])
52
-
53
- print("読み込み完了\nインパルス応答の作成\n...")
54
-
55
-
56
-
57
- vc1 = np.convolve(s[0],A[0][0].real) + np.convolve(s[1],A[0][1].real)
58
-
59
- vc2 = np.convolve(s[0],A[1][0].real) + np.convolve(s[1],A[1][1].real)
60
-
61
- vc = np.array([[0 for i in range(2048)] for j in range(2)],dtype=complex)
62
-
63
- for i in range(2048):
64
-
65
- vc[0][i] = vc1[i]
66
-
67
- vc[1][i] = vc2[i]
68
-
69
-
70
-
71
- print("終了\nインパルス応答のフーリエ変換\n...")
72
-
73
- for i in range(2):
74
-
75
- for j in range(2):
76
-
77
- A[i][j] = np.fft.fft(A[i][j])
78
-
79
-
80
-
81
- print("終了\n短時間フーリエ変換\n...")
82
-
83
- #frequency, segment time, STFT of x
84
-
85
- frq1, t1, x1 = signal.stft(vc[0],fs=fs,nperseg=frame)
86
-
87
- frq2, t2, x2 = signal.stft(vc[1],fs=fs,nperseg=frame)
88
-
89
-
90
-
91
- fig = plt.figure()
92
-
93
- ax1 = fig.add_subplot(4,1,1)
94
-
95
- ax2 = fig.add_subplot(4,1,2)
96
-
97
- #ax3 = fig.add_subplot(4,1,3)
98
-
99
- #ax4 = fig.add_subplot(4,1,4)
100
-
101
- ax1.plot(np.abs(x1))
102
-
103
- ax2.plot(t1)
104
-
105
- #ax3.plot(frq1)
106
-
107
- #ax4.plot(x1[3])
108
-
109
- fig.tight_layout()
110
-
111
- plt.show()
112
-
113
- ```
114
-
115
25
  ![イメージ説明](97b076a004c1896f470ddf39a7a34f70.png)