0
\$\begingroup\$

I am trying to build a simple analog circuit that compares how similar two song signals are. One signal is the song sung by me, for example, and the other signal is the reference song signal. Since simplicity is very much wanted, I do not expect it to be very accurate or "formal". As long as it can give me a rough measurement how close the song sung by me is to the reference song , I am perfectly happy.

At first, I thought about making an analog circuit doing Fourier transform/series and then comparing how far the two signals' frequency components fall, but the responses suggest that it would not be easy. So I am open to any ideas/implementations now!

The components available are opamp, diode, resistor, capacity, MOSFET, BJT, NAND gate, NOR, gate, D-flipflop, and counter.

\$\endgroup\$
13
  • 2
    \$\begingroup\$ Does it have to be Fourier Transform based or are other techniques of separating frequency components permitted? If it must be FT based I think you're out of luck. Otherwise, look at swept frequency techniques based on the superhet radio ... swept frequency oscillator, mixer, fixed frequency narrowband filter (IF filter). Or more crudely, a simple bank of bandpass filters! \$\endgroup\$
    – user16324
    Oct 3, 2014 at 15:07
  • 1
    \$\begingroup\$ A Fourier transform is a digital algorithm. Maybe you mean an analog spectrum analyzer? Or are you thinking of building a digital Fourier transform engine with BJTs and D-Flops? (Doesn't qualify as simple or practical.) \$\endgroup\$
    – John D
    Oct 3, 2014 at 15:07
  • 3
    \$\begingroup\$ @JohnD - no, it isn't. It's continuous (analog) math. But Digital circuits are indeed advantageous for evaluating the Discrete Fourier Transform, which is often used as an approximate substitute. A lock-in amplifier is something fairly close to a circuit implementation of a single DFT bin (or for that matter, a heterodyne receiver...) \$\endgroup\$ Oct 3, 2014 at 15:20
  • \$\begingroup\$ @ChrisStratton Yep, you're right, I was thinking of the usual implementation in hardware which is the FFT algorithm to compute the DFT. But as you point out there are close analog circuit implementations. Not necessarily simple though. \$\endgroup\$
    – John D
    Oct 3, 2014 at 15:38
  • 2
    \$\begingroup\$ You need to separate specs from supposed implementations. Tell us what you really want this to do, and leave how you want it done out of the question. There may be other ways to get what you want other than the specific solutions you imagine. \$\endgroup\$ Oct 3, 2014 at 15:39

5 Answers 5

7
\$\begingroup\$

Cross-correlation is a measure of similarity of two signals. The Fourier transform uses this property to Transform signals versus orthogonal (Sine and Cosine) reference frequencies, expressing the Fourier transform as a linear combination of Sines and Cosines.

Therefore you could simply use a correlation circuit whose inputs are i) the signal of interest; ii) Cosine of varying frequency. Repeat for Sine (ideally in parallel). Then you have measurement of correlation from which you can calculate the Magnitude and Angle as usual.

To see how it works, consider a signal containing the component cos(W1.t) and correlating it with the test signal cos(W1.t) ; i.e. the same frequency. As correlation is simply multiplying and integrating the product will be cos^2(W1.t) = 1/2 + cos(2W1.t). Assuming you test various frequencies across whole integer cycles, this will be the only component that integrates to a non-zero value (i.e. has a DC component). That's how the FT and DFT work.

I've found a very informative article on the link between the DFT and correlation, that really describes it very well.

\$\endgroup\$
6
  • \$\begingroup\$ Yes - for the strongest, if it's there long enough to find. But the circuits to find the 2nd and 3rd strongest, while avoiding the "already claimed" peak are going to be even trickier. \$\endgroup\$ Oct 3, 2014 at 15:40
  • \$\begingroup\$ By sweeping the frequency you will find all components. That's how the Fourier transform works. \$\endgroup\$
    – akellyirl
    Oct 3, 2014 at 15:45
  • \$\begingroup\$ Very nice ref. Can you point to an analog crosscorrelation circuit? \$\endgroup\$ Oct 3, 2014 at 16:50
  • 2
    \$\begingroup\$ Wow. Just wow. Here I am about to graduate with a B.S. in Computer Engineering, and I never really understood how the Fourier Transform worked until I read the link you provided. Thanks! \$\endgroup\$
    – krb686
    Oct 3, 2014 at 22:21
  • 1
    \$\begingroup\$ @OlinLathrop A mathematical explanation of the problem is rigorous with no room for interpretation. There are plenty of references for the FT in that context. I have tried to focus on understanding, using simple explanations which will undoubtedly be open to interpretation. I'm sure you understand this as I notice you have a very similar style focused on explanation but open to interpretation. \$\endgroup\$
    – akellyirl
    Oct 4, 2014 at 12:28
