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

6 次查看(过去 30 天)
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