Skip to content

Commit 32852b4

Browse files
committed
4章前半を追加
1 parent 4a92efb commit 32852b4

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

khashimoto/chapter04/q01.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,27 @@
55

66
def zeropad(L, S, x):
77
zero1 = np.zeros(L - S)
8-
x_pad = np.concatenate([zero1, x, zero1]) # 1.
8+
# x_pad = np.concatenate([zero1, x, zero1]) # 1.
9+
x_pad = np.concatenate([zero1, x])
910
zero2 = x_pad.size % S
1011
if zero2 != 0:
1112
x_pad = np.concatenate([x_pad, np.zeros(S - zero2)]) # 2.
13+
x_pad = np.concatenate([x_pad, np.zeros(L - S)])
1214
return x_pad
1315

1416

1517
"""
1618
# 確認
1719
x = np.ones(5)
1820
print(x)
19-
x_pad = zeropad(4, 3, x)
21+
x_pad = zeropad(4, 2, x)
2022
print(x_pad)
2123
2224
2325
# [1. 1. 1. 1. 1.]
2426
# [0. 1. 1. 1. 1. 1. 0. 0. 0.]
27+
28+
# [1. 1. 1. 1. 1.]
29+
# [0. 0. 1. 1. 1. 1. 1. 0. 0. 0.]
30+
# 不足分が出ないように零詰め
2531
"""

khashimoto/chapter04/q02.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def frame(L, S, x):
1818
# 確認
1919
x = np.ones(5)
2020
print(x)
21-
x_2 = frame(4, 3, x)
21+
print(zeropad(4, 2, x))
22+
x_2 = frame(4, 2, x)
2223
print(x_2)
2324
2425

khashimoto/chapter04/q04.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818

1919
# プロット
20-
T = np.arange(len(x_stft)) * 0.1 # 時間軸
20+
T = np.arange(len(x_stft)) # 時間軸
2121
fr = np.arange(x_stft.shape[1]) / x_stft.shape[1] * fs / 2 # 周波数軸
2222

2323
plt.subplot(1, 2, 1)

khashimoto/chapter04/q05.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# 合成窓
22

33
import numpy as np
4+
import matplotlib.pyplot as plt
45

56

67
def window(S, w):
@@ -18,8 +19,10 @@ def window(S, w):
1819

1920
"""
2021
# 確認
21-
w = np.ones(6)
22-
print(window(2, w))
22+
L = 1024
23+
w = 0.54 - 0.46 * np.cos(2 * np.pi * np.arange(L) / (L - 1)) # Hamming窓
24+
plt.plot(window(256, w))
25+
plt.show()
2326
2427
2528
# [0.33333333 0.33333333 0.33333333 0.33333333 0.33333333 0.33333333]

0 commit comments

Comments
 (0)