FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Sound
(Moderators: pitaru, REAS)
   Comparing two samples
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Comparing two samples  (Read 2021 times)
LigaMainz

WWW
Comparing two samples
« on: May 11th, 2004, 5:07pm »

Hi.
 
I got a problem. I want to compare two samples with eachother and want to get a percentage value of their equality.
 
I tried to compare the levels of each frame and than the spectrum. But somehow the result isn't satisfying.  

 
this is my sketch so far, try and see:
 
http://www.say-nono.com/processing/bloei_audio_1/
 
 
Any better Ideas?
What is the best and fastest way to do this?
Are there any existing projects already?
 
 
 
Thanks+
Vince
 
JohnG

WWW
Re: Comparing two samples
« Reply #1 on: May 12th, 2004, 1:40pm »

Unfortunately analysing frames isn't really going to work, if you have 2 of the same sample, but one offset by a single frame, they're going to appear completely different in a frame by frame basis.
 
One possible way is to compare the getSpectrum() populated data, and compare similarity, averaged over a couple of frames.
 
Quasimondo

WWW Email
Re: Comparing two samples
« Reply #2 on: May 13th, 2004, 7:47pm »

I haven't tried that yet, but maybe you could get help from the field of string comparision. If you think of the sample data as a string you could try to calculate the Levenshtein Distance between two of them. More about this algorithm here:
 
http://www.merriampark.com/ld.htm
 
Perhaps it would be an idea to reduce the complexity of the samples first - I presume you are looking into speech reconition?
 
edit: I've just discovered on that page that Levenshtein is indeed used for speech recognition
« Last Edit: May 13th, 2004, 7:50pm by Quasimondo »  

Mario Klingemann | Quasimondo | Incubator | côdeazur
mattgilbert

tangramkid WWW Email
Re: Comparing two samples
« Reply #3 on: Jul 31st, 2004, 12:53am »

I recently was faced with a similar issue, of comparing the getSpectrum data of two Samples. The way I did it was just to sum up the differences in each spectrum, something like
 
Code:

float diffSum = 0;
for(int i = 0; i < spectrumA.length; i++){
  diffSum += abs(spectrumA[i] - spectrumB[i]);
}
return diffSum;

 
Of course, that only works when the spectrums are the same length, which is a reasonable thing to expect in this application...
 
It seems that the stuff in the link makes sense for comparing words or letter sequences, but in the case of spectrum data, where spectrumA[i] and spectrumB[i] are numbers whose values can be compared better than just whether or not they are the same.
 
Does that make sense? Are there ways of using Levenshtein Distance that I'm overlooking?
 
matt
 
 
zach


Re: Comparing two samples
« Reply #4 on: Jul 31st, 2004, 5:31am »

on May 12th, 2004, 1:40pm, JohnG wrote:
Unfortunately analysing frames isn't really going to work, if you have 2 of the same sample, but one offset by a single frame, they're going to appear completely different in a frame by frame basis.

 
 
not entirely accurate:
 
first, consider the how the simple DST works:
(http://www.dspdimension.com/html/dftapied.html)
we mutliply each sample, *not* summing the differences.
Because you are mutliplying samples (each sample in one window vs each corresponding sample in the other window) if they are off by a frame or 5 frames or 10 it's not gonna be such a problem.  what is a problem is if they are phase inverted - ie, one sample window is the upsidedown version of the other sample window.  Then you will see no correlation, when there is.  
 
investigate "cross correlation"
(http://astronomy.swin.edu.au/~pbourke/analysis/correlate/)
 
it while slide a window of one signal along another window.  The result plots areas of correlation.  
this method can deal with phase shifting, etc.
 
this image shows the results of two images be ing cross correlated:
 
http://www.ph.ed.ac.uk/~ted/thesis/img250.png
 
the peak represents the position of most correlation.
 
- zach  
« Last Edit: Aug 1st, 2004, 3:06am by zach »  
mattgilbert

tangramkid WWW Email
Re: Comparing two samples
« Reply #5 on: Aug 4th, 2004, 12:35am »

*click*
 
i think i get it. it took me a few looks, but the cross-correlation links should come in very handy. have you, zach, or anyone, used cross correlation in an audio application?
 
thanks,
 
matt
 
 
 
zach


Re: Comparing two samples
« Reply #6 on: Aug 5th, 2004, 1:36am »


I have used it in the concert I worked on, messa di voce, where golan levin and I wrote software that analyzed vocal signals in real time.  we actually applied the cross corelation on another window of the same signal,as one part of a pitch detector system.  this is called "autocorrelation" but it is fundementally the same operation.
 
the concert can be read about here:
http://www.tmema.org/messa/messa.html
 
- zach
 
ps on a similar note, check out this cool project by martin wattenberg which uses your sketches to query a stock price database and return a period of time which matches that profile.
http://www.bewitched.com/projects/querysketch/wattenberg-chi2001.pdf
 
 
 
 
 
mattgilbert

tangramkid WWW Email
Re: Comparing two samples
« Reply #7 on: Aug 7th, 2004, 9:05pm »

beautiful, beautiful work!
 
mattgilbert

tangramkid WWW Email
Re: Comparing two samples
« Reply #8 on: Aug 8th, 2004, 7:17pm »

I've just posted a piece that uses cross-correlation, thanks to zach's helpful posts and links.
 
The piece is called Reap, and it's a program that takes two sound files, chops up one and tries to rebuild the other one with the pieces. While the results aren't music (this is not an automated remixer), it's pretty interesting seeing how well you can build one track with the pieces of another.
 
http://www.mattgilbert.net/reap/
 
More match-ups and full tracks to come.
 
matt
 
 
 
Pages: 1 

« Previous topic | Next topic »