필터 지우기
필터 지우기

Why do i get the error "Index exceeds matrix dimensions. Error in fingerprinting (line 6) song1=song1(1:44100);" in my code

조회 수: 1 (최근 30일)
  • * * 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
Jan
Jan 2013년 10월 8일
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.

댓글을 달려면 로그인하십시오.

답변 (1개)

David Sanchez
David Sanchez 2013년 10월 8일
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
Jan
Jan 2013년 10월 8일
편집: Jan 2013년 10월 8일
@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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by