3
$\begingroup$

To my ears, sawtooth and square waves are more similar to each other than either one is to a triangle wave. However, when I compare their magnitude spectra against each other using normalized cross-correlation, the square and triangle waves are the most similar to each other, followed by the sawtooth and triangle waves. Does anyone know what the source of this apparent mismatch is?

$\endgroup$
4
$\begingroup$
  • Sawtooth:
    • Even and odd harmonics, falling off at 1/n
  • Square:
    • Odd harmonics only, falling off at 1/n
  • Triangle:
    • Odd harmonics only, falling off at 1/n2

So while triangle and square have the same set of frequencies present, the spectral envelope of sawtooth and square is more similar, with much stronger high frequency harmonics. Triangle waves are simpler/closer to a sine wave.

(Also, if you're generating them digitally, it's uncommon for them to be bandlimited, which produces worse aliasing artifacts with the square and sawtooth than with the triangle. This would be most audible with frequency sweeps or high fundamental frequencies.)

$\endgroup$
  • $\begingroup$ Right, so I was expecting the normalized cross-correlation of the spectral envelopes to show that sawtooth and square waves are the most similar to each other, but I got the opposite result. Any ideas as to why? I checked and double-checked for math errors and couldn't find any, but maybe my eyes/brain missed something... $\endgroup$ – visual-kinetic Oct 2 '12 at 16:24
  • 2
    $\begingroup$ I don't have any data to back that, but I'm not sure that you'd get consistent results when asking people to say whether square is more similar to triangle or to sawtooth. Timbre is multidimensional. Some people would group square and saw because they sound richer than triangle (higher spectral centroid / f0). Some people would group square and triangle because they sound "hollower" than sawtooth (no even harmonics). $\endgroup$ – pichenettes Oct 2 '12 at 18:30
  • 1
    $\begingroup$ @visual-kinetic: Ohhh, you're cross-correlating the spectrum of a square wave with the spectrum of a triangle wave? Well all of the frequencies are identical in that case. If you're multiplying a sawtooth with a square wave, half the harmonics are being multiplied by 0, so the ratio to the total amplitude will be lower? $\endgroup$ – endolith Oct 2 '12 at 18:39
  • 1
    $\begingroup$ @visual-kinetic: have a look at this answer. dsp.stackexchange.com/questions/3425/… . In particular the link to the document describing common features used for audio classification. Extracting these features on each audio clip and comparing the feature vectors will be much more useful than comparing the raw audio waveform! $\endgroup$ – pichenettes Oct 2 '12 at 19:26
  • 1
    $\begingroup$ @visual-kinetic: Not sure if this is what you're doing, but you might want to look at the two-way mismatch (TWM) algorithm, too. $\endgroup$ – endolith Oct 2 '12 at 21:41
3
$\begingroup$

The human ear does not "sense" the time-domain representation of the signal, but, in a rough approximation, the magnitude of its frequency-domain representation (spectrum).

In particular, several variants of the same stationary signal with different phase shifts will sound exactly the same. From that, it is clear to see that normalized cross-correlation is a poor metric for comparing audio signals; since a sine-wave and the same sine-wave with a 90° phase shift will have a low cross-correlation, while they are indistinguishable. A better place to start to compare waveforms would be to compute the cross-correlation of the magnitude spectra.

$\endgroup$
  • 1
    $\begingroup$ Sorry, by "harmonics" I was actually referring to the waveforms' magnitude spectra. I'll edit the question so it's clearer. Thanks! $\endgroup$ – visual-kinetic Oct 2 '12 at 15:17
  • 2
    $\begingroup$ I think you might mean a 90-degree phase shift. Two sinusoids with a 180-degree phase shift between them will have a significant (negative) cross-correlation. For a 90-degree phase shift, you would get zero cross-correlation if the time window is an integer number of periods. $\endgroup$ – Jason R Oct 2 '12 at 15:33
  • $\begingroup$ Yes, I meant 90°, edited. $\endgroup$ – pichenettes Oct 2 '12 at 17:42
  • $\begingroup$ -1 He was not talking about time-domain cross-correlation. $\endgroup$ – Jim Clay Oct 2 '12 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.