checking for a discontinuity in a signal

Discussion in 'MATLAB' started by John Murray, Dec 12, 2008.

  1. John Murray

    John Murray Guest

    Hi

    I have a vector filled with sequences of numbers that go up in steps of a value of 1, but there a a couple of these sequences int he vector.

    ie. [200 201 202 555 556 557 558 923 924 925 926]
    what is the best (most efficient) way of geting the index's of where the next number does not follow on from the number before it?

    I could do this by hand using a for loop or something checking the pervious value, but I doubt this is the most efficient way in Matlab.

    I could loop through it and see that 555 is greater than 202 by a value of more than 1 and so add that index into a new array, or store 202 and 555 in the array, whatever....

    but I would expect a vector soemthing like
    [4 8] which would give me the index of the value where it differed by a value greater than 1.

    or
    [202 555 558 923] which gives me the first and last values of the difference sequences.

    Regards
    John
     
    John Murray, Dec 12, 2008
    #1
    1. Advertisements

  2. find(diff(a)>1)+1
     
    Pekka Kumpulainen, Dec 12, 2008
    #2
    1. Advertisements

  3. John Murray

    John Murray Guest

    Got to be something more efficient than:
    for i=2:length(mySequence)
    if mySequence(i) - mySequence(i-1) > 0
    myDiscontinuityIndex = [myDiscontinuityIndex i];
    myDiscontinuityValues = [myDiscontinuityValues mySequence(i-1) mySequence(i)];
    end
    end
     
    John Murray, Dec 12, 2008
    #3
  4. John Murray

    John Murray Guest

    sorry.....

    myDiscontinuityIndex = [];
    myDiscontinuityValues = [];
    for i=2:length(mySequence)
    if mySequence(i) - mySequence(i-1) > 1
    myDiscontinuityIndex = [myDiscontinuityIndex i];
    myDiscontinuityValues = [myDiscontinuityValues mySequence(i-1) mySequence(i)];
    end
    end
     
    John Murray, Dec 12, 2008
    #4
  5. John Murray

    John Murray Guest

    Cheers :)
     
    John Murray, Dec 12, 2008
    #5
  6. Yes, there are more efficient ways to do it, see above.
    or
    myDiscontinuityIndex = find(diff(mySequence)>1)+1;
    myDiscontinuityValues = (mySequence(myDiscontinuityIndex));
     
    Pekka Kumpulainen, Dec 12, 2008
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.