Pages: [1]   Go Down
Author Topic: Frequency  (Read 1308 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26285
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Goertzel's algorithm?
FFT?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Edison Member
*
Karma: 34
Posts: 1319
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

FFT/DFT 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.
Logged

Offline Offline
Jr. Member
**
Karma: 2
Posts: 97
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

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

Any interesting link?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

 
Code:
#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
     ADCSRA = 0xe5; // set the adc to free running mode
     ADMUX = 0x40; // use adc0
     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
         while(!(ADCSRA & 0x10)); // wait for adc to be ready
         ADCSRA = 0xf5; // restart adc
         byte m = ADCL; // fetch adc data
         byte j = ADCH;
         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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26285
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
it only displays strange characters:
Did you set the correct bit rate?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
« Last Edit: August 01, 2013, 07:09:38 am by luppittegui » Logged

Offline Offline
Edison Member
*
Karma: 48
Posts: 1630
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://forum.arduino.cc/index.php?topic=179095.0

Pete
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26285
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1]   Go Up
Jump to: