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

5 views (last 30 days)
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.

Accepted Answer

Jan
Jan on 12 Mar 2013
Edited: Jan on 12 Mar 2013
Without a loop:
index = find(diff(d2x) > 23.74);

More Answers (1)

Carlos
Carlos on 12 Mar 2013
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 Comments
David Mehr
David Mehr on 12 Mar 2013
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 on 12 Mar 2013
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'

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!