wolffd@0
|
1 function demo3tempo
|
wolffd@0
|
2 % To get familiar with tempo estimation from audio using the MIR Toolbox.
|
wolffd@0
|
3 % To assess the performance of the tempo estimation method.
|
wolffd@0
|
4
|
wolffd@0
|
5 % 1. Let's investigate the different stages needed for tempo estimation.
|
wolffd@0
|
6
|
wolffd@0
|
7 d = miraudio('ragtime')
|
wolffd@0
|
8 mirenvelope(d)
|
wolffd@0
|
9 e = mirenvelope(d,'Halfwavediff')
|
wolffd@0
|
10
|
wolffd@0
|
11 % Decompose the audio file with a filter bank.
|
wolffd@0
|
12 f = mirfilterbank(d)
|
wolffd@0
|
13
|
wolffd@0
|
14 % Calculate also a half-wave rectified differentiated envelope.
|
wolffd@0
|
15 ee = mirenvelope(f,'HalfwaveDiff')
|
wolffd@0
|
16
|
wolffd@0
|
17 % Sum the frequency channels.ok
|
wolffd@0
|
18 s = mirsum(ee,'Centered')
|
wolffd@0
|
19
|
wolffd@0
|
20 d2 = miraudio('vivaldi')
|
wolffd@0
|
21 f2 = mirfilterbank(d2)
|
wolffd@0
|
22 ee2 = mirenvelope(f2,'HalfwaveDiff')
|
wolffd@0
|
23 s2 = mirsum(ee2,'Centered')
|
wolffd@0
|
24
|
wolffd@0
|
25 % Calculate the autocorrelation function.
|
wolffd@0
|
26 ac = mirautocor(s)
|
wolffd@0
|
27
|
wolffd@0
|
28 % Apply the resonance model to the autocorrelation function.
|
wolffd@0
|
29 ac = mirautocor(s,'Resonance')
|
wolffd@0
|
30
|
wolffd@0
|
31 % Find peaks in the autocorrelation function.
|
wolffd@0
|
32 p = mirpeaks(ac)
|
wolffd@0
|
33 mirgetdata(p)
|
wolffd@0
|
34
|
wolffd@0
|
35 % Get the period of the peaks.
|
wolffd@0
|
36 t = mirtempo(p,'Total',1)
|
wolffd@0
|
37
|
wolffd@0
|
38 display('Strike any key to continue...');
|
wolffd@0
|
39 pause
|
wolffd@0
|
40 close all
|
wolffd@0
|
41
|
wolffd@0
|
42 % 2. All the functions we used are integrated into the function tempo.
|
wolffd@0
|
43 help mirtempo
|
wolffd@0
|
44
|
wolffd@0
|
45 % For instance, we can simply write:
|
wolffd@0
|
46 [t,ac] = mirtempo('ragtime')
|
wolffd@0
|
47
|
wolffd@0
|
48 % As you can see in the help, the resonance is integrated by default in the
|
wolffd@0
|
49 % tempo function. To toggle off the use of the resonance function, type:
|
wolffd@0
|
50 [t,ac] = mirtempo('ragtime','Resonance',0)
|
wolffd@0
|
51
|
wolffd@0
|
52 [t,ac] = mirtempo('ragtime','total',5)
|
wolffd@0
|
53
|
wolffd@0
|
54 display('Strike any key to continue...');
|
wolffd@0
|
55 pause
|
wolffd@0
|
56 close all
|
wolffd@0
|
57
|
wolffd@0
|
58 % 3. The excerpt 'laksin' and 'czardas' have variable tempi. Use frame-
|
wolffd@0
|
59 % based tempo analysis to estimate the variation of the tempi.
|
wolffd@0
|
60 % Apply to this end the tempo command with the 'frame' option.
|
wolffd@0
|
61 [t1,p1] = mirtempo('laksin','Frame')
|
wolffd@0
|
62 [t2,p2] = mirtempo('czardas','Frame')
|
wolffd@0
|
63
|
wolffd@0
|
64 % What is the range of variation of tempi?
|
wolffd@0
|
65 help mirhisto
|
wolffd@0
|
66 h1 = mirhisto(t1)
|
wolffd@0
|
67 h2 = mirhisto(t2) |