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