function [pesq_mos, pesq_seg] = pesq(ref, deg, fs) % Check inputs if nargin < 3 fs = 16000; end if nargin < 2 error('Not enough input arguments'); end if length(ref) ~= length(deg) error('Input signals must be of equal length'); end % Load filter coefficients load('pesq_filter.mat'); % High-pass filter deg_hp = filter(b_hp, a_hp, deg); % Remove silence [r_beg, r_end] = find_voiced(ref, fs); [d_beg, d_end] = find_voiced(deg_hp, fs); r_sig = ref(r_beg:r_end); d_sig = deg_hp(d_beg:d_end); % Find maximum length sig_len = min(length(r_sig), length(d_sig)); % Filter signals r_sig = filter(b_lpf, a_lpf, r_sig(1:sig_len)); d_sig = filter(b_lpf, a_lpf, d_sig(1:sig_len)); % Resample signals r_sig = resample(r_sig, 8000, fs); d_sig = resample(d_sig, 8000, fs); % Calculate PESQ [pesq_mos, pesq_seg] = pesq_mex(r_sig, d_sig); end function [beg, endd] = find_voiced(sig, fs) % Set parameters win_len = 240; win_shift = 80; sil_thresh = 30; min_voiced = 0.1; % Calculate energy sig_pow = sig.^2; sig_pow_filt = filter(ones(1, win_len)/win_len, 1, sig_pow); % Normalize sig_pow_filt = sig_pow_filt/max(sig_pow_filt); % Find voiced segments beg = []; endd = []; num_voiced = 0; for n = 1:win_shift:length(sig)-win_len if sig_pow_filt(n+win_len/2) > min_voiced && ... mean(sig_pow_filt(n:n+win_len-1)) > sil_thresh if isempty(beg) beg = n; end else if ~isempty(beg) endd = [endd n-1]; num_voiced = num_voiced + 1; beg = []; end end end if ~isempty(beg) endd = [endd length(sig)]; num_voiced = num_voiced + 1; end % Remove segments that are too short min_len = fs*0.05; len_voiced = endd-beg+1; too_short = len_voiced < min_len; beg(too_short) = []; endd(too_short) = []; end这段代码中的pesq_mex.mex64文件怎么编译
时间: 2023-06-15 22:07:18 浏览: 191
PESQ 工具编译源码,内附编译教程。
5星 · 资源好评率100%
该mex文件是用C或C++语言编写的,需要使用MATLAB的mex命令进行编译。具体的步骤如下:
1. 打开MATLAB命令窗口,进入pesq_mex.c文件所在的目录。
2. 输入以下命令:
mex pesq_mex.c
3. 如果编译成功,则会生成pesq_mex.mex64或pesq_mex.mexw64文件,如果失败,则会提示错误信息。如果出现错误信息,需要根据错误信息进行调试和修改。
4. 将生成的pesq_mex.mex64或pesq_mex.mexw64文件复制到pesq函数所在的目录中,即可在MATLAB中调用pesq函数。
阅读全文