Mercurial > hg > emotion-detection-top-level
comparison Code/Test/formant_tracker.m @ 4:92ca03a8fa99 tip
Update to ICASSP 2013 benchmark
author | Dawn Black |
---|---|
date | Wed, 13 Feb 2013 11:02:39 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:e1cfa7765647 | 4:92ca03a8fa99 |
---|---|
1 function[formant]=formant_tracker(input,dimension,step,window_size,p,threshold) | |
2 % %Formant_tracker based on LPC Analysis | |
3 % format:[formants]=formant_tracker(input,dimension,step,window_size,p,threshold) | |
4 % where, | |
5 % input:input speech waveform; | |
6 % dimension:input size, in number of samples. | |
7 % step:step size , in number of samples; | |
8 % window_size: frame/window size, in number of samples; | |
9 % p: number of LP coeffcients; | |
10 % threshold: the threshold value for pole magnitude.Poles having higher magnitude are candidates for being formant | |
11 % frequencies. | |
12 % | |
13 % Author:Narsimh Kamath. | |
14 % NITK, India.Thanks! | |
15 num=1; | |
16 dimension-window_size; | |
17 | |
18 for i=1:step:(dimension/50)-window_size | |
19 | |
20 frame=input(num*step-window_size/2:num*step+window_size/2); | |
21 | |
22 | |
23 | |
24 for k=1:p+1 | |
25 autocorrelation(k)=0; | |
26 for l=1:window_size-k | |
27 autocorrelation(k)=autocorrelation(k)+frame(l)*frame(l+k-1); | |
28 end | |
29 autocorrelation(k)=autocorrelation(k)/window_size; | |
30 end | |
31 | |
32 t=window_size/2; | |
33 for k=20:t | |
34 acf(k)=0; | |
35 for l=1:window_size-k | |
36 acf(k)=acf(k)+frame(l)*frame(l+k-1); | |
37 end | |
38 acf(k)=acf(k)/window_size; | |
39 end | |
40 [rr,ii]=max(acf(10:t)); | |
41 tp=10000/ii; | |
42 | |
43 alpha=zeros(p,p); | |
44 a=zeros(p,1); | |
45 E=zeros(p,1); | |
46 E(1)=autocorrelation(1); | |
47 for i=1:p | |
48 sum=0; | |
49 for j=1:i-1 | |
50 if(i)>1 | |
51 sum=sum+alpha(j,(i-1))*autocorrelation(abs(i-j)+1); | |
52 end | |
53 end | |
54 | |
55 k(i)=(autocorrelation(i+1)-sum)/E(i); | |
56 alpha(i,i)=k(i); | |
57 if i>1 | |
58 for j=1:i-1 | |
59 alpha(j,i)=alpha(j,i-1)-k(i)*alpha(i-j,i-1); | |
60 end | |
61 end | |
62 E(i+1)=(1-k(i)^2)*E(i); | |
63 var=E(i+1); | |
64 end | |
65 for j=1:p | |
66 a(j)=alpha(j,p); | |
67 end | |
68 f=[1 -a']; | |
69 gain=0; | |
70 p; | |
71 for i =1:p+1 | |
72 gain=gain+f(i)*autocorrelation(i); | |
73 end | |
74 gain; | |
75 gain=gain^0.5; | |
76 | |
77 | |
78 root1=roots([1,-a']); | |
79 | |
80 mag_root=abs(root1); | |
81 arg_root=angle(root1); | |
82 my_roots(:,num) = mag_root(:); | |
83 % if( max(frame) > 0.001 ) | |
84 % subplot(311); plot(frame); | |
85 % subplot(312); plot(abs(fft(frame))); | |
86 % subplot(313); plot(mag_root); | |
87 % end | |
88 k=1; | |
89 for j=1:p | |
90 if mag_root(j)>threshold | |
91 if arg_root(j)>0 &arg_root(j)<pi | |
92 formant(num,k)=arg_root(j)/pi*5000; | |
93 | |
94 num; | |
95 k; | |
96 k=k+1; | |
97 end | |
98 end | |
99 end | |
100 | |
101 | |
102 num=num+1; | |
103 end | |
104 s=size(formant); | |
105 for i=1:length(formant) | |
106 for j=1:s(2) | |
107 if formant(i,j)==0 | |
108 formant(i,j)=NaN; | |
109 end | |
110 end | |
111 end | |
112 | |
113 plot(formant,'.b'); | |
114 return; | |
115 end | |
116 |