% CCRMA MIR Workshop 2009 % Lab4: Structural analysis - self similarity matrix and novelty score % Kyogu Lee (June 2009) clear all; close all; % read audio file [x,fs] = wavread('../wav/01_no_reply.wav'); %[x,fs] = wavread('../wav/prelude_cmaj.wav'); if size(x,2) > size(x,1) x = x'; % make a column vector end x = mean(x,2); % make mono %x = x(1:20*fs); % first 20 seconds % analysis parameters M = 2^nextpow2(floor(fs*0.1)); % compute MFCC (try other features!) % [ceps,freqresp,fb,fbrecon,freqrecon] = mfcc(input, samplingRate, % [frameRate]) warning off; [mfceps,freqresp,fb] = mfcc(x,fs,fs/(M/2)); inf_idx = find(isinf(mfceps(1,:))); mfceps(:,inf_idx) = eps; nframe = size(mfceps,2); % compute distance matrix (similarity matrix) dist = zeros(nframe,nframe); for i=1:nframe-1 for j=i+1:nframe dist(i,j) = norm(mfceps(:,i)-mfceps(:,j)); % L-2 norm (Euclidean distance) % try other distance metrics! end end % make distance matrix symmetric dists = max(dist,dist'); % normalize dists_n = dists/max(max(dists)); % make a self similarity matrix sim_mtx = 1 - dists_n; % compute novely score ns = diag(dists_n,1); % ns is just diagonal elements % novelty score using gaussian kernel ker_size = 16; % kernel size in seconds N = floor(ker_size*fs/(M/2)); % kernel size in frames if mod(N,2) N = N+1; % make even end ker = gauss_kernel(N); for i=1:nframe-N+1 cor = corrcoef(ker,sim_mtx(i:i+N-1,i:i+N-1)); ns_ker(i) = cor(1,2); end ns_ker_n = ns_ker/max(ns_ker); % normalization % display figure(1); imagesc([0:length(dist)-1]/(fs/M*2),[0:length(dist)-1]/(fs/M*2),sim_mtx); colormap(gray); title('Self similarity matrix'); xlabel('time (secs)'); figure(2); surf(ker); colormap(1-gray); title('gaussian kernel'); figure(3); subplot(211); plot([0:length(ns)-1]/(fs/M*2),ns); title('Novelty score'); xlabel('time (secs)'); subplot(212); plot(([0:length(ns_ker)-1]+N/2)/(fs/M*2),ns_ker_n); title('Novelty score using kernel'); xlabel(['time ' ... '(secs)']);