Frequency

Hello!

I need to get the frequency that I send to arduino from my computer by jack (a mic connects mi pc to arduino). For example, if I send 1000Hz, Arduino have to catch 1000Hz.

Are there any code done?

Tnx!!

Goertzel's algorithm?
FFT?

But how can I use it?
Are there examples that process the sound and obtain the frequency? I need only that

Digital signal processing is not that easy. However, if you can find an FFT library you won't have to write the hard part of the code yourself.

[u]FFT/DFT[/u] will give you the frequency components and their amplitude at any point/period of time.

If you have a pure tone or a pure square wave, you can simply measure the time between zero-crossings* (or between rising-edges) and calculate the frequency. (Real-world natural sounds contain more than one frequency so this may, or may not, work for finding the "fundamental" frequency.)

• Since the Arduino cannot accept the negative half of an audio/AC waveform, you have to add bias or otherwise deal with the negative signal, and then find the true zero-crossing or find a point near the zero crossing in software.

what frequency resolution do you need, and is the incoming signal a pure tone?

I am not an arduino programmer, only need the code that works

I'm sure you've got information or code that works and do that, I'll put the code and don't matter how works, only the result

I’ve got this code, but it only displays strange characters:

``````#define LOG_OUT 1 // use the log output function
#define FHT_N 256 // set to 256 point fht

#include <FHT.h> // include the library

void setup() {
Serial.begin(9600); // use the serial port
TIMSK0 = 0; // turn off timer0 for lower jitter
DIDR0 = 0x01; // turn off the digital input for adc0
}

void loop() {
while(1) { // reduces jitter
cli();  // UDRE interrupt slows this way down on arduino1.0
for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples
int k = (j << 8) | m; // form into an int
k -= 0x0200; // form into a signed int
k <<= 6; // form into a 16b signed int
fht_input[i] = k; // put real data into bins
}
fht_window(); // window the data for better frequency response
fht_reorder(); // reorder the data before doing the fht
fht_run(); // process the data in the fht
fht_mag_log(); // take the output of the fht
sei();
Serial.write(255); // send a start byte
Serial.write(fht_log_out, FHT_N/2); // send out the data
Serial.println(long);
}
}
``````

How can I display the frequency?

it only displays strange characters:

Did you set the correct bit rate?

yeah, I think the problem is "write" instead of "print", but I don't know how to change becouse it's an array.

But the main problem is display the frequency, because "fht_log_out" is an array and I read that I have to get the picks

How can I do that?

I've got a new problem

I'd like to read in a digital port instead of analog port.

With the code above, how can I do this?

Scrub all the ADC code, and do a digitalWrite at approximately the same interval.
You'll probably want to scale up any ones read to a more sensible value for the FFT.