MFCC的滑动平均滤波实现代码
时间: 2023-03-14 22:15:34 浏览: 47
MFCC滑动平均滤波的实现代码如下:from scipy.signal import butter, lfilterdef butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, adef butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = lfilter(b, a, data)
return y
相关问题
二维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)