LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Comparing two sound waves

I have a project that I am working on that needs to compare two sound waves.  
 
I have two sounds waves, w1 and w2.  I am looping w1 and playing it on one channel.  I play the sound through a device and then record it on another channel, the recorded wave being w2.  I want to know if w1=w2 or if w2 contains w1.  I have tried looking at the cross corelation of the two waves but this doesn't seem to help because w1 and w2 aren't neccessarly the same length. 
 
Any help would be appreciated.
 
Alan
0 Kudos
Message 1 of 3
(5,920 Views)

Comparing 2 sound waves

One wave is shorter or equal to the other

Question is to find (nearly) equal occurrences of the shorter in the longer.

This is not an uncommon requirement. The trick is to align then and do a subtraction, sum the differences . Move the shorter on one point and do it again. This will give you a vector of differences which you can examine to find the lowest point. Then you see if it’s close enough.

Be careful to have the frequencies of the sound recordings the same, or do some interppolation to make them the same.

With the proposed heuristic you can get positive and negative differences which balance out. Maybe it’s better to square the difference before adding it up.

The system is quite computationally intensive.

I have used this approach for recognizing shapes in fetal heart rate tracings, where there are characteristic shapes of ominous patterns.

0 Kudos
Message 2 of 3
(5,906 Views)
One problem you will run into with both this and an error sum approach is that your recorded sound wave, even if it is "the same" as the original, will probably have the samples at a different position (different phase).  This can cause more error than you expect.  You can use the resampling VIs to cure this, or roll your own using Fourier techniques (take the Fourier transform, change the phase of all the elements to move them in time just a bit, take the inverse Fourier transform).  You can use minimization techniques to automate a lot of the drudgery of this.  I have used the downhill simplex successfully for this sort of thing in the past.  Don't be afraid to modify VI.lib VIs to do what you need them to do.  Just be sure to save them to a new location so you don't overwrite the originals.
0 Kudos
Message 3 of 3
(5,890 Views)