Using the 'diff' function inside the 'find' function.

조회 수: 4 (최근 30일)
David Mehr
David Mehr 2013년 3월 12일
Greetings,
So I am trying to identify from a wav file each time a new note is struck. looking at the 2nd derivative of it when there is a rapid change in magnitude i assume a new note is played. Now i need to write a function that says something like:
for k = 1:1:length(d2x);
if diff(d2x(k,1) and d2x((k+1),1)) > 'some-value'
store it.
end.
so it cycles through the matrix and references everytime the difference between two neighbours is bigger than a value i will decide on.
Could somebody help me actually code this idea, my matlab is getting better but im at a real loss with this.

채택된 답변

Jan
Jan 2013년 3월 12일
편집: Jan 2013년 3월 12일
Without a loop:
index = find(diff(d2x) > 23.74);

추가 답변 (1개)

Carlos
Carlos 2013년 3월 12일
Her is my guess. Why don´t you just store k in a vector? I mean something like
aux= zeros(length(d2x));
aux2=1;
for k = 1:1:length(d2x)
if diff(d2x(k,1) and d2x((k+1),1)) > 'some-value'
aux(aux2)=k;
aux2=aux2+1;
end
end
By doing this, in your vector aux you would have the indices of the positions where you detect the change.
  댓글 수: 2
David Mehr
David Mehr 2013년 3월 12일
my issue isnt simply storing it,
the line: "if diff(d2x(k,1) and d2x((k+1),1)) > 'some-value' "
Is just some pseudo code for what im trying to solve. I do however like the idea of storing the location WITH the value, deffinately something i will do.
So this doesnt answer what im trying to do fully, but it is of some help so thank you.
Carlos
Carlos 2013년 3월 12일
So you want to compare d2x(k,1) and d2x((k+1),1)? If I am undersatnding well,just do:
if (d2x(k,1)-d2x((k+1),1))> 'some-value'

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by