Why do i get the error "Index exceeds matrix dimensions. Error in fingerprinting (line 6) song1=song1(1:44100);" in my code
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
- * * Item one
- * * Item twoMy code is :
- function fingerprinting %main routine for fingerprinting and matching
- %write reference wav-files ("Library") into vectors
- clear all;
- clc;
- song1=wavread('song1.wav');
- song1=song1(1:3*44100);
- song2=wavread('song2.wav');
- song2=song2(1:3*44100);
- song4=wavread('song4.wav');
- song4=song4(1:3*44100);
- %write sample wav-file into vector
- sample=wavread('sample.wav');
- sample=sample(1:3*44100);
- %create signatures of reference files and sample
- FP1=fingerprint1(song1);
- FP2=fingerprint1(song2);
- FP4=fingerprint1(song4);
- FPS=fingerprint1(sample);
- %calculate similarity between the reference FP and the sample FP
- M1=eq(FPS,FP1);
- M2=eq(FPS,FP2);
- M4=eq(FPS,FP4);
- %sum up number of equal digits
- s1=sum(M1);
- s2=sum(M2);
- s4=sum(M4);
- com1=sum(s1);
- com2=sum(s2);
- com4=sum(s4);
- %look for a perfect match
- match=0;
- if com1==4608 %max. equal digits
- fprintf('perfect match with song 1')
- match=1;
- end
- if com2==4608
- fprintf('perfect match with song 2')
- match=1;
- end
- if com4==4608
- fprintf('perfect match with song 4')
- match=1;
- end
- %if there is no perfect match, find best match
- if com1>com2
- if com1>com4
- if match==0
- fprintf('song 1 is closest match')
- end
- end
- end
- if com2>com1
- if com2>com4
- if match==0
- fprintf('song 2 ist closest match')
- end
- end
- end
- if com4>com1
- if com4>com2
- if match==0
- fprintf('song 4 ist closest match')
- end
- end
- end;
- Fingerprint extraction:
- function H=fingerprint1(song) %fingerprint extraction
- A=auditoryfbank(song, 44100); %bandpass filtering using the pre-designed filterbank
- B=A.*A; %energy calculation
- H=zeros(256,18);
- %calculating the energy difference between two adjacent bands in two subsequent time frames
- for n=2:256
- for m=1:17
- H(n,m)=B(n,m)-B(n,m+1)-(B(n-1,m)-B(n-1,m+1));
- if H(n,m)>0
- H(n,m)=1;
- else
- H(n,m)=0;
- end
- end
- end;
1 comentario
Jan
el 8 de Oct. de 2013
Do not start each line with a star. See the "? help" link to learn how to format code in this forum.
clear all on top of a function is 1. meaningless, 2. wastes time by forcing Matlab to reload all functions from the slow hard disk, 3. deletes all valuable breakpoints of the debugger.
Respuestas (1)
David Sanchez
el 8 de Oct. de 2013
Your code says:
song1=song1(1:3*44100);
what assumes that song1 is at least a 1x132300 array. It seems that song1 is smaller than that.
2 comentarios
Jan
el 8 de Oct. de 2013
Editada: Jan
el 8 de Oct. de 2013
@Shweeta: We cannot guess, what you want. But at least you cannot exceed the maximum index:
song1 = song1(1:min(3*44100, numel(song1)))
But the same problem might occur for the other files also: You cannot crop the elements behind 3*44100, when the data have less elements.
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!