Go Down

Topic: Use Arduino to locate the frequency after FFT calculation (Read 851 times) previous topic - next topic

KusanagiMotoko

Jun 06, 2013, 08:26 am Last Edit: Jun 06, 2013, 12:43 pm by AWOL Reason: 1
Good day everyone.

I'm trying to let my Arduino do an FFT of input signal, and then tell me what is the frequency that correspond to the "peak". The data output (fht_log_out) from the FFT execution module (I use FHT library) is in uint8 type. So what I have tried are compare and find the maximum value in this uint8 type of data, and then locate the bin number of the corresponding maximum value, and then by normalizing the bin number I should get the frequency.

However that will not work, and I guess the reason is that I couldn't find the maximum value in a uint9 kind of datatype. What should I do?

Here is my code segment:

Code: [Select]

 // Find the pike location
 DoubleArray_FHT = DoubleArray_FHT/FHT_N;
 uint16_t TempMax = 0; //temperary maximum
 for (byte i=0;i<FHT_N/2;i++){
   if(fht_log_out[i]>TempMax)
   {
     TempMax = fht_log_out[i];//find the maximum in fht_log_out
     BinNumber = i;// position of the maximum
     Speed = BinNumber*200/256;



Any suggestion will be much appreciated! Anyone?

Moderator edit: attempt to render code legible.

g_u_e_s_t

what is the error you are seeing?  are you printing out the bin number, and it is the wrong bin?

it looks like some of the code is missing from your post, so its hard to say, but what you have looks ok.

tmd3

There's not much to go on in the original query. I'd suggest:

  • Print the contents of fht_input[] after the analog data is acquired, and see if it looks like what you expect.  Note that you'll have to enable interrupts to get Serial.print() to work.

  • Print the contents of fht_log_out[] after the calculations are complete, and see if it looks like what you expect.  Again, you'll need interrupts enabled.


These are elementary troubleshooting steps, and they may have been done already; if so, no one's mentioned it.

Go Up