写一个 MATLAB…
- User
写一个 MATLAB 函数,根据倒谱分析的原理对测试语音进行基音周期检测和共振峰检测,并输出音频信号基音周期和共振峰检测效果图。测试语音的文件名是suojinxin_2017131414.wav
- Assistant
function [pitch_periods, formants] = speech_analysis(filename)
% Load audio file [x,fs] = audioread(filename);
% Preemphasis preemph = [1 -0.97]; x = filter(preemph,1,x);
% Windowing winlen = 30e-3; % window length in seconds winshift = 10e-3; % window shift in seconds winlenpts = round(winlenfs); winshiftpts = round(winshiftfs); nframes = floor((length(x)-winlenpts)/winshiftpts)+1; xframe = zeros(winlenpts+2,nframes); for i=1:nframes istart = (i-1)*winshiftpts+1; iend = istart+winlenpts-1; xframe(:,i) = [x(istart-1); x(istart:iend); x(iend+1)]; end
% Find pitch period using autocorrelation ac_coef = zeros(winlenpts+1,nframes); for i=1:nframes [ac_coef(:,i),lags] = xcorr(xframe(:,i)); end pitch_periods = zeros(1,nframes); for i=1:nframes ac_peaklocs = find(ac_coef(:,i)==max(ac_coef(:,i))); pitch_periods(i) = lags(ac_peaklocs(1))/fs; end