MATLAB编程实现短时自相关和短时平均幅度差,参考测试语音为 C2.wav,每个参数的函数定义格式为: funcvalue = funcname(x) 其中 x 为语音信号,funcvalue 为[帧长,帧数]的矩阵。 这里显示的语音信号,是语音帧拼接而成,即没有去掉交叠项。
时间: 2023-06-11 14:06:48 浏览: 207
以下是MATLAB实现短时自相关和短时平均幅度差的代码:
```matlab
function r = short_time_autocorr(x)
% 短时自相关函数
% 输入:x - 语音信号
% 输出:r - [帧长, 帧数]的矩阵
frame_length = 0.03; % 帧长为30ms
frame_shift = 0.01; % 帧移为10ms
fs = 16000; % 采样率为16kHz
n_fft = 2^nextpow2(frame_length*fs); % FFT点数为2的幂次方
% 分帧
frame_samples = round(frame_length*fs);
shift_samples = round(frame_shift*fs);
num_frames = floor((length(x)-frame_samples)/shift_samples) + 1;
frames = zeros(frame_samples, num_frames);
for i = 1:num_frames
start_sample = (i-1)*shift_samples + 1;
frames(:,i) = x(start_sample:start_sample+frame_samples-1);
end
% 预加重
pre_emphasis = [1, -0.97];
frames = filter(1, pre_emphasis, frames);
% 加窗
window = hamming(frame_samples);
frames = bsxfun(@times, frames, window);
% 自相关
r = zeros(n_fft, num_frames);
for i = 1:num_frames
frame_fft = fft(frames(:,i), n_fft);
r(:,i) = ifft(abs(frame_fft).^2);
end
% 取前一半
r = r(1:n_fft/2, :);
end
function m = short_time_ampdiff(x)
% 短时平均幅度差函数
% 输入:x - 语音信号
% 输出:m - [帧长, 帧数]的矩阵
frame_length = 0.03; % 帧长为30ms
frame_shift = 0.01; % 帧移为10ms
fs = 16000; % 采样率为16kHz
% 分帧
frame_samples = round(frame_length*fs);
shift_samples = round(frame_shift*fs);
num_frames = floor((length(x)-frame_samples)/shift_samples) + 1;
frames = zeros(frame_samples, num_frames);
for i = 1:num_frames
start_sample = (i-1)*shift_samples + 1;
frames(:,i) = x(start_sample:start_sample+frame_samples-1);
end
% 预加重
pre_emphasis = [1, -0.97];
frames = filter(1, pre_emphasis, frames);
% 加窗
window = hamming(frame_samples);
frames = bsxfun(@times, frames, window);
% 平均幅度差
m = zeros(frame_samples, num_frames);
for i = 1:num_frames
diff = diff(frames(:,i));
m(:,i) = mean(abs(diff));
end
end
% 测试
[x, fs] = audioread('C2.wav');
r = short_time_autocorr(x);
m = short_time_ampdiff(x);
```
阅读全文