主要内容

LPC Analysis and Synthesis of Speech

This example shows how to implement a speech compression technique known as Linear Prediction Coding (LPC) using DSP System Toolbox™ functionality available at the MATLAB® command line.

介绍

In this example you implement LPC analysis and synthesis (LPC coding) of a speech signal. This process consists of two steps: analysis and synthesis. In the analysis section, you extract the reflection coefficients from the signal and use it to compute the residual signal. In the synthesis section, you reconstruct the signal using the residual signal and reflection coefficients. The residual signal and reflection coefficients require less number of bits to code than the original speech signal.

下图显示了您将实现的系统。

在此模拟中,语音信号分为大小3200个样品的帧,重叠为1600个样本。每个框架都使用锤窗窗口。发现第十二阶自相关系数,然后使用Levinson-Durbin算法根据自相关系数计算反射系数。原始语音信号通过分析过滤器,该滤波器是一个全零滤波器,其系数为上述反射系数。过滤器的输出是残差信号。该残留信号通过一个合成过滤器,该滤波器是分析滤波器的倒数。合成过滤器的输出是原始信号。

初始化

Here you initialize some of the variables like the frame size and also instantiate the System objects used in your processing. These objects also pre-compute any necessary variables or tables resulting in efficient processing calls later inside a loop.

Initialize variables.

框架= 1600; fftLen = 2048;

Here you create a System object™ to read from an audio file and determine the file's audio sampling rate.

audioReader = dsp.AudioFileReader('SamplesPerFrame', frameSize,...'OutputDataType','double');fileInfo = info(audioreader);fs = fileInfo.Samplater;

创建用于预先强调的FIR数字过滤系统对象。

preEmphasisFilter = dsp.FIRFilter(...'Numerator', [1 -0.95]);

Create a buffer System object and set its properties such that you get an output of twice the length of the框架with an overlap length of框架.

signalBuffer = dsp.AsyncBuffer(2*frameSize);

Create an FIR digital filter System object used for analysis. Also create two all-pole digital filter System objects used for synthesis and de-emphasis.

analysisFilter = dsp.FIRFilter(...'Structure','Lattice MA',...'ReflectionCoefficientsSource','Input port');synthesisFilter = dsp.AllpoleFilter('Structure','晶格AR');deEmphasisFilter = dsp.AllpoleFilter(“分母”,[1 -0.95]);

Create a System object to play the resulting audio.

audioWriter = audioDeviceWriter('SampleRate', Fs);% Setup plots for visualization.范围=光谱分析仪('SampleRate', Fs,...“ plotastwosidedspectrum”, false,'YLimits',[-140,0],...'标题','Linear Prediction of Speech',...'ShowLegend', 真的,“频道名称”,{'Signal','LPC'});

流处理循环

Here you call your processing loop where you do the LPC analysis and synthesis of the input audio signal using the System objects you have instantiated.

The loop is stopped when you reach the end of the input file, which is detected by theAudioFilereDer系统对象。

尽管~isDone(audioReader)%阅读音频输入sig = audioReader();% 分析%请注意,过滤系数是作为参数传递给的%分析系统对象。sigpreem = preEmphasisFilter(sig); write(signalBuffer,sigpreem); sigbuf = read(signalBuffer,2*frameSize, frameSize); hammingwin = hamming(2*frameSize); sigwin = hammingwin.*sigbuf;% Autocorrelation sequence on [0:13]sigacf = xcorr(sigwin, 12,'biased');sigacf = sigacf(13:end);%计算自动相关功能的反射系数%使用Levinson-Durbin递归。手段n outputs both% polynomial coefficients and reflection coefficients. The polynomial%系数用于计算和绘制LPC光谱。[sigA, ~, sigK] = levinson(sigacf);% Levinson-Durbinsiglpc = analysisFilter(sigpreem, sigK);% 合成synthesisFilter.ReflectionCoefficients = sigK.'; sigsyn = synthesisFilter(siglpc); sigout = deEmphasisFilter(sigsyn);% Play output audioAudioWriter(Sigout);% Update plotssigA_padded = zeros(size(sigwin),'like', sigA.');% Zero-padded to plotsigA_padded(1:size(sigA.',1), :) = sigA.'; scope([sigwin, sigA_padded]);end

释放

在这里,您可以在系统对象上调用发布方法以关闭任何打开的文件和设备。

释放(Audioreader);暂停(10*audioreader.samplesperframe/audioreader.samplerate);%等到音频完成播放释放(AudioWriter);释放(范围);

结论

您在这里已经看到了使用线性预测编码实现语音压缩技术。该实现使用了MATLAB命令行中可用的DSP系统工具箱功能。该代码仅涉及使用适当输入参数的连续系统对象调用。这涉及不容易发生手动状态跟踪的错误,例如,MATLAB实现缓冲区。