No announcement yet.

Find zero crossings in wav file

  • Filter
  • Time
  • Show
Clear All
new posts

  • Find zero crossings in wav file

    I want to locate the zero crossings in a short wav file. The obvious way is to take two consecutive points and do something like IF (A>0 and B<0) or (A<0 and B>0) then store that point and move ahead one. Is there any more elegant way?

  • #2
    result = a or a , only when a = zero would return zero.
    A dozen what.


    • #3
      If you are comparing to wave channels then result = a or b only when both is zero.
      A dozen what.


      • #4
        I only need to look at one monophonic channel, but remember that there probably won't be a point with zero value, only that the waveform moved through zero, with sample points on either side of zero.


        • #5
          Not sure its any faster but
          IF BIT(a, sign bit) XOR BIT(b, sign bit) THEN
          where sign bit = 15 for an integer and 31 for a long


          • #6
            Is it 8 bit, or 16 bit, wav?

            8 bit has a 128 mid point, 16 bit is signed; either way just look for a change in most significant bit. That should be faster than < and > comparisons.

            For 8 bit something like:

            mask byte with &h10
            XOR with previous masked byte
            if result of XOR is true then zero was crossed (MSB is different)
            keep this masked byte for XOR with following byte, etc, etc.



            • #7
              Think this might be the base templete. I also think the simplest thing is to look for going from negitive to postive and visa versa to find zero crossing.

              if x is postive then x is true
              if x is neg then x is fasle

              if x is true loop until false
              if x is false - zero cross from positive to negative occured -exit loop - now test for false to true condition

              if x is false loop until true
              if x is true zero cross from negative to positive to occured -exit loop

              do this until end of file.
              A dozen what.


              • #8
                Hey, those all look great- tonight I'll add some routines and see how they work. BTW, this isn't for music. I have a signal from a test at work, and it seemed really easy to just feed it into the pc, record a mono 16-bit wav file, then do whatever analysis I wanted with PB. Thanks!


                • #9
                  Make sure that there are no dc offsets in your signal, if so you will have to normalise the data if you want to use Dale's method (which by the way rocks!).
                  In other words, find the average and add the difference to each sample before doing the zero crossing analysis.
                  Gary Barnes
                  The Control Key

                  If you are not part of the solution
                  then you are either a gas, solid, plasma or some other form of matter.


                  • #10
                    Probably not near optimal, but this works just great for what I'm doing-

                     temp = Amplitude(0) OR &h7FFF                                    'mask is 0111 1111 1111 1111
                        FOR count = 0 TO NumberOfSamples-1
                            IF temp XOR (Amplitude(count+1) OR &h7FFF) THEN crossings(x)=count : INCR x
                            temp = Amplitude(count+1) OR &h7FFF
                        NEXT count
                    Thanks again!