2

I am planning to build a puzzle box for my son’s graduation. He is very musical so I want one part of the puzzle to require playing a specific tune on a piano, flute, whistling or whatever to cause a servo to actuate. I was thinking a Raspberry Pi based application might be just the thing.

I understand how to set up a microphone to record and how to actuate a servo when the correct tune is detected. While I do have background in signal processing and FFTs, I have no interest in making a project out of writing elaborate code to sort out the sounds. Surely (I am hoping at least) this is a common function for things like song identification etc. 🙂

1
  • 1
    Unless you are good at harmonics and understand music encoding and how to analyze it, I'd suggest you look at machine learning models built for harmonical analitics. However, none of these topics are easy, and have little to do with the Raspberry Pi specifically.
    – user96931
    Commented Feb 10, 2020 at 1:28

1 Answer 1

1

Answer

Ah, let me see, I agree real time FFT is too complicated and over killing.

Goggle tensorFlow trained on very limited, say only 3 very short, 2 seconds long target tunes might be easier. But it might be a bit tedious to train the stupid tensorFlow ears.

Easiest might be to use Rpi and ADC to do "structured" and "statistical" pattern recognition, as summarized blow:

(1) Chop/structured the converted digital signal string into 4 or more sections,

(2) Get the statistically overall, moving time max, min, and avg values of each section,

(3) Compare/contrast/correlate the above overall/section values with that of the three target tunes to pick your educated/calculated guess.

You might need to try and error to trade off recognition time and successful recognition rate etc for optimal parameters of say, chopping number, moving time period etc.

For real time streaming audio hobbyists, I would recommend dirt cheap PCM1802 (Ref 1).


Update 2020feb11hkt1849

If my suggestion looks simple, actually it is.

FFT uses digital transform from time domain to frequency domain, to make the transformed data processing algebraic easy (similar to logarithmic transform making the multiplication/division manipulation becomes simpler addition and subtraction), but the scary convolution/deconvolution theory is hard to grasp.

On the other hand, neural networks using tensorFlow etc is non algorithmic, ie, no procedure or algorithm involved, and so called models blindly process layers, this make human understanding very abstract and head breaking.

Now my suggested structural and statistical pattern recognition procedure only needs middle school arithmetic understanding of average, maximum and minimum.

What is so newebie friendly is that for developing the project offline, you don't even need any sophisticated tools such as MathLab or similar.

What you need is just Excel, which in fact is very powerful, with the "what if" features etc.

Excel is very newbie friendly to do the max, min, avg, and also other more complicated statistical formula, can make the trial and error tune detection easy.

Of course python can be used later to speed up the procedure for realtime applications.

In short , only middle school students can DIY the hardware (the hard part, using of PCM1802 is also explained in the side project in the reference).

Difficulty level: Middle school physics and mathematics.


Adding bells and whistles

If you find the project too simple or too easy, you can add some bells and whistles like using the also dirt cheap PCM1808 DAC studied in the project to play back what your son have played.

--

Letting the servos dancing

It won't be too more difficult to let a 16 servo robot girl to dance along, while playing the guessed tune. For this part, you might use the other dirt cheap chip, the 16 channel PCM/servo controller PCA9685.

Warning: No guarantee that your son's school mates might not become over jealous, or he not over worrying which pretty girl to invite to the graduation party.


References

(1) How to use Rpi python to control PCM1802 24-bit HiFi stereo ADC and MAX4466 microphone amplifier


Appendices

(A) PCM1802 Features and Block Diagram

pcm1802


End of answer.


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.