python 分帧 加窗
时间: 2023-10-11 19:07:18 浏览: 133
基于matlab实现语音分帧与加窗
在Python中,进行信号分帧加窗的常用方法有两种。第一种方法是使用Matplotlib库中的stem函数进行可视化绘制,如下所示:
```
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.family'] = ['sans-serif']
plt.rcParams['font.sans-serif'] = ['SimHei']
N = 32
nn = [i for i in range(N)]
plt.subplot(3, 1, 1)
plt.stem(np.ones(N))
plt.title('(a)矩形窗')
w = 0.54 - 0.46 * np.cos(np.multiply(nn, 2 * np.pi) / (N - 1))
plt.subplot(3, 1, 2)
plt.stem(w)
plt.title('(b)汉明窗')
w = 0.5 * (1 - np.cos(np.multiply(nn, 2 * np.pi) / (N - 1)))
plt.subplot(3, 1, 3)
plt.stem(w)
plt.title('(c)海宁窗')
plt.savefig('images/window.png')
plt.close()
```
第二种方法是使用scipy库中的signal模块进行窗函数的生成和绘制,如下所示:
```
import matplotlib.pyplot as plt
import scipy.signal as signal
plt.figure(figsize=(6,2))
plt.plot(signal.hanning(512))
plt.grid()
plt.show()
```
以上是两种常见的Python代码示例,用于进行信号分帧加窗操作。这些代码可以帮助您实现信号处理中对信号进行窗函数处理的需求。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Python语音基础操作--3.1语音分帧与加窗](https://blog.csdn.net/sinat_18131557/article/details/105340416)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [python对语音信号读取、分帧、加窗](https://blog.csdn.net/YAOHAIPI/article/details/102826051)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文