Dawn@4
|
1 function [ idx ] = voicingByClustering( x, fs, noOfFrames, frameLength )
|
Dawn@4
|
2 % attempt to classify the voiced/unvoiced frames using k-means
|
Dawn@4
|
3 % clustering with the short term energy and spectral centroid
|
Dawn@4
|
4 % as feature vectors
|
Dawn@4
|
5 % returns an array containing voicing decision for frames
|
Dawn@4
|
6 % Useful only for speech frames
|
Dawn@4
|
7 % Window length and step (in seconds):
|
Dawn@4
|
8 win = frameLength/fs;
|
Dawn@4
|
9 step = win;
|
Dawn@4
|
10
|
Dawn@4
|
11 % calculate the short term energy
|
Dawn@4
|
12 Eor = ShortTimeEnergy(x, win*fs, step*fs );
|
Dawn@4
|
13 % calculate the spectral centroid
|
Dawn@4
|
14 Cor = SpectralCentroid(x, win*fs, step*fs, fs );
|
Dawn@4
|
15
|
Dawn@4
|
16 % dataFileName = '../../../../../Results/VUVgrouping.txt';
|
Dawn@4
|
17 % dataFileID = fopen( dataFileName, 'w' );
|
Dawn@4
|
18
|
Dawn@4
|
19 noOfClusters = 2; %voiced, unvoiced
|
Dawn@4
|
20 data = [Eor Cor];
|
Dawn@4
|
21 idArray = zeros(1, length(Eor));
|
Dawn@4
|
22
|
Dawn@4
|
23 % myColours = ['r.'; 'm.'; 'c.'; 'w.'; 'g.'; 'y.'; 'b.'];
|
Dawn@4
|
24
|
Dawn@4
|
25 [idx ctrs]=kmeans( data, noOfClusters, 'Replicates',100,...
|
Dawn@4
|
26 'start', 'sample', 'Distance', 'cityblock');
|
Dawn@4
|
27
|
Dawn@4
|
28 % we don't know which group will be classed as voiced
|
Dawn@4
|
29 % or unvoiced.
|
Dawn@4
|
30 % assume that the number of voiced frames is more than unvoiced
|
Dawn@4
|
31
|
Dawn@4
|
32 noOfAFrames = length( find( idx == 1 ));
|
Dawn@4
|
33 noOfBFrames = length( find( idx == 2 ));
|
Dawn@4
|
34 if( noOfAFrames < noOfBFrames )
|
Dawn@4
|
35 voicedIdx = 2;
|
Dawn@4
|
36 unvoicedIdx = 1;
|
Dawn@4
|
37 else
|
Dawn@4
|
38 voicedIdx = 1;
|
Dawn@4
|
39 unvoicedIdx = 2;
|
Dawn@4
|
40 end
|
Dawn@4
|
41
|
Dawn@4
|
42
|
Dawn@4
|
43 % now re-number the idx array so all voiced frames = 1 and
|
Dawn@4
|
44 % unvoiced = 2
|
Dawn@4
|
45
|
Dawn@4
|
46 voicedPos = find( idx == voicedIdx );
|
Dawn@4
|
47 unvoicedPos = find( idx == unvoicedIdx );
|
Dawn@4
|
48
|
Dawn@4
|
49 %replace the idx
|
Dawn@4
|
50 idx( voicedPos ) = 1;
|
Dawn@4
|
51 idx( unvoicedPos ) = 2;
|
Dawn@4
|
52
|
Dawn@4
|
53 end
|
Dawn@4
|
54
|