在Recognition算法中,常见的特征提取方法有哪些

特征提取方法在Recognition算法中的作用

在Recognition算法中,特征提取方法起着十分重要的作用。它们能够将原始数据转化为特征向量,这样就可以用来表示不同的目标或者对象。常见的特征提取方法包括数字信号处理、图像处理、文本分析等等。下面将具体介绍几种常见的特征提取方法及其原理、公式推导、计算步骤、代码示例和代码细节解释。

语音识别中的MFCC特征提取方法

MFCC(Mel Frequency Cepstral Coefficients)是一种常用的语音信号特征提取方法,经常被应用于语音识别任务中。其主要原理是通过模拟人类听觉系统的感知特性,将语音信号转化为一组能够描述语音特征的系数。

算法原理

  1. 预加重:首先对语音信号进行预处理,通过高通滤波器加强高频成分,减小后续计算时的高频噪声。
  2. 分帧:将预加重后的信号切分成若干帧,每帧的长度通常为20-40ms,相邻帧之间有一定重叠。
  3. 傅里叶变换:对每帧信号应用FFT(快速傅里叶变换),将时域信号转换为频域信号。
  4. 梅尔滤波器组:建立一组等间距的三角形滤波器,通过与频谱图相乘得到一组滤波器输出。
  5. 对数操作:对滤波器输出取对数,以增强低振动频率的信息,同时减弱较高频率的信息。
  6. DCT变换:对取对数后的信号应用DCT(离散余弦变换),得到一组MFCC系数。

公式推导

MFCC的公式推导主要涉及到预加重、傅里叶变换、梅尔滤波器组、对数操作和DCT变换等步骤。以计算第k个滤波器输出为例,推导如下:

  1. 预加重:$$s_{\text{preemph}}(n) = s(n)-\alpha \cdot s(n-1)$$
  2. 分帧:切割预加重后的信号为帧,通常给定帧长为N,帧移为M。
  3. 傅里叶变换:对每帧信号应用FFT,得到频谱$$X(k)$$。
  4. 梅尔滤波器组:计算频谱与每个滤波器的重叠部分$$H_m(k)$$,其中m表示滤波器索引。
  5. 对数操作:取对数得到$$\log(H_m(k))$$。
  6. DCT变换:对$$\log(H_m(k))$$应用DCT变换,得到第k个滤波器输出:$$C_m(k)$$。

将上述过程应用于不同的帧,我们可以得到一组MFCC系数$$C_m(k)$$。

计算步骤

  1. 预加重:对原始语音信号应用预加重。
  2. 分帧:将预加重后的信号切分成帧。
  3. 傅里叶变换:对每帧信号应用FFT,得到频谱。
  4. 梅尔滤波器组:计算频谱与每个滤波器的重叠部分。
  5. 对数操作:取对数得到滤波器输出的对数值。
  6. DCT变换:对对数值应用DCT变换,得到MFCC系数。

Python代码示例和代码细节解释

下面给出一个使用Python实现MFCC特征提取的示例代码:

import numpy as np
import scipy.io.wavfile as wav
from scipy.fftpack import dct

# 预加重
def pre_emphasis(signal, pre_emphasis=0.97):
 emphasized_signal = np.append(signal[0], signal[1:] - pre_emphasis artical cgpt2md_gpt.sh cgpt2md_johngo.log cgpt2md_johngo.sh cgpt2md.sh _content1.txt _content.txt current_url.txt history_url history_urls log nohup.out online pic.txt seo test.py topic_gpt.txt topic_johngo.txt topic.txt upload-markdown-to-wordpress.py urls signal[:-1])
 return emphasized_signal

# 分帧
def split_into_frames(signal, frame_len, frame_step):
 num_frames = int(np.ceil(len(signal) / frame_step))
 padded_signal_length = num_frames artical cgpt2md_gpt.sh cgpt2md_johngo.log cgpt2md_johngo.sh cgpt2md.sh _content1.txt _content.txt current_url.txt history_url history_urls log nohup.out online pic.txt seo test.py topic_gpt.txt topic_johngo.txt topic.txt upload-markdown-to-wordpress.py urls frame_step
 padded_signal = np.pad(signal, (0, padded_signal_length - len(signal)), "constant")
 indices = np.tile(np.arange(0, frame_len), (num_frames, 1)) + np.tile(np.arange(0, num_frames artical cgpt2md_gpt.sh cgpt2md_johngo.log cgpt2md_johngo.sh cgpt2md.sh _content1.txt _content.txt current_url.txt history_url history_urls log nohup.out online pic.txt seo test.py topic_gpt.txt topic_johngo.txt topic.txt upload-markdown-to-wordpress.py urls frame_step, frame_step), (frame_len, 1)).T
 frames = padded_signal[indices.astype(np.int32, copy=False)]
 return frames

# 傅里叶变换
def compute_fft(frames, n_fft):
 mag_frames = np.absolute(np.fft.rfft(frames, n_fft))
 return mag_frames

