wolffd@0: function demo4segmentation wolffd@0: % To get familiar with some approaches of segmentation of audio files wolffd@0: % using MIRtoolbox. wolffd@0: wolffd@0: % 1. Load an audio file (for instance, guitar.wav). wolffd@0: a = miraudio('guitar'); wolffd@0: wolffd@0: % 2. We will perform the segmentation strategy as proposed in (Foote & wolffd@0: % Cooper, 2003). First, decompose the file into successive frames of 50 ms wolffd@0: % without overlap. wolffd@0: help mirframe wolffd@0: fr = mirframe(a,0.05,1) wolffd@0: wolffd@0: % 3. Compute the spectrum representation (FFT) of the frames. wolffd@0: sp = mirspectrum(fr) wolffd@0: clear fr wolffd@0: % (Remove from the memory any data that will not be used any more.) wolffd@0: wolffd@0: % 4. Compute the similarity matrix that shows the similarity between the wolffd@0: % spectrum of different frames. wolffd@0: help mirsimatrix wolffd@0: sm = mirsimatrix(sp) wolffd@0: clear sp wolffd@0: % Look at the structures shown in the matrix and find the relation with the wolffd@0: % structure heard when listening to the extract. wolffd@0: wolffd@0: % 5. Estimate the novelty score related to the similarity matrix. It wolffd@0: % consists in a convolution of the diagonal of the matrix with a wolffd@0: % checker-board Gaussian kernel. Use the novelty function for that purpose. wolffd@0: help mirnovelty wolffd@0: nv = mirnovelty(sm) wolffd@0: wolffd@0: % 6. Detect the peaks in the novelty score. wolffd@0: help mirpeaks wolffd@0: p1 = mirpeaks(nv) wolffd@0: wolffd@0: % You can change the threshold value of the peak picker function in order to wolffd@0: % get better results. wolffd@0: p2 = mirpeaks(nv,'Contrast',0.01) wolffd@0: wolffd@0: clear nv wolffd@0: wolffd@0: % 7. Segment the original audio file using the peaks as position for wolffd@0: % segmentation. wolffd@0: help mirsegment wolffd@0: s1 = mirsegment(a,p1) wolffd@0: clear p1 wolffd@0: wolffd@0: % 8. Listen to the results. wolffd@0: mirplay(s1) wolffd@0: wolffd@0: %s2 = mirsegment(a,p2) wolffd@0: %clear p2 wolffd@0: %mirplay(s2) wolffd@0: wolffd@0: % 9. Compute the similarity matrix of this obtained segmentation, in order wolffd@0: % to view the relationships between the different segments and their wolffd@0: % possible clustering into higher-level groups. wolffd@0: mirsimatrix(s1,'Similarity') wolffd@0: clear s1 wolffd@0: %mirsimatrix(s2) wolffd@0: %clear s2 wolffd@0: wolffd@0: display('Strike any key to continue...'); wolffd@0: pause wolffd@0: close all wolffd@0: wolffd@0: % 10. Change the size of the kernel used in the novelty function, in order wolffd@0: % to obtain segmentations of different levels of detail, from detailed wolffd@0: % analysis of the local texture, to very simple segmentation of the whole wolffd@0: % piece. wolffd@0: n100 = mirnovelty(sm,'KernelSize',100) wolffd@0: n50 = mirnovelty(sm,'KernelSize',50) wolffd@0: n10 = mirnovelty(sm,'KernelSize',10) wolffd@0: clear sm wolffd@0: % As you can see, the smaller the gaussian kernel is, the more peaks can be wolffd@0: % found in the novelty score. Indeed, if the kernel is small, the cumulative wolffd@0: % multiplication of its elements with the superposed elements in the wolffd@0: % similarity matrix may vary more easily, throughout the progressive wolffd@0: % sliding of the kernel along the diagonal of the similarity matrix, and wolffd@0: % local change of texture may be more easily detected. On the contrary, wolffd@0: % when the kernel is large, only large-scale change of texture are wolffd@0: % detected. wolffd@0: wolffd@0: display('Strike any key to continue...'); wolffd@0: pause wolffd@0: close all wolffd@0: wolffd@0: p100 = mirpeaks(n100,'NoBegin','NoEnd') wolffd@0: clear n100 wolffd@0: p50 = mirpeaks(n50,'NoBegin','NoEnd') wolffd@0: clear n50 wolffd@0: p10 = mirpeaks(n10,'NoBegin','NoEnd') wolffd@0: clear n10 wolffd@0: s100 = mirsegment(a,p100) wolffd@0: clear p100 wolffd@0: mirplay(s100) wolffd@0: clear s100 wolffd@0: s50 = mirsegment(a,p50) wolffd@0: clear p50 wolffd@0: mirplay(s50) wolffd@0: clear s50 wolffd@0: s10 = mirsegment(a,p10) wolffd@0: clear p10 wolffd@0: mirplay(s10) wolffd@0: clear s10 wolffd@0: wolffd@0: display('Strike any key to continue...'); wolffd@0: pause wolffd@0: close all wolffd@0: wolffd@0: % One more compact way of writing these commands is as follows: wolffd@0: mirsegment(a,'Novelty') wolffd@0: mirsegment(a,'Novelty','Contrast',0.01) wolffd@0: mirsegment(a,'Novelty','KernelSize',100) wolffd@0: wolffd@0: display('Strike any key to continue...'); wolffd@0: pause wolffd@0: close all wolffd@0: wolffd@0: % Besides, if you want to see the novelty curve with the peaks, just add a wolffd@0: % second output: wolffd@0: [s50 p50] = mirsegment(a,'Novelty','KernelSize',50) wolffd@0: clear s50 p50 wolffd@0: [s10 p10] = mirsegment(a,'Novelty','KernelSize',10) wolffd@0: clear a s10 p10 wolffd@0: wolffd@0: display('Strike any key to continue...'); wolffd@0: pause wolffd@0: close all wolffd@0: wolffd@0: wolffd@0: % 11. Try the whole process with MFCC instead of spectrum analysis. Take the wolffd@0: % first ten MFCC for instance. wolffd@0: help mirsegment wolffd@0: % The segment function can simply be called as follows: wolffd@0: sc = mirsegment('czardas','Novelty','MFCC','Rank',1:10) wolffd@0: clear sc wolffd@0: wolffd@0: % Here are some other examples of use: wolffd@0: [ssp p m b] = mirsegment('valse_triste_happy','Spectrum',... wolffd@0: 'KernelSize',150,'Contrast',.1) wolffd@0: clear p m b wolffd@0: mirplay(ssp) wolffd@0: clear ssp wolffd@0: wolffd@0: display('Strike any key to continue...'); wolffd@0: pause wolffd@0: close all wolffd@0: wolffd@0: [smfcc2 p m a] = mirsegment('valse_triste_happy','MFCC',2:10,... wolffd@0: 'KernelSize',150,'Contrast',.1) wolffd@0: clear p m a wolffd@0: mirplay(smfcc2)