Go Down

Topic: FHT whistle detection (Read 4605 times) previous topic - next topic

tmd3

Now whenever I upload the sketch below and run it, my computer can't recognize the Yun.
I've never as much as seen a live Yun, so I may not be able to help, but I'll hazard a guess.  

The sketch disables interrupts, and then tries to print the input array while interrupts are disabled.  That won't work, because Serial.print() relies on interrupts being enabled to do its work.  Serial.print() merely sets up the print operation by putting the characters into a buffer, for the serial communication ISR to send.  When interrupts are disabled, no characters are transmitted, and the serial buffer fills to capacity.  Once it's full, any further call to Serial.print() will cause the processor to wait until there's space in the buffer for the new data.  With no characters leaving the serial buffer, it will wait forever.  It won't be able to do anything else.

You can fix this by moving the sei() instruction, which reenables interrupts, to the point right before your first call to Serial.print.  Or, perhaps better yet, you can eliminate the cli() and sei() instructions entirely.  My tests with with this FHT library don't find any change in performance with interrupts either on or off, and I suspect that the notion that they somehow interfere is a relic of wither an old IDE, or of some other implementation of the test program.

Code: [Select]
If you can tell me what components to buy and how to assemble them, I would be very grateful!
I'm not sure what I would improve.  For easy design and installation, the Adafruit gizmo looks to be a very good solution.  It manages most of the details of an analog audio interface for you.

I don't know what your goal is.  It might be to get a whistle-identifier working, in which case you may be well-advised to pursue a hardware solution, as others have suggested.  Or, it might be that the learning component of this project is what's really important you here - in that case, a hardware solution short-circuits your aims.  You know what you want to accomplish.  I'd recommend that you select the option that suits your needs, and carry on.

I'll note that this is a difficult project for a beginner.  We've seen a lot of questions about frequency estimation using the FFT or FHT, but I can't recall anyone reporting a clear success.  After you get past these initial hurdles, you may find that this project is more difficult than you imagine.  A wiser man than I might advise you to whet your skills on something that's more achievable.

SomethingClever

@jremington

Thank you - I am looking in to all options right now :)

I really would like to learn something, but as I am learning tons of other stuff right now this has a low priority.

SomethingClever

#17
Aug 12, 2015, 02:58 pm Last Edit: Aug 12, 2015, 02:59 pm by SomethingClever
@jremington

I followed the instructions, and I have tried everything and adjusted everything, but the circuit doesn't work.

I hope someone can help me out. The light is turned off no matter what, and as I can understand it should be turned on until the right frequency is detected. I have checked and double checked all capacitors and resistors, and they should be right.



Attached an image, but I can't see it. Here it is: http://imgur.com/cNuut7a

jremington

#18
Aug 12, 2015, 10:10 pm Last Edit: Aug 12, 2015, 10:12 pm by jremington
Assuming you are referring to this: http://www.scary-terry.com/more_stuff/tonedet/tonedet.htm

I can't tell for sure whether you have wired everything correctly or have the correct components, but the LED should be OFF unless a tone is detected. Have you wired the LED the right way around? Briefly connect pin 8 of the LM567 to ground to check -- the LED will light if it is OK.

The audio input of the LM567 must see an audio signal of at least 20 mV rms (around 60 mV peak-to-peak) for the LM567 to respond. What voltage does that microphone module output?
No PM's please.

SomethingClever

I thought it had to be ON unless a tone was detected due to the sentence "The output of the circuit goes low when a tone is detected".

I am sure I have the right components. Have checked and rechecked. The LED is wired the right way, yes. I will check everything again tomorrow and get back to you about the voltage.

jremington

If you wired it correctly, the LED will turn on only when the LM567 output is low.
No PM's please.

SomethingClever

#21
Aug 13, 2015, 08:28 pm Last Edit: Aug 13, 2015, 08:48 pm by SomethingClever
@jremington

Everything works now! I probably worked yesterday also, but I had misunderstood how to read the LED.

I tried both 3.3v and 5v for the microphone, and 3.3 works better.

Thank you so much for your help!

Now I just need to find the right frequency for the project :)

Edit: The formula f=1/(R2 x C6) is used to calculate the frequency needed. When R2 = 6.3 and C6 = 0.1, the frequency should be 1,59k, but it only detects a frequency around 2k. The formula works when trying other combinations. Do you have an idea why it fails here?

jremington

The formula and the component values on the parts are probably not very accurate. You should use an adjustable resistor (trim pot, etc.) for R2 to tune the response.
No PM's please.

SomethingClever

#23
Aug 14, 2015, 10:40 pm Last Edit: Aug 14, 2015, 11:14 pm by SomethingClever
Everything works now and I can detect a whistle. It has to be around one specific tone (E6, 1300hz) though, and not every whistle will do. I will try to find a way to extend the frequency range if that is possible.

jremington

#24
Aug 15, 2015, 06:25 am Last Edit: Aug 15, 2015, 06:32 am by jremington
Congratulations! 

The LM567 data sheet has some information about setting the detection bandwidth, but you need a fairly large signal.
Quote
10.4.2 Operation With Vi > 200 mV RMS
For input voltages greater than 200 mV RMS, the bandwidth depends directly from the loop filter capacitance and free running frequency product. Bandwidth is represented as a percentage of the free running frequency, and according to the product of f0∙C2, it can have a variation from 2 to 14%. Table 2 shows the approximate values for bandwidth in function of the product result.
Note that the LM567 performs a "one point Fourier transform" by multiplying an internally generated sine wave with the external sine wave. A large value signifies a match. The FFT and FHT do multiple point Fourier transforms.
No PM's please.

Go Up