









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
LPC Methods autocorrelation lattice and covariance
Typology: Essays (university)
1 / 15
This page cannot be seen from the preview
Don't miss anything!
simple speech production
[row col] = size(data); if col==1 data=data'; end
nframe = 0; msfr = round(sr/1000fr); % Convert ms to samples msfs = round(sr/1000fs); % Convert ms to samples duration = length(data); speech = filter([1 -preemp], 1, data)'; % Preemphasize speech msoverlap = msfs - msfr; ramp = [0:1/(msoverlap-1):1]'; % Compute part of window
for frameIndex=1:msfr:duration-msfs+1 % frame rate=20ms frameData = speech(frameIndex:(frameIndex+msfs-1)); % frame size=30ms nframe = nframe+1; autoCor = xcorr(frameData); % Compute the cross correlation autoCorVec = autoCor(msfs+[0:L]);
% Levinson's method err(1) = autoCorVec(1); k(1) = 0; A = []; for index=1:L numerator = [1 A.']autoCorVec(index+1:-1:2); denominator = -1err(index); k(index) = numerator/denominator; % PARCOR coeffs A = [A+k(index)flipud(A); k(index)]; err(index+1) = (1-k(index)^2)err(index);
% filter response if 0 gain=0; cft=0:(1/255):1; for index=1:L gain = gain + aCoeff(index,nframe)exp(-i2picft).^index; end gain = abs(1./gain); spec(:,nframe) = 20log10(gain(1:128))'; plot(20log10(gain)); title(nframe); drawnow; end
if 0 impulseResponse = filter(1, aCoeff(:,nframe), [1 zeros(1,255)]); freqResp = 20*log10(abs(fft(impulseResponse))); plot(freqResp); end
function [ outspeech ] = speechcoder1( inspeech )
% Parameters: % inspeech : wave data with sampling rate Fs % (Fs can be changed underneath if necessary) % Returns: % outspeech : wave data with sampling rate Fs % (coded and resynthesized)
if ( nargin ~= 1) error('argument check failed'); end;
Fs = 16000; % sampling rate in Hertz (Hz) Order = 10; % order of the model used by LPC
% encoded the speech using LPC [aCoeff, resid, pitch, G, parcor, stream] = proclpc(inspeech, Fs, Order);
% decode/synthesize speech using LPC and impulse-trains as excitation outspeech = synlpc(aCoeff, pitch, Fs, G)
results :
MATLAB files : clear all;
%osama saraireh % speech processing %Dr. Veton Kepuska %FIT FAll 2005 a= input ('please load the speech signal as a .wav file ' , 's'); Inputsoundfile = a ; [inspeech, Fs, bits] = wavread(Inputsoundfile); % read the wavefile outspeech1 = speechcoder1(inspeech); % plain LPC vocoder outspeech2 = speechcoder2(inspeech); % Voice excitded LPC vocoder
% plot results figure(1); subplot(3,1,1); plot(inspeech); grid; subplot(3,1,2); plot(outspeech1); grid; subplot(3,1,3); plot(outspeech2); grid; disp('Press any key to play the original sound file'); pause; soundsc(inspeech, Fs); disp('Press any key to play the LPC compressed file!'); pause; soundsc(outspeech1, Fs); disp('Press a key to play the voice-excited LPC compressed sound!'); pause; soundsc(outspeech2, Fs);
function [aCoeff,resid,pitch,G,parcor,stream] = proclpc(data,sr,L,fr,fs,preemp)
% L - The order of the analysis.. % fr - Frame time increment, in ms. Defaults to 20ms % fs - Frame size in ms. % preemp - default 0. % aCoeff - The LPC analysis results, % resid - The LPC residual, % pitch - calculated by finding the peak in the residual's autocorrelation %for each frame. % G - The LPC gain for each frame. % parcor - The parcor coefficients. % stream - The LPC analysis' residual or excitation signal as one long vector.
if (nargin<3), L = 10; end if (nargin<4), fr = 20; end if (nargin<5), fs = 30; end if (nargin<6), preemp = .9378; end
[row col] = size(data); if col==1 data=data'; end
nframe = 0; msfr = round(sr/1000fr); % Convert ms to samples msfs = round(sr/1000fs); % Convert ms to samples duration = length(data); speech = filter([1 -preemp], 1, data)'; % Preemphasize speech msoverlap = msfs - msfr; ramp = [0:1/(msoverlap-1):1]'; % Compute part of window
for frameIndex=1:msfr:duration-msfs+1 % frame rate=20ms frameData = speech(frameIndex:(frameIndex+msfs-1)); % frame size=30ms nframe = nframe+1; autoCor = xcorr(frameData); % Compute the cross correlation autoCorVec = autoCor(msfs+[0:L]);
% Levinson's method err(1) = autoCorVec(1); k(1) = 0; A = [];
stream = [stream; resid(msfr+1:msfs,nframe)]; else overlap = resid(msfr+1:msfs,nframe).*flipud(ramp); end end stream = filter(1, [1 -preemp], stream)';
Speech Model one
LPC Vocoder :
function [ outspeech ] = speechcoder1( inspeech )
% Parameters: % inspeech : wave data with sampling rate Fs
% outputs: % outspeech : wave data with sampling rate Fs % (coded and resynthesized)
if ( nargin ~= 1) error('argument check failed'); end;
Fs = 8000; % sampling rate in Hertz (Hz) Order = 10; % order of the model used by LPC
% encoded the speech using LPC [aCoeff, resid, pitch, G, parcor, stream] = proclpc(inspeech, Fs, Order);
% decode/synthesize speech using LPC and impulse-trains as excitation outspeech = synlpc(aCoeff, pitch, Fs, G);
% Voice-excited LPC vocoder
function [ outspeech ] = speechcoder2( inspeech ) % Parameters:
% inspeech : wave data with sampling rate Fs % (Fs can be changed underneath if necessary)
% output: % outspeech : wave data with sampling rate Fs % (coded and resynthesized)
if ( nargin ~= 1) error('argument check failed'); end;
Fs = 16000; % sampling rate in Hertz (Hz) Order = 10; % order of the model used by LPC
% encoded the speech using LPC [aCoeff, resid, pitch, G, parcor, stream] = proclpc(inspeech, Fs, Order);
% perform a discrete cosine transform on the residual resid = dct(resid); [a,b] = size(resid); % only use the first 50 DCT-coefficients this can be done % because most of the energy of the signal is conserved in these coeffs resid = [ resid(1:50,:); zeros(430,b) ];
% quantize the data resid = uencode(resid,4); resid = udecode(resid,4);
% perform an inverse DCT resid = idct(resid);
% add some noise to the signal to make it sound better noise = [ zeros(50,b); 0.01*randn(430,b) ]; resid = resid + noise;
% decode/synthesize speech using LPC and the compressed residual as excitation outspeech = synlpc2(aCoeff, resid, Fs, G)