1.软件版本
matlab2013b
2.系统设计概述
首先,整体框架的基本构架如下所示:
编码:
解码:
传统的AMDF算法或者ACF算法都无法满足实际的需求,这里,通过计算AMDF/ACF值或者ACF/AMDF值。这里选择效果更好的ACF/AMDF方法进行。
矢量量化采用一种逐帧的LPC VQ方案,这里,基本流程:
得到的音调预测和增益直接进行量化,而线性预测则需要进行矢量量化器进行量化,并进行组帧。
其中矢量编码解码的基本结构如下所示:
3.部分源码
clc;
clear;
close all;
warning off;
addpath 'func\'
addpath 'Train\'
RandStream.setDefaultStream(RandStream('mt19937ar','seed',1));
%读取待处理的声音文件
[yOri,Fs,nbits] = wavread('test1.wav');
sound(yOri,Fs);
plotFlag = 0; %绘图标识位
istrain = 0;
%1.预处理,滤波
%1.预处理,滤波
n = 8;
Wn = ([60,3600]/4000);
[b,a] = butter(n,Wn,'bandpass');
yPre = filter(b,a,yOri);
plot1;
%2.预加重
%2.预加重
a = 1;
b = [1 -0.9375];
yPw = filter(b,a,yPre);
plot2;
%3.清、浊音判决的分析及量化
%低带能量:通过一个截止频率为900Hz 阻带为10dB的低通滤波器
Wp = 900/4000;
[b,a]= cheby2(6,10,Wp,'low');
yLF = filter(b,a,yPre);
plot3;
%成帧
[yFrame,nF] = func_enFrame(yLF);
%短时能量来区分清/浊音
VoiceSoundFlag = func_short_energy(yFrame,nF);
%二阶逆滤波(白化滤波)
yFrame = inverseFilter(yFrame,nF);
%获得基音周期(AMDF)
pitchT = func_GetPitch(yFrame,VoiceSoundFlag,nF);
%计算增益(RMS)
RMS = func_RMS(yFrame,VoiceSoundFlag,pitchT,nF);
%LPC预测阶数
[Vlpc,Vlsf] = func_LPC_Order(yFrame,nF);
%矢量量化采用王炳锡书5.8章红圈的方法,并组帧
%训练,得到码本,这里需要大量的语音库,这里仅仅提供算法流程,训练库使用少量样本
if istrain == 1
tops;
load Train\code_save.mat
else
load Train\code_save.mat
end
figure;
K1 = 1;
K2 = 2;
plot(lsf{1}(K1,:), lsf{1}(K2,:), 'xr');
hold on;
plot(code{1}(K1,:),code{1}(K2,:), 'vk');
hold on;
plot(lsf{2}(K1,:), lsf{2}(K2,:), 'xb');
hold on;
plot(code{2}(K1,:),code{2}(K2,:), '+k');
hold on;
xlabel('2th Dimension');
ylabel('6th Dimension');
legend('Speaker 1', 'Codebook 1', 'Speaker 2', 'Codebook 2');
title('2D plot of accoustic vectors');
%VQ发送
Frame = func_vq_trans(Vlsf,pitchT,RMS,VoiceSoundFlag,nF,code);
%计算压缩对比
Rate = func_size_cal(yOri,Frame);
%接收,矢量解码器
[Vlsf3,VQ_decode,lsf_code,VoiceSoundFlag3,RMS3,pitchT3] = func_vq_rec(Frame,nF,code);
%解码
yCom = func_decode(Vlsf3,VoiceSoundFlag3,pitchT3,RMS3,nF);
%去加重
b = 1;
a = [1 -0.9375];
yCom = filter(b,a,yCom);
sound(yCom,Fs);
figure;
subplot(311);
plot(yOri);
subplot(312);
plot(pitchT);
subplot(313);
plot(yCom);
4.仿真结论
5.参考文献
[1]夏殿松, 胡淼, 洪夏俊. 一种基于AMDF和ACF的基音周期提取算法研究[J]. 军事通信技术, 2009(1):5.A03-06