Mercurial > hg > emotion-detection-top-level
comparison Code/Descriptors/yin/calculate_pitchYIN.m @ 0:ea0c737c6323
first commit
author | Dawn Black <dawn.black@eecs.qmul.ac.uk> |
---|---|
date | Thu, 26 Jul 2012 14:46:25 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ea0c737c6323 |
---|---|
1 function [framePrd] = calculate_pitchYIN( sampleFileName, x, fs, frameLength, noOfFrames ) | |
2 | |
3 % sampleFileName = sampleWavFileName( 1 : length( sampleWavFileName ) - 4 ); | |
4 % pitchFileName = [ sampleFileName '_YIN_pitch.txt']; | |
5 % pitchFileID = fopen( pitchFileName, 'w'); | |
6 | |
7 [periodInSamples, fileinfo] = yin ([ '../' sampleFileName '.wav']); | |
8 | |
9 % YIN produces one pitch estimate for every 32 samples. For our purposes | |
10 % this must be scaled to one sample every frame (approx 10ms but also a | |
11 % power of two). | |
12 | |
13 frameLength = 2^(ceil(log2(fileinfo.sr/100))); | |
14 noOfFrames = floor(fileinfo.nsamples / frameLength); %skip the final samples if necessary | |
15 | |
16 yinPrdSamplesPerFrame = length(periodInSamples) / noOfFrames; | |
17 | |
18 | |
19 start = 1; | |
20 stop = length(periodInSamples); | |
21 framePrd = []; | |
22 | |
23 for i=1:noOfFrames | |
24 % find the first and last periodInSamples frames to be averaged for | |
25 % every master frame of length frameLength | |
26 start = floor((i-1) * (length(periodInSamples) / noOfFrames)) + 1; | |
27 stop = ceil(i * (length(periodInSamples) / noOfFrames)); | |
28 if( stop <= length(periodInSamples) ) | |
29 % exclude NaN frames | |
30 prdChunk = periodInSamples( start : stop ); | |
31 goodPrdIdx = find( isnan( prdChunk )==0 ); | |
32 if( length( goodPrdIdx ) > 0 ) | |
33 framePrd(i,2) = mean( prdChunk(goodPrdIdx)); | |
34 else | |
35 framePrd(i,2) = NaN; | |
36 end | |
37 framePrd(i,1) = i; % record the frame number | |
38 % might need to know this in case of frame mismatch | |
39 prdFrames(i) = stop - start; | |
40 % write to file | |
41 % fprintf(pitchFileID, '%d %f \n', framePrd(i,1), framePrd(i,2) ); | |
42 else | |
43 break; | |
44 end | |
45 end | |
46 | |
47 % plot(periodInSamples,'x'); hold on; | |
48 % xaxisdiv=((length(periodInSamples)/length(framePrd))/2):(length(periodInSamples)/length(framePrd)):length(periodInSamples) + ((length(periodInSamples)/length(framePrd))/2); | |
49 % plot(xaxisdiv(1:length(framePrd)),framePrd(:,2),'rx'); | |
50 | |
51 % fclose( pitchFileID ); |