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'

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by