3
\$\begingroup\$

The simplest circuit is just a DSP (digital signal processor). The input signal goes into a A/D input, and some output pins are used to indicate whether there is sufficient amplitude in whatever spectrum ranges you care about. The rest is firmware.

By pushing the complexity from the electronics to the firmware, you get a simple circuit, which was your primary spec. I know you said analog circuit, but that is a implementation detail as apposed to a spec. So is performing a fourier transform. Apparently you just want a course frequency analyzer. Implemented a fourier transform is one way to achieve that, but there may be better ways.

In any case, you have to separate specs from imagined implementation. If a answer meets the specs but doesn't give you what you want, then the specs are bad, not the answer.

Added:

You now say you want to see how "similar" two audio tracks are. That's quite a complicated problem and will take a lot more than getting a rough idea of frequency content. The simplest circuit for this is no circuit at all, other than the electronics you already have. Get both recordings into your PC, which can be done via the sound input if necessary. After that it is all software.

One of the first things the software will have to do is to adjust for the invevitable time differences. You probably have to find beats or other large-scale items that are supposed to match in both tracks, and adjust the time of the second track to match the reference up to some acceptable error. Beyond that error you declare a difference. Next I'd look at volume envelope at a few broad frequency ranges, and measure how well they correlate. That doesn't need Fourier analysis, just a few high and low pass filters.

After that, you'll have to experiment. I've never tried to do this before, so I don't know what indicates perceptual "same" to the human hearing system.

\$\endgroup\$
2
\$\begingroup\$

A voice signal will be hard because it's always changing. The Fourier spectrum is not "stationary". If it was you could build a band pass filter with a moderate Q (maybe 10-20) and sweep or step the frequency of the filter. (You'd have to sweep slowly to stay at each freq. Q times the frequency.) and then stick an AC voltmeter after that. If cost is no object you could make a whole bunch of filters, each with a different resonance, and send the signal into them all. parallel processing. But you might as well get an ADC and do it in software.

\$\endgroup\$
1
  • \$\begingroup\$ Yah, now I realize that it is not "stationary". But it does not actually have to be Fourier transform. Please kindly refer to my updated question for details. \$\endgroup\$ Oct 4, 2014 at 2:38
2
\$\begingroup\$

I mix plenty of vocal tracks and comparing one vocal track with another is best ONLY done by the ear. For instance, one of the most obvious things about vocal tracks is the imprecise timing of how words are phrased whilst sung - you will never get anything like a perfect alignment but, does that mean your vocal rendition of a song (with slightly different phrasing and timing of some words) is any better or any worse that the original.

What about the shape of your vocal harmonics - they just won't be similar to the original no matter how hard you try to mimic the original. What about vocal slurs (drifting the pitch of a sung phrase from one note to another - this will be likely different to the original but who cares providing your vocal sounds good to a professional human ear (and to a regular dude too).

The original sung vocal (if done somewhat professionally) will have compression and reverb at the very least and likely also to have some echo artefacts - you can never sing in any way possible that will reproduce these "studio" effects. OK you might use some reverb, compression and echo, possibly even some chorus and stereo width enhancements BUT these will just not be the same as the original no matter how long you try.

What about equalization - oh my oh my - do you honestly believe that a pro sung vocal won't have some form of "tone" enhancement to improve the vocal's presense in the song - I'm thinking here that a common setting is 3 dB down at 1kHz, 4 dB up at 6kHz and a general roll-off of frequencies from about 200Hz to DC.

I'll put money down here and STATE (without any more justification other than my experiences), that you will be wasting your time trying to make what you want.

\$\endgroup\$
1
  • \$\begingroup\$ Yes... In the end, I changed our design, doing something more achievable. So you win the bet! lol \$\endgroup\$ Oct 17, 2014 at 16:46
1
\$\begingroup\$

Perhaps you could make a series of bandpass filters and precision rectifiers and compare the frequency content in each bin. I would suggest comparing the difference of the logs of the content and turning on several LEDs in sequence for bigger differences. This will be a fairly simple circuit, but repeated for each frequency, so many parts.

Blocks for n frequencies are:

  • bandpass filter (2n required)
  • precision rectifier (2n required)
  • log circuit (2n required)
  • difference circuit (n required)
  • low pass filter (n required)
  • 'thermometer' ADC with LED drive outputs (n required)

Outside of the analog realm, you could certainly do this with a DSP or FPGA and probably with a 32-bit ARM or MIPS (eg. PIC32) microcontroller.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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