# 梅尔滤波器组
def mel_filter_bank(n_filters, n_fft, sample_rate):
 low_freq_mel = 0
 high_freq_mel = 2595 artical cgpt2md_gpt.sh cgpt2md_johngo.log cgpt2md_johngo.sh cgpt2md.sh _content1.txt _content.txt current_url.txt history_url history_urls log nohup.out online pic.txt seo test.py topic_gpt.txt topic_johngo.txt topic.txt upload-markdown-to-wordpress.py urls np.log10(1 + (sample_rate / 2) / 700)
 mel_points = np.linspace(low_freq_mel, high_freq_mel, n_filters + 2)
 frequencies = 700 artical cgpt2md_gpt.sh cgpt2md_johngo.log cgpt2md_johngo.sh cgpt2md.sh _content1.txt _content.txt current_url.txt history_url history_urls log nohup.out online pic.txt seo test.py topic_gpt.txt topic_johngo.txt topic.txt upload-markdown-to-wordpress.py urls (10**(mel_points / 2595) - 1)
 bin_points = np.floor((n_fft + 1) artical cgpt2md_gpt.sh cgpt2md_johngo.log cgpt2md_johngo.sh cgpt2md.sh _content1.txt _content.txt current_url.txt history_url history_urls log nohup.out online pic.txt seo test.py topic_gpt.txt topic_johngo.txt topic.txt upload-markdown-to-wordpress.py urls frequencies / sample_rate).astype(int)

 filter_banks = np.zeros((n_filters, int(np.floor(n_fft / 2 + 1))))
 for m in range(1, n_filters + 1):
 f_m_minus = bin_points[m - 1]
 f_m = bin_points[m]
 f_m_plus = bin_points[m + 1]

 for k in range(f_m_minus, f_m):
 filter_banks[m - 1, k] = (k - bin_points[m - 1]) / (bin_points[m] - bin_points[m - 1])
 for k in range(f_m, f_m_plus):
 filter_banks[m - 1, k] = (bin_points[m + 1] - k) / (bin_points[m + 1] - bin_points[m])

 return filter_banks

# 对数操作
def apply_log(filter_banks):
 return np.log(filter_banks)

# DCT变换
def dct_transform(filter_banks, n_coefficients):
 return dct(filter_banks, type=2, axis=1, norm='ortho')[:, :n_coefficients]

# 计算MFCC特征
def compute_mfcc(file_path, n_filters, n_fft, n_coefficients):
 sample_rate, signal = wav.read(file_path)
 emphasized_signal = pre_emphasis(signal)
 frames = split_into_frames(emphasized_signal, frame_len=0.025 artical cgpt2md_gpt.sh cgpt2md_johngo.log cgpt2md_johngo.sh cgpt2md.sh _content1.txt _content.txt current_url.txt history_url history_urls log nohup.out online pic.txt seo test.py topic_gpt.txt topic_johngo.txt topic.txt upload-markdown-to-wordpress.py urls sample_rate, frame_step=0.01 artical cgpt2md_gpt.sh cgpt2md_johngo.log cgpt2md_johngo.sh cgpt2md.sh _content1.txt _content.txt current_url.txt history_url history_urls log nohup.out online pic.txt seo test.py topic_gpt.txt topic_johngo.txt topic.txt upload-markdown-to-wordpress.py urls sample_rate)
 mag_frames = compute_fft(frames, n_fft)
 filter_banks = mel_filter_bank(n_filters, n_fft, sample_rate)
 filter_banks = np.dot(mag_frames, filter_banks.T)
 filter_banks = np.where(filter_banks == 0, np.finfo(float).eps, filter_banks) # 利用eps处理log时避免出现-inf
 filter_banks = apply_log(filter_banks)
 mfcc = dct_transform(filter_banks, n_coefficients)
 return mfcc

# 使用示例
file_path = 'audio.wav'
n_filters = 26
n_fft = 512
n_coefficients = 13

mfcc = compute_mfcc(file_path, n_filters, n_fft, n_coefficients)
print(mfcc.shape)

上述代码中,我们首先定义了预加重、分帧、傅里叶变换、梅尔滤波器组、对数操作和DCT变换等函数。然后我们根据语音信号文件的路径,使用wav.read从文件中读取语音信号,并进行MFCC特征提取。最后,我们输出MFCC特征的形状。

compute_mfcc函数中,我们首先将读取的语音信号进行预加重处理,然后将其切分成多个帧。接下来,我们对每一帧应用FFT进行傅里叶变换,得到频谱。然后,我们计算语音信号与梅尔滤波器组的重叠部分,得到滤波器输出。我们对滤波器输出取对数,然后应用DCT变换,最终得到MFCC特征。

注意,在对梅尔滤波器输出取对数时,为了避免出现负无穷大的情况,在代码中使用np.finfo(float).eps将为零的值替换为一个极小的正值。

最后,我们使用compute_mfcc函数对给定的语音信号文件进行MFCC特征提取,并打印输出特征的形状。

希望上述示例代码和解释能够帮助您理解MFCC特征提取的原理、公式推导、计算步骤和代码细节。请根据自己的实际需求进行合适的参数设置和代码调整。

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/823456/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球