MFCC的滑动平均滤波实现代码
时间: 2023-03-14 08:09:35 浏览: 43
MFCC滑动平均滤波实现的代码可以参考如下:import numpy as npdef sliding_mean_filter(data, window_size):
"""Applies a sliding mean filter to a given input data array.
Args:
data (np.array): 1-dimensional input data array.
window_size (int): Size of the sliding window.
Returns:
np.array: Filtered data array.
"""
cumsum = np.cumsum(np.insert(data, 0, 0))
return (cumsum[window_size:] - cumsum[:-window_size]) / window_size
相关问题
二维MFCC的滑动平均滤波实现代码
二维MFCC滑动平均滤波实现的代码可以参考下面的示例:
```
import numpy as np# Define the size of the sliding window
window_size = 32# Create an array of zeros to hold the sliding window
sliding_window = np.zeros(window_size)# Step through the MFCC array
for i in range(len(mfcc)):
# Add the current sample to the end of the sliding window
sliding_window[:-1] = sliding_window[1:]
sliding_window[-1] = mfcc[i]
# Calculate the average value of the sliding window
avg = np.mean(sliding_window)
# Output the filtered value
filtered_mfcc[i] = avg
```
MFCC的PCA降维实现代码
以下是使用Python的scikit-learn库实现MFCC的PCA降维代码:
```python
import numpy as np
import librosa
from sklearn.decomposition import PCA
# Load audio file
audio_file = 'sample.wav'
y, sr = librosa.load(audio_file)
# Compute MFCCs
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
# PCA dimensionality reduction
pca = PCA(n_components=10)
mfccs_pca = pca.fit_transform(mfccs.T)
print(mfccs_pca.shape)
```
上述代码首先使用librosa库加载音频文件,并计算出它的MFCC系数。然后,使用scikit-learn库中的PCA类,将MFCC系数降至10维。最后,输出降维后的MFCC系数形状。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)