-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetLPCresidual.m
81 lines (60 loc) · 1.73 KB
/
GetLPCresidual.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function [res,LPCcoeff] = GetLPCresidual(wave,L,shift,order,gci,type,t0)
% %%%
%
% Use: [res] = GetLPCresidual(wave,L,shift,order,gci,type,t0)
%
%
% L=window length (samples) (typ.25ms)
% shift=window shift (samples) (typ.5ms)
% order= LPC order
% gci=gci position (samples)
% type=vector of voicing decisions (=0 if Unvoiced, =1 if Voiced)
% t0=vector of period values (in samples)
%
% Written by Thomas Drugman, TCTS Lab.
%
% %%%
%% My Bit!!
% use: L = 25/1000*fs % 25 ms frame length
% shift = 5/1000*fs % 5 ms shift
% order = 24
wave=wave(:);
if nargin<5
doPS=0;
else
doPS=1;
end
if doPS==0
start=1;
stop=start+L;
res=zeros(1,length(wave));
LPCcoeff=zeros(order+1,round(length(wave)/shift));
n=1;
while stop<length(wave)
segment=wave(start:stop);
segment=segment.*hanning(length(segment));
[A,e]=lpc(segment,order);
LPCcoeff(:,n)=A(:);
inv=filter(A,1,segment);
inv=inv*sqrt(sum(segment.^2)/sum(inv.^2));
res(start:stop)=res(start:stop)+inv';
start=start+shift;
stop=stop+shift;
n=n+1;
end
res=res/max(abs(res));
else
Ltot=length(wave);
[begin,ending,frametype] = CompleteFramingWithType(gci,16000,Ltot,shift,L,type,t0);
res=zeros(1,length(wave));
for k=1:length(begin)
start=begin(k);
stop=ending(k);
segment=wave(start:stop);
segment=segment.*hanning(length(segment));
[A,e]=lpc(segment,order);
inv=filter(A,1,segment);
res(start:stop)=res(start:stop)+inv';
end
res=res/max(abs(res));
end