annotate toolboxes/MIRtoolbox1.3.2/MIRToolboxDemos/demo4segmentation.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function demo4segmentation
Daniel@0 2 % To get familiar with some approaches of segmentation of audio files
Daniel@0 3 % using MIRtoolbox.
Daniel@0 4
Daniel@0 5 % 1. Load an audio file (for instance, guitar.wav).
Daniel@0 6 a = miraudio('guitar');
Daniel@0 7
Daniel@0 8 % 2. We will perform the segmentation strategy as proposed in (Foote &
Daniel@0 9 % Cooper, 2003). First, decompose the file into successive frames of 50 ms
Daniel@0 10 % without overlap.
Daniel@0 11 help mirframe
Daniel@0 12 fr = mirframe(a,0.05,1)
Daniel@0 13
Daniel@0 14 % 3. Compute the spectrum representation (FFT) of the frames.
Daniel@0 15 sp = mirspectrum(fr)
Daniel@0 16 clear fr
Daniel@0 17 % (Remove from the memory any data that will not be used any more.)
Daniel@0 18
Daniel@0 19 % 4. Compute the similarity matrix that shows the similarity between the
Daniel@0 20 % spectrum of different frames.
Daniel@0 21 help mirsimatrix
Daniel@0 22 sm = mirsimatrix(sp)
Daniel@0 23 clear sp
Daniel@0 24 % Look at the structures shown in the matrix and find the relation with the
Daniel@0 25 % structure heard when listening to the extract.
Daniel@0 26
Daniel@0 27 % 5. Estimate the novelty score related to the similarity matrix. It
Daniel@0 28 % consists in a convolution of the diagonal of the matrix with a
Daniel@0 29 % checker-board Gaussian kernel. Use the novelty function for that purpose.
Daniel@0 30 help mirnovelty
Daniel@0 31 nv = mirnovelty(sm)
Daniel@0 32
Daniel@0 33 % 6. Detect the peaks in the novelty score.
Daniel@0 34 help mirpeaks
Daniel@0 35 p1 = mirpeaks(nv)
Daniel@0 36
Daniel@0 37 % You can change the threshold value of the peak picker function in order to
Daniel@0 38 % get better results.
Daniel@0 39 p2 = mirpeaks(nv,'Contrast',0.01)
Daniel@0 40
Daniel@0 41 clear nv
Daniel@0 42
Daniel@0 43 % 7. Segment the original audio file using the peaks as position for
Daniel@0 44 % segmentation.
Daniel@0 45 help mirsegment
Daniel@0 46 s1 = mirsegment(a,p1)
Daniel@0 47 clear p1
Daniel@0 48
Daniel@0 49 % 8. Listen to the results.
Daniel@0 50 mirplay(s1)
Daniel@0 51
Daniel@0 52 %s2 = mirsegment(a,p2)
Daniel@0 53 %clear p2
Daniel@0 54 %mirplay(s2)
Daniel@0 55
Daniel@0 56 % 9. Compute the similarity matrix of this obtained segmentation, in order
Daniel@0 57 % to view the relationships between the different segments and their
Daniel@0 58 % possible clustering into higher-level groups.
Daniel@0 59 mirsimatrix(s1,'Similarity')
Daniel@0 60 clear s1
Daniel@0 61 %mirsimatrix(s2)
Daniel@0 62 %clear s2
Daniel@0 63
Daniel@0 64 display('Strike any key to continue...');
Daniel@0 65 pause
Daniel@0 66 close all
Daniel@0 67
Daniel@0 68 % 10. Change the size of the kernel used in the novelty function, in order
Daniel@0 69 % to obtain segmentations of different levels of detail, from detailed
Daniel@0 70 % analysis of the local texture, to very simple segmentation of the whole
Daniel@0 71 % piece.
Daniel@0 72 n100 = mirnovelty(sm,'KernelSize',100)
Daniel@0 73 n50 = mirnovelty(sm,'KernelSize',50)
Daniel@0 74 n10 = mirnovelty(sm,'KernelSize',10)
Daniel@0 75 clear sm
Daniel@0 76 % As you can see, the smaller the gaussian kernel is, the more peaks can be
Daniel@0 77 % found in the novelty score. Indeed, if the kernel is small, the cumulative
Daniel@0 78 % multiplication of its elements with the superposed elements in the
Daniel@0 79 % similarity matrix may vary more easily, throughout the progressive
Daniel@0 80 % sliding of the kernel along the diagonal of the similarity matrix, and
Daniel@0 81 % local change of texture may be more easily detected. On the contrary,
Daniel@0 82 % when the kernel is large, only large-scale change of texture are
Daniel@0 83 % detected.
Daniel@0 84
Daniel@0 85 display('Strike any key to continue...');
Daniel@0 86 pause
Daniel@0 87 close all
Daniel@0 88
Daniel@0 89 p100 = mirpeaks(n100,'NoBegin','NoEnd')
Daniel@0 90 clear n100
Daniel@0 91 p50 = mirpeaks(n50,'NoBegin','NoEnd')
Daniel@0 92 clear n50
Daniel@0 93 p10 = mirpeaks(n10,'NoBegin','NoEnd')
Daniel@0 94 clear n10
Daniel@0 95 s100 = mirsegment(a,p100)
Daniel@0 96 clear p100
Daniel@0 97 mirplay(s100)
Daniel@0 98 clear s100
Daniel@0 99 s50 = mirsegment(a,p50)
Daniel@0 100 clear p50
Daniel@0 101 mirplay(s50)
Daniel@0 102 clear s50
Daniel@0 103 s10 = mirsegment(a,p10)
Daniel@0 104 clear p10
Daniel@0 105 mirplay(s10)
Daniel@0 106 clear s10
Daniel@0 107
Daniel@0 108 display('Strike any key to continue...');
Daniel@0 109 pause
Daniel@0 110 close all
Daniel@0 111
Daniel@0 112 % One more compact way of writing these commands is as follows:
Daniel@0 113 mirsegment(a,'Novelty')
Daniel@0 114 mirsegment(a,'Novelty','Contrast',0.01)
Daniel@0 115 mirsegment(a,'Novelty','KernelSize',100)
Daniel@0 116
Daniel@0 117 display('Strike any key to continue...');
Daniel@0 118 pause
Daniel@0 119 close all
Daniel@0 120
Daniel@0 121 % Besides, if you want to see the novelty curve with the peaks, just add a
Daniel@0 122 % second output:
Daniel@0 123 [s50 p50] = mirsegment(a,'Novelty','KernelSize',50)
Daniel@0 124 clear s50 p50
Daniel@0 125 [s10 p10] = mirsegment(a,'Novelty','KernelSize',10)
Daniel@0 126 clear a s10 p10
Daniel@0 127
Daniel@0 128 display('Strike any key to continue...');
Daniel@0 129 pause
Daniel@0 130 close all
Daniel@0 131
Daniel@0 132
Daniel@0 133 % 11. Try the whole process with MFCC instead of spectrum analysis. Take the
Daniel@0 134 % first ten MFCC for instance.
Daniel@0 135 help mirsegment
Daniel@0 136 % The segment function can simply be called as follows:
Daniel@0 137 sc = mirsegment('czardas','Novelty','MFCC','Rank',1:10)
Daniel@0 138 clear sc
Daniel@0 139
Daniel@0 140 % Here are some other examples of use:
Daniel@0 141 [ssp p m b] = mirsegment('valse_triste_happy','Spectrum',...
Daniel@0 142 'KernelSize',150,'Contrast',.1)
Daniel@0 143 clear p m b
Daniel@0 144 mirplay(ssp)
Daniel@0 145 clear ssp
Daniel@0 146
Daniel@0 147 display('Strike any key to continue...');
Daniel@0 148 pause
Daniel@0 149 close all
Daniel@0 150
Daniel@0 151 [smfcc2 p m a] = mirsegment('valse_triste_happy','MFCC',2:10,...
Daniel@0 152 'KernelSize',150,'Contrast',.1)
Daniel@0 153 clear p m a
Daniel@0 154 mirplay(smfcc